hidpp10: Move independent functions to module level
This commit is contained in:
parent
7d171b1d09
commit
193dbfda21
|
@ -417,7 +417,7 @@ class Device:
|
|||
self.set_configuration(0x11) # signal end of configuration
|
||||
self.read_battery() # battery information may have changed so try to read it now
|
||||
elif was_active and self.receiver: # need to set configuration pending flag in receiver
|
||||
hidpp10.Hidpp10().set_configuration_pending_flags(self.receiver, 0xFF)
|
||||
hidpp10.set_configuration_pending_flags(self.receiver, 0xFF)
|
||||
if logger.isEnabledFor(logging.DEBUG):
|
||||
logger.debug("device %d changed: active=%s %s", self.number, self._active, self.battery_info)
|
||||
if self.status_callback is not None:
|
||||
|
|
|
@ -45,6 +45,19 @@ def write_register(device, register_number, *value):
|
|||
return device.request(request_id, *value)
|
||||
|
||||
|
||||
def get_configuration_pending_flags(receiver):
|
||||
assert not receiver.isDevice
|
||||
result = read_register(receiver, REGISTERS.devices_configuration)
|
||||
if result is not None:
|
||||
return ord(result[:1])
|
||||
|
||||
|
||||
def set_configuration_pending_flags(receiver, devices):
|
||||
assert not receiver.isDevice
|
||||
result = write_register(receiver, REGISTERS.devices_configuration, devices)
|
||||
return result is not None
|
||||
|
||||
|
||||
class Hidpp10:
|
||||
def get_battery(self, device):
|
||||
assert device is not None
|
||||
|
@ -189,17 +202,6 @@ class Hidpp10:
|
|||
assert len(flags) == 3
|
||||
return _bytes2int(flags)
|
||||
|
||||
def get_configuration_pending_flags(self, receiver):
|
||||
assert not receiver.isDevice
|
||||
result = read_register(receiver, REGISTERS.devices_configuration)
|
||||
if result is not None:
|
||||
return ord(result[:1])
|
||||
|
||||
def set_configuration_pending_flags(self, receiver, devices):
|
||||
assert not receiver.isDevice
|
||||
result = write_register(receiver, REGISTERS.devices_configuration, devices)
|
||||
return result is not None
|
||||
|
||||
|
||||
def parse_battery_status(register, reply):
|
||||
if register == REGISTERS.battery_charge:
|
||||
|
|
|
@ -264,7 +264,7 @@ def _process_hidpp10_notification(device, n):
|
|||
)
|
||||
device.link_encrypted = link_encrypted
|
||||
if not link_established and device.receiver:
|
||||
_hidpp10.set_configuration_pending_flags(device.receiver, 0xFF)
|
||||
hidpp10.set_configuration_pending_flags(device.receiver, 0xFF)
|
||||
device.changed(active=link_established)
|
||||
return True
|
||||
|
||||
|
|
|
@ -85,7 +85,7 @@ class Receiver:
|
|||
self.notification_flags = None
|
||||
self.pairing = Pairing()
|
||||
self.initialize(product_info)
|
||||
_hidpp10.set_configuration_pending_flags(self, 0xFF)
|
||||
hidpp10.set_configuration_pending_flags(self, 0xFF)
|
||||
|
||||
def initialize(self, product_info: dict):
|
||||
# read the receiver information subregister, so we can find out max_devices
|
||||
|
|
|
@ -38,7 +38,7 @@ def _print_receiver(receiver):
|
|||
print(" Device path :", receiver.path)
|
||||
print(f" USB id : 046d:{receiver.product_id}")
|
||||
print(" Serial :", receiver.serial)
|
||||
pending = _hidpp10.get_configuration_pending_flags(receiver)
|
||||
pending = hidpp10.get_configuration_pending_flags(receiver)
|
||||
if pending:
|
||||
print(f" C Pending : {pending:02x}")
|
||||
if receiver.firmware:
|
||||
|
|
|
@ -299,7 +299,7 @@ def test_get_register(device, register, expected_result):
|
|||
],
|
||||
)
|
||||
def test_get_configuration_pending_flags(device, expected_result):
|
||||
result = _hidpp10.get_configuration_pending_flags(device)
|
||||
result = hidpp10.get_configuration_pending_flags(device)
|
||||
|
||||
assert result == expected_result
|
||||
|
||||
|
@ -312,6 +312,6 @@ def test_get_configuration_pending_flags(device, expected_result):
|
|||
],
|
||||
)
|
||||
def test_set_configuration_pending_flags(device, expected_result):
|
||||
result = _hidpp10.set_configuration_pending_flags(device, 0x00)
|
||||
result = hidpp10.set_configuration_pending_flags(device, 0x00)
|
||||
|
||||
assert result == expected_result
|
||||
|
|
Loading…
Reference in New Issue