From 000e13195755ebf747d4cde4e4dab95fe61bd1a9 Mon Sep 17 00:00:00 2001 From: MattHag <16444067+MattHag@users.noreply.github.com> Date: Tue, 5 Nov 2024 02:49:53 +0100 Subject: [PATCH] Remove NamedInts: Convert PowerSwitchLocation to flag Related #2273 --- lib/logitech_receiver/hidpp10_constants.py | 27 +++++++++++----------- lib/logitech_receiver/receiver.py | 2 +- 2 files changed, 15 insertions(+), 14 deletions(-) diff --git a/lib/logitech_receiver/hidpp10_constants.py b/lib/logitech_receiver/hidpp10_constants.py index f006caa06..6541014a6 100644 --- a/lib/logitech_receiver/hidpp10_constants.py +++ b/lib/logitech_receiver/hidpp10_constants.py @@ -41,19 +41,20 @@ receiver=0x0F, # for compatibility with HID++ 2.0 ) -POWER_SWITCH_LOCATION = NamedInts( - base=0x01, - top_case=0x02, - edge_of_top_right_corner=0x03, - top_left_corner=0x05, - bottom_left_corner=0x06, - top_right_corner=0x07, - bottom_right_corner=0x08, - top_edge=0x09, - right_edge=0x0A, - left_edge=0x0B, - bottom_edge=0x0C, -) + +class PowerSwitchLocation(IntEnum): + BASE = 0x01 + TOP_CASE = 0x02 + EDGE_OF_TOP_RIGHT_CORNER = 0x03 + TOP_LEFT_CORNER = 0x05 + BOTTOM_LEFT_CORNER = 0x06 + TOP_RIGHT_CORNER = 0x07 + BOTTOM_RIGHT_CORNER = 0x08 + TOP_EDGE = 0x09 + RIGHT_EDGE = 0x0A + LEFT_EDGE = 0x0B + BOTTOM_EDGE = 0x0C + # Some flags are used both by devices and receivers. The Logitech documentation # mentions that the first and last (third) byte are used for devices while the diff --git a/lib/logitech_receiver/receiver.py b/lib/logitech_receiver/receiver.py index 97f391fe1..29f2abb2b 100644 --- a/lib/logitech_receiver/receiver.py +++ b/lib/logitech_receiver/receiver.py @@ -229,7 +229,7 @@ def device_pairing_information(self, n: int) -> dict: 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) if pair_info: - power_switch = hidpp10_constants.POWER_SWITCH_LOCATION[pair_info[9] & 0x0F] + power_switch = hidpp10_constants.PowerSwitchLocation(pair_info[9] & 0x0F) serial = pair_info[1:5].hex().upper() else: # some Nano receivers? pair_info = self.read_register(0x2D5) # undocumented and questionable