Refactor InfoSubRegisters: Use IntEnum in favour of NamedInts
This commit is contained in:
parent
378175f98f
commit
96364d2df3
|
@ -194,16 +194,15 @@ class Registers(IntEnum):
|
||||||
|
|
||||||
|
|
||||||
# Subregisters for receiver_info register
|
# Subregisters for receiver_info register
|
||||||
INFO_SUBREGISTERS = NamedInts(
|
class InfoSubRegisters(IntEnum):
|
||||||
serial_number=0x01, # not found on many receivers
|
SERIAL_NUMBER = 0x01 # not found on many receivers
|
||||||
fw_version=0x02,
|
FW_VERSION = 0x02
|
||||||
receiver_information=0x03,
|
RECEIVER_INFORMATION = 0x03
|
||||||
pairing_information=0x20, # 0x2N, by connected device
|
PAIRING_INFORMATION = 0x20 # 0x2N, by connected device
|
||||||
extended_pairing_information=0x30, # 0x3N, by connected device
|
EXTENDED_PAIRING_INFORMATION = 0x30 # 0x3N, by connected device
|
||||||
device_name=0x40, # 0x4N, by connected device
|
DEVICE_NAME = 0x40 # 0x4N, by connected device
|
||||||
bolt_pairing_information=0x50, # 0x5N, by connected device
|
BOLT_PAIRING_INFORMATION = 0x50 # 0x5N, by connected device
|
||||||
bolt_device_name=0x60, # 0x6N01, by connected device,
|
BOLT_DEVICE_NAME = 0x60 # 0x6N01, by connected device
|
||||||
)
|
|
||||||
|
|
||||||
|
|
||||||
class DeviceFeature(Flag):
|
class DeviceFeature(Flag):
|
||||||
|
|
|
@ -36,6 +36,7 @@ from . import hidpp10_constants
|
||||||
from .common import Alert
|
from .common import Alert
|
||||||
from .common import Notification
|
from .common import Notification
|
||||||
from .device import Device
|
from .device import Device
|
||||||
|
from .hidpp10_constants import InfoSubRegisters
|
||||||
from .hidpp10_constants import NotificationFlag
|
from .hidpp10_constants import NotificationFlag
|
||||||
from .hidpp10_constants import Registers
|
from .hidpp10_constants import Registers
|
||||||
|
|
||||||
|
@ -47,7 +48,6 @@ if typing.TYPE_CHECKING:
|
||||||
logger = logging.getLogger(__name__)
|
logger = logging.getLogger(__name__)
|
||||||
|
|
||||||
_hidpp10 = hidpp10.Hidpp10()
|
_hidpp10 = hidpp10.Hidpp10()
|
||||||
_IR = hidpp10_constants.INFO_SUBREGISTERS
|
|
||||||
|
|
||||||
|
|
||||||
class LowLevelInterface(Protocol):
|
class LowLevelInterface(Protocol):
|
||||||
|
@ -127,7 +127,7 @@ class Receiver:
|
||||||
|
|
||||||
def initialize(self, product_info: dict):
|
def initialize(self, product_info: dict):
|
||||||
# read the receiver information subregister, so we can find out max_devices
|
# 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:
|
if serial_reply:
|
||||||
self.serial = serial_reply[1:5].hex().upper()
|
self.serial = serial_reply[1:5].hex().upper()
|
||||||
self.max_devices = serial_reply[6]
|
self.max_devices = serial_reply[6]
|
||||||
|
@ -193,7 +193,7 @@ class Receiver:
|
||||||
return flag_bits
|
return flag_bits
|
||||||
|
|
||||||
def device_codename(self, n):
|
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:
|
if codename:
|
||||||
codename = codename[2 : 2 + ord(codename[1:2])]
|
codename = codename[2 : 2 + ord(codename[1:2])]
|
||||||
return codename.decode("ascii")
|
return codename.decode("ascii")
|
||||||
|
@ -218,7 +218,7 @@ class Receiver:
|
||||||
polling_rate = ""
|
polling_rate = ""
|
||||||
serial = None
|
serial = None
|
||||||
power_switch = "(unknown)"
|
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
|
if pair_info: # a receiver that uses Unifying-style pairing registers
|
||||||
wpid = pair_info[3:5].hex().upper()
|
wpid = pair_info[3:5].hex().upper()
|
||||||
kind = hidpp10_constants.DEVICE_KIND[pair_info[7] & 0x0F]
|
kind = hidpp10_constants.DEVICE_KIND[pair_info[7] & 0x0F]
|
||||||
|
@ -233,7 +233,7 @@ class Receiver:
|
||||||
raise exceptions.NoSuchDevice(number=n, receiver=self, error="read pairing information - non-unifying")
|
raise exceptions.NoSuchDevice(number=n, receiver=self, error="read pairing information - non-unifying")
|
||||||
else:
|
else:
|
||||||
raise exceptions.NoSuchDevice(number=n, receiver=self, error="read pairing information")
|
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:
|
if pair_info:
|
||||||
power_switch = hidpp10_constants.PowerSwitchLocation(pair_info[9] & 0x0F)
|
power_switch = hidpp10_constants.PowerSwitchLocation(pair_info[9] & 0x0F)
|
||||||
serial = pair_info[1:5].hex().upper()
|
serial = pair_info[1:5].hex().upper()
|
||||||
|
@ -416,13 +416,13 @@ class BoltReceiver(Receiver):
|
||||||
self.max_devices = product_info.get("max_devices", 1)
|
self.max_devices = product_info.get("max_devices", 1)
|
||||||
|
|
||||||
def device_codename(self, n):
|
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:
|
if codename:
|
||||||
codename = codename[3 : 3 + min(14, ord(codename[2:3]))]
|
codename = codename[3 : 3 + min(14, ord(codename[2:3]))]
|
||||||
return codename.decode("ascii")
|
return codename.decode("ascii")
|
||||||
|
|
||||||
def device_pairing_information(self, n: int) -> dict:
|
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:
|
if pair_info:
|
||||||
wpid = (pair_info[3:4] + pair_info[2:3]).hex().upper()
|
wpid = (pair_info[3:4] + pair_info[2:3]).hex().upper()
|
||||||
kind = hidpp10_constants.DEVICE_KIND[pair_info[1] & 0x0F]
|
kind = hidpp10_constants.DEVICE_KIND[pair_info[1] & 0x0F]
|
||||||
|
|
|
@ -196,7 +196,7 @@ class SolaarListener(listener.EventsListener):
|
||||||
if (
|
if (
|
||||||
self.receiver.read_register(
|
self.receiver.read_register(
|
||||||
hidpp10_constants.Registers.RECEIVER_INFO,
|
hidpp10_constants.Registers.RECEIVER_INFO,
|
||||||
hidpp10_constants.INFO_SUBREGISTERS.pairing_information + n.devnumber - 1,
|
hidpp10_constants.InfoSubRegisters.PAIRING_INFORMATION + n.devnumber - 1,
|
||||||
)
|
)
|
||||||
is None
|
is None
|
||||||
):
|
):
|
||||||
|
|
Loading…
Reference in New Issue