diff --git a/lib/logitech_receiver/hidpp10_constants.py b/lib/logitech_receiver/hidpp10_constants.py index b34d68596..c27ba239d 100644 --- a/lib/logitech_receiver/hidpp10_constants.py +++ b/lib/logitech_receiver/hidpp10_constants.py @@ -194,16 +194,15 @@ class Registers(IntEnum): # Subregisters for receiver_info register -INFO_SUBREGISTERS = NamedInts( - serial_number=0x01, # not found on many receivers - fw_version=0x02, - receiver_information=0x03, - pairing_information=0x20, # 0x2N, by connected device - extended_pairing_information=0x30, # 0x3N, by connected device - device_name=0x40, # 0x4N, by connected device - bolt_pairing_information=0x50, # 0x5N, by connected device - bolt_device_name=0x60, # 0x6N01, by connected device, -) +class InfoSubRegisters(IntEnum): + SERIAL_NUMBER = 0x01 # not found on many receivers + FW_VERSION = 0x02 + RECEIVER_INFORMATION = 0x03 + PAIRING_INFORMATION = 0x20 # 0x2N, by connected device + EXTENDED_PAIRING_INFORMATION = 0x30 # 0x3N, by connected device + DEVICE_NAME = 0x40 # 0x4N, by connected device + BOLT_PAIRING_INFORMATION = 0x50 # 0x5N, by connected device + BOLT_DEVICE_NAME = 0x60 # 0x6N01, by connected device class DeviceFeature(Flag): diff --git a/lib/logitech_receiver/receiver.py b/lib/logitech_receiver/receiver.py index a7ef1ede3..0617fdd59 100644 --- a/lib/logitech_receiver/receiver.py +++ b/lib/logitech_receiver/receiver.py @@ -36,6 +36,7 @@ from .common import Alert from .common import Notification from .device import Device +from .hidpp10_constants import InfoSubRegisters from .hidpp10_constants import NotificationFlag from .hidpp10_constants import Registers @@ -45,7 +46,6 @@ logger = logging.getLogger(__name__) _hidpp10 = hidpp10.Hidpp10() -_IR = hidpp10_constants.INFO_SUBREGISTERS class LowLevelInterface(Protocol): @@ -125,7 +125,7 @@ def __init__( def initialize(self, product_info: dict): # read the receiver information subregister, so we can find out max_devices - serial_reply = self.read_register(Registers.RECEIVER_INFO, _IR.receiver_information) + serial_reply = self.read_register(Registers.RECEIVER_INFO, InfoSubRegisters.RECEIVER_INFORMATION) if serial_reply: self.serial = serial_reply[1:5].hex().upper() self.max_devices = serial_reply[6] @@ -191,7 +191,7 @@ def enable_connection_notifications(self, enable=True): return flag_bits def device_codename(self, n): - codename = self.read_register(Registers.RECEIVER_INFO, _IR.device_name + n - 1) + codename = self.read_register(Registers.RECEIVER_INFO, InfoSubRegisters.DEVICE_NAME + n - 1) if codename: codename = codename[2 : 2 + ord(codename[1:2])] return codename.decode("ascii") @@ -216,7 +216,7 @@ def device_pairing_information(self, n: int) -> dict: polling_rate = "" serial = None power_switch = "(unknown)" - pair_info = self.read_register(Registers.RECEIVER_INFO, _IR.pairing_information + n - 1) + pair_info = self.read_register(Registers.RECEIVER_INFO, InfoSubRegisters.PAIRING_INFORMATION + n - 1) if pair_info: # a receiver that uses Unifying-style pairing registers wpid = pair_info[3:5].hex().upper() kind = hidpp10_constants.DEVICE_KIND[pair_info[7] & 0x0F] @@ -231,7 +231,7 @@ def device_pairing_information(self, n: int) -> dict: raise exceptions.NoSuchDevice(number=n, receiver=self, error="read pairing information - non-unifying") else: raise exceptions.NoSuchDevice(number=n, receiver=self, error="read pairing information") - pair_info = self.read_register(Registers.RECEIVER_INFO, _IR.extended_pairing_information + n - 1) + pair_info = self.read_register(Registers.RECEIVER_INFO, InfoSubRegisters.EXTENDED_PAIRING_INFORMATION + n - 1) if pair_info: power_switch = hidpp10_constants.PowerSwitchLocation(pair_info[9] & 0x0F) serial = pair_info[1:5].hex().upper() @@ -414,13 +414,13 @@ def initialize(self, product_info: dict): self.max_devices = product_info.get("max_devices", 1) def device_codename(self, n): - codename = self.read_register(Registers.RECEIVER_INFO, _IR.bolt_device_name + n, 0x01) + codename = self.read_register(Registers.RECEIVER_INFO, InfoSubRegisters.BOLT_DEVICE_NAME + n, 0x01) if codename: codename = codename[3 : 3 + min(14, ord(codename[2:3]))] return codename.decode("ascii") def device_pairing_information(self, n: int) -> dict: - pair_info = self.read_register(Registers.RECEIVER_INFO, _IR.bolt_pairing_information + n) + pair_info = self.read_register(Registers.RECEIVER_INFO, InfoSubRegisters.BOLT_PAIRING_INFORMATION + n) if pair_info: wpid = (pair_info[3:4] + pair_info[2:3]).hex().upper() kind = hidpp10_constants.DEVICE_KIND[pair_info[1] & 0x0F] diff --git a/lib/solaar/listener.py b/lib/solaar/listener.py index 5d49e30c1..4416f4b31 100644 --- a/lib/solaar/listener.py +++ b/lib/solaar/listener.py @@ -196,7 +196,7 @@ def _notifications_handler(self, n): if ( self.receiver.read_register( hidpp10_constants.Registers.RECEIVER_INFO, - hidpp10_constants.INFO_SUBREGISTERS.pairing_information + n.devnumber - 1, + hidpp10_constants.InfoSubRegisters.PAIRING_INFORMATION + n.devnumber - 1, ) is None ):