Skip to content

Commit

Permalink
cleanup: Remove duplicated code to read register
Browse files Browse the repository at this point in the history
Related #1097
  • Loading branch information
MattHag committed Feb 29, 2024
1 parent c4a82b9 commit 8056207
Showing 1 changed file with 5 additions and 14 deletions.
19 changes: 5 additions & 14 deletions lib/logitech_receiver/hidpp10.py
Original file line number Diff line number Diff line change
Expand Up @@ -157,19 +157,7 @@ def set_3leds(self, device, battery_level=None, charging=None, warning=None):
write_register(device, REGISTERS.three_leds, v1, v2)

def get_notification_flags(self, device):
assert device is not None

# Avoid a call if the device is not online,
# or the device does not support registers.
if device.kind is not None:
# peripherals with protocol >= 2.0 don't support registers
if device.protocol and device.protocol >= 2.0:
return

flags = read_register(device, REGISTERS.notifications)
if flags is not None:
assert len(flags) == 3
return _bytes2int(flags)
return self._get_register(device, REGISTERS.notifications)

def set_notification_flags(self, device, *flag_bits):
assert device is not None
Expand All @@ -187,6 +175,9 @@ def set_notification_flags(self, device, *flag_bits):
return result is not None

def get_device_features(self, device):
self._get_register(device, REGISTERS.mouse_button_flags)

def _get_register(self, device, register):
assert device is not None

# Avoid a call if the device is not online,
Expand All @@ -196,7 +187,7 @@ def get_device_features(self, device):
if device.protocol and device.protocol >= 2.0:
return

flags = read_register(device, REGISTERS.mouse_button_flags)
flags = read_register(device, register)
if flags is not None:
assert len(flags) == 3
return _bytes2int(flags)
Expand Down

0 comments on commit 8056207

Please sign in to comment.