From 8056207b0e96a99b60f22f702cf1149747a8fd16 Mon Sep 17 00:00:00 2001 From: Matthias Hagmann <16444067+MattHag@users.noreply.github.com> Date: Thu, 29 Feb 2024 16:56:25 +0100 Subject: [PATCH] cleanup: Remove duplicated code to read register Related #1097 --- lib/logitech_receiver/hidpp10.py | 19 +++++-------------- 1 file changed, 5 insertions(+), 14 deletions(-) diff --git a/lib/logitech_receiver/hidpp10.py b/lib/logitech_receiver/hidpp10.py index 216bffc2c2..5ded48d64c 100644 --- a/lib/logitech_receiver/hidpp10.py +++ b/lib/logitech_receiver/hidpp10.py @@ -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 @@ -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, @@ -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)