File tree Expand file tree Collapse file tree 3 files changed +22
-4
lines changed Expand file tree Collapse file tree 3 files changed +22
-4
lines changed Original file line number Diff line number Diff line change 47
47
48
48
49
49
class PowerSwitchLocation (IntEnum ):
50
+ UNKNOWN = 0x00
50
51
BASE = 0x01
51
52
TOP_CASE = 0x02
52
53
EDGE_OF_TOP_RIGHT_CORNER = 0x03
@@ -59,6 +60,13 @@ class PowerSwitchLocation(IntEnum):
59
60
LEFT_EDGE = 0x0B
60
61
BOTTOM_EDGE = 0x0C
61
62
63
+ @classmethod
64
+ def location (cls , loc : int ) -> PowerSwitchLocation :
65
+ try :
66
+ return cls (loc )
67
+ except ValueError :
68
+ return cls .UNKNOWN
69
+
62
70
63
71
class NotificationFlag (Flag ):
64
72
"""Some flags are used both by devices and receivers.
Original file line number Diff line number Diff line change @@ -108,7 +108,7 @@ def extract_codename(response: bytes) -> str:
108
108
def extract_power_switch_location (response : bytes ) -> str :
109
109
"""Extracts power switch location from response."""
110
110
index = response [9 ] & 0x0F
111
- return hidpp10_constants .PowerSwitchLocation (index ).name .lower ()
111
+ return hidpp10_constants .PowerSwitchLocation . location (index ).name .lower ()
112
112
113
113
114
114
def extract_connection_count (response : bytes ) -> int :
Original file line number Diff line number Diff line change @@ -259,12 +259,22 @@ def test_extract_codename():
259
259
assert codename == "K520"
260
260
261
261
262
- def test_extract_power_switch_location ():
263
- response = b"0\x19 \x8e >\xb8 \x06 \x00 \x00 \x00 \x01 \x00 \x00 \x00 \x00 \x00 \x00 "
262
+ @pytest .mark .parametrize (
263
+ "power_switch_byte, expected_location" ,
264
+ [
265
+ (b"\x01 " , "base" ),
266
+ (b"\x09 " , "top_edge" ),
267
+ (b"\x0c " , "bottom_edge" ),
268
+ (b"\x00 " , "unknown" ),
269
+ (b"\x0f " , "unknown" ),
270
+ ],
271
+ )
272
+ def test_extract_power_switch_location (power_switch_byte , expected_location ):
273
+ response = b"\x19 \x8e >\xb8 \x06 \x00 \x00 \x00 \x00 " + power_switch_byte + b"\x00 \x00 \x00 \x00 \x00 "
264
274
265
275
ps_location = receiver .extract_power_switch_location (response )
266
276
267
- assert ps_location == "base"
277
+ assert ps_location == expected_location
268
278
269
279
270
280
def test_extract_connection_count ():
You can’t perform that action at this time.
0 commit comments