Clarify that fake hidpp is used

This module shouldn't be necessary on the long run. Remove pieces from
it whenever possible.
This commit is contained in:
MattHag 2024-09-15 16:43:26 +02:00 committed by Peter F. Patel-Schneider
parent 3c1aa35067
commit 741c0861c2
6 changed files with 576 additions and 510 deletions

View File

@ -25,7 +25,7 @@ from logitech_receiver import common
from logitech_receiver import device from logitech_receiver import device
from logitech_receiver import hidpp20 from logitech_receiver import hidpp20
from . import hidpp from . import fake_hidpp
class LowLevelInterfaceFake: class LowLevelInterfaceFake:
@ -33,14 +33,14 @@ class LowLevelInterfaceFake:
self.responses = responses self.responses = responses
def open_path(self, path): def open_path(self, path):
return hidpp.open_path(path) return fake_hidpp.open_path(path)
def request(self, response, *args, **kwargs): def request(self, response, *args, **kwargs):
func = partial(hidpp.request, self.responses) func = partial(fake_hidpp.request, self.responses)
return func(response, *args, **kwargs) return func(response, *args, **kwargs)
def ping(self, response, *args, **kwargs): def ping(self, response, *args, **kwargs):
func = partial(hidpp.ping, self.responses) func = partial(fake_hidpp.ping, self.responses)
return func(response, *args, **kwargs) return func(response, *args, **kwargs)
def close(self, *args, **kwargs): def close(self, *args, **kwargs):
@ -70,7 +70,11 @@ di_DDDD = DeviceInfoStub("11", product_id="DDDD")
@pytest.mark.parametrize( @pytest.mark.parametrize(
"device_info, responses, expected_success", "device_info, responses, expected_success",
[(di_bad_handle, hidpp.r_empty, None), (di_error, hidpp.r_empty, False), (di_CCCC, hidpp.r_empty, True)], [
(di_bad_handle, fake_hidpp.r_empty, None),
(di_error, fake_hidpp.r_empty, False),
(di_CCCC, fake_hidpp.r_empty, True),
],
) )
def test_create_device(device_info, responses, expected_success): def test_create_device(device_info, responses, expected_success):
low_level_mock = LowLevelInterfaceFake(responses) low_level_mock = LowLevelInterfaceFake(responses)
@ -87,7 +91,7 @@ def test_create_device(device_info, responses, expected_success):
@pytest.mark.parametrize( @pytest.mark.parametrize(
"device_info, responses, expected_codename, expected_name, expected_kind", "device_info, responses, expected_codename, expected_name, expected_kind",
[(di_CCCC, hidpp.r_empty, "?? (CCCC)", "Unknown device CCCC", "?")], [(di_CCCC, fake_hidpp.r_empty, "?? (CCCC)", "Unknown device CCCC", "?")],
) )
def test_device_name(device_info, responses, expected_codename, expected_name, expected_kind): def test_device_name(device_info, responses, expected_codename, expected_name, expected_kind):
low_level = LowLevelInterfaceFake(responses) low_level = LowLevelInterfaceFake(responses)
@ -103,7 +107,14 @@ def test_device_name(device_info, responses, expected_codename, expected_name, e
"device_info, responses, handle, _name, _codename, number, protocol, registers", "device_info, responses, handle, _name, _codename, number, protocol, registers",
zip( zip(
[di_CCCC, di_C318, di_B530, di_C068, di_C08A, di_DDDD], [di_CCCC, di_C318, di_B530, di_C068, di_C08A, di_DDDD],
[hidpp.r_empty, hidpp.r_keyboard_1, hidpp.r_keyboard_2, hidpp.r_mouse_1, hidpp.r_mouse_2, hidpp.r_mouse_3], [
fake_hidpp.r_empty,
fake_hidpp.r_keyboard_1,
fake_hidpp.r_keyboard_2,
fake_hidpp.r_mouse_1,
fake_hidpp.r_mouse_2,
fake_hidpp.r_mouse_3,
],
[0x11, 0x11, 0x11, 0x11, 0x11, 0x11], [0x11, 0x11, 0x11, 0x11, 0x11, 0x11],
[None, "Illuminated Keyboard", "Craft Advanced Keyboard", "G700 Gaming Mouse", "MX Vertical Wireless Mouse", None], [None, "Illuminated Keyboard", "Craft Advanced Keyboard", "G700 Gaming Mouse", "MX Vertical Wireless Mouse", None],
[None, "Illuminated", "Craft", "G700", "MX Vertical", None], [None, "Illuminated", "Craft", "G700", "MX Vertical", None],
@ -160,7 +171,14 @@ pi_DDDD = {"wpid": "DDDD", "kind": 2, "serial": "1234", "polling": "2ms", "power
zip( zip(
range(1, 7), range(1, 7),
[pi_CCCC, pi_2011, pi_4066, pi_1007, pi_407B, pi_DDDD], [pi_CCCC, pi_2011, pi_4066, pi_1007, pi_407B, pi_DDDD],
[hidpp.r_empty, hidpp.r_keyboard_1, hidpp.r_keyboard_2, hidpp.r_mouse_1, hidpp.r_mouse_2, hidpp.r_mouse_3], [
fake_hidpp.r_empty,
fake_hidpp.r_keyboard_1,
fake_hidpp.r_keyboard_2,
fake_hidpp.r_mouse_1,
fake_hidpp.r_mouse_2,
fake_hidpp.r_mouse_3,
],
[0x11, 0x11, 0x11, 0x11, 0x11, 0x11], [0x11, 0x11, 0x11, 0x11, 0x11, 0x11],
[None, "Wireless Keyboard K520", "Craft Advanced Keyboard", "MX Air", "MX Vertical Wireless Mouse", None], [None, "Wireless Keyboard K520", "Craft Advanced Keyboard", "MX Air", "MX Vertical Wireless Mouse", None],
["CODE", "K520", "Craft", "MX Air", "MX Vertical", "CODE"], ["CODE", "K520", "Craft", "MX Air", "MX Vertical", "CODE"],
@ -180,8 +198,8 @@ def test_device_receiver(number, pairing_info, responses, handle, _name, codenam
mock_hid.side_effect = lambda x, y, z: x mock_hid.side_effect = lambda x, y, z: x
low_level = LowLevelInterfaceFake(responses) low_level = LowLevelInterfaceFake(responses)
low_level.request = partial(hidpp.request, hidpp.replace_number(responses, number)) low_level.request = partial(fake_hidpp.request, fake_hidpp.replace_number(responses, number))
low_level.ping = partial(hidpp.ping, hidpp.replace_number(responses, number)) low_level.ping = partial(fake_hidpp.ping, fake_hidpp.replace_number(responses, number))
test_device = device.Device(low_level, FakeReceiver(codename="CODE"), number, True, pairing_info, handle=handle) test_device = device.Device(low_level, FakeReceiver(codename="CODE"), number, True, pairing_info, handle=handle)
test_device.receiver.device = test_device test_device.receiver.device = test_device
@ -207,7 +225,14 @@ def test_device_receiver(number, pairing_info, responses, handle, _name, codenam
zip( zip(
range(1, 7), range(1, 7),
[pi_CCCC, pi_2011, pi_4066, pi_1007, pi_407B, pi_DDDD], [pi_CCCC, pi_2011, pi_4066, pi_1007, pi_407B, pi_DDDD],
[hidpp.r_empty, hidpp.r_keyboard_1, hidpp.r_keyboard_2, hidpp.r_mouse_1, hidpp.r_mouse_2, hidpp.r_mouse_3], [
fake_hidpp.r_empty,
fake_hidpp.r_keyboard_1,
fake_hidpp.r_keyboard_2,
fake_hidpp.r_mouse_1,
fake_hidpp.r_mouse_2,
fake_hidpp.r_mouse_3,
],
[None, 0x11, 0x11, 0x11, 0x11, 0x11], [None, 0x11, 0x11, 0x11, 0x11, 0x11],
[None, None, "12345678", None, None, "12345679"], # unitId [None, None, "12345678", None, None, "12345679"], # unitId
[None, None, "1234567890AB", None, None, "123456780000"], # modelId [None, None, "1234567890AB", None, None, "123456780000"], # modelId
@ -224,8 +249,8 @@ def test_device_ids(number, info, responses, handle, unitId, modelId, tid, kind,
mock_hid.side_effect = lambda x, y, z: x mock_hid.side_effect = lambda x, y, z: x
low_level = LowLevelInterfaceFake(responses) low_level = LowLevelInterfaceFake(responses)
low_level.request = partial(hidpp.request, hidpp.replace_number(responses, number)) low_level.request = partial(fake_hidpp.request, fake_hidpp.replace_number(responses, number))
low_level.ping = partial(hidpp.ping, hidpp.replace_number(responses, number)) low_level.ping = partial(fake_hidpp.ping, fake_hidpp.replace_number(responses, number))
test_device = device.Device(low_level, FakeReceiver(), number, True, info, handle=handle) test_device = device.Device(low_level, FakeReceiver(), number, True, info, handle=handle)
@ -244,19 +269,19 @@ class FakeDevice(device.Device): # a fully functional Device but its HID++ func
self.responses = responses self.responses = responses
super().__init__(LowLevelInterfaceFake(responses), *args, **kwargs) super().__init__(LowLevelInterfaceFake(responses), *args, **kwargs)
request = hidpp.Device.request request = fake_hidpp.Device.request
ping = hidpp.Device.ping ping = fake_hidpp.Device.ping
@pytest.mark.parametrize( @pytest.mark.parametrize(
"device_info, responses, protocol, led, keys, remap, gestures, backlight, profiles", "device_info, responses, protocol, led, keys, remap, gestures, backlight, profiles",
[ [
(di_CCCC, hidpp.r_empty, 1.0, type(None), None, None, None, None, None), (di_CCCC, fake_hidpp.r_empty, 1.0, type(None), None, None, None, None, None),
(di_C318, hidpp.r_empty, 1.0, type(None), None, None, None, None, None), (di_C318, fake_hidpp.r_empty, 1.0, type(None), None, None, None, None, None),
(di_B530, hidpp.r_keyboard_1, 1.0, type(None), None, None, None, None, None), (di_B530, fake_hidpp.r_keyboard_1, 1.0, type(None), None, None, None, None, None),
(di_B530, hidpp.r_keyboard_2, 2.0, type(None), 4, 0, 0, None, None), (di_B530, fake_hidpp.r_keyboard_2, 2.0, type(None), 4, 0, 0, None, None),
(di_B530, hidpp.complex_responses_1, 4.5, hidpp20.LEDEffectsInfo, 0, 0, 0, None, None), (di_B530, fake_hidpp.complex_responses_1, 4.5, hidpp20.LEDEffectsInfo, 0, 0, 0, None, None),
(di_B530, hidpp.complex_responses_2, 4.5, hidpp20.RGBEffectsInfo, 8, 3, 1, True, True), (di_B530, fake_hidpp.complex_responses_2, 4.5, hidpp20.RGBEffectsInfo, 8, 3, 1, True, True),
], ],
) )
def test_device_complex(device_info, responses, protocol, led, keys, remap, gestures, backlight, profiles, mocker): def test_device_complex(device_info, responses, protocol, led, keys, remap, gestures, backlight, profiles, mocker):
@ -289,12 +314,12 @@ def test_device_complex(device_info, responses, protocol, led, keys, remap, gest
@pytest.mark.parametrize( @pytest.mark.parametrize(
"device_info, responses, protocol, p, persister, settings", "device_info, responses, protocol, p, persister, settings",
[ [
(di_CCCC, hidpp.r_empty, 1.0, None, None, 0), (di_CCCC, fake_hidpp.r_empty, 1.0, None, None, 0),
(di_C318, hidpp.r_empty, 1.0, {}, {}, 0), (di_C318, fake_hidpp.r_empty, 1.0, {}, {}, 0),
(di_C318, hidpp.r_keyboard_1, 1.0, {"n": "n"}, {"n": "n"}, 1), (di_C318, fake_hidpp.r_keyboard_1, 1.0, {"n": "n"}, {"n": "n"}, 1),
(di_B530, hidpp.r_keyboard_2, 4.5, {"m": "m"}, {"m": "m"}, 1), (di_B530, fake_hidpp.r_keyboard_2, 4.5, {"m": "m"}, {"m": "m"}, 1),
(di_C068, hidpp.r_mouse_1, 1.0, {"o": "o"}, {"o": "o"}, 2), (di_C068, fake_hidpp.r_mouse_1, 1.0, {"o": "o"}, {"o": "o"}, 2),
(di_C08A, hidpp.r_mouse_2, 4.5, {"p": "p"}, {"p": "p"}, 0), (di_C08A, fake_hidpp.r_mouse_2, 4.5, {"p": "p"}, {"p": "p"}, 0),
], ],
) )
def test_device_settings(device_info, responses, protocol, p, persister, settings, mocker): def test_device_settings(device_info, responses, protocol, p, persister, settings, mocker):
@ -310,9 +335,21 @@ def test_device_settings(device_info, responses, protocol, p, persister, setting
@pytest.mark.parametrize( @pytest.mark.parametrize(
"device_info, responses, protocol, battery, changed", "device_info, responses, protocol, battery, changed",
[ [
(di_C318, hidpp.r_empty, 1.0, None, {"active": True, "alert": 0, "reason": None}), (di_C318, fake_hidpp.r_empty, 1.0, None, {"active": True, "alert": 0, "reason": None}),
(di_C318, hidpp.r_keyboard_1, 1.0, common.Battery(50, None, 0, None), {"active": True, "alert": 0, "reason": None}), (
(di_B530, hidpp.r_keyboard_2, 4.5, common.Battery(18, 52, None, None), {"active": True, "alert": 0, "reason": None}), di_C318,
fake_hidpp.r_keyboard_1,
1.0,
common.Battery(50, None, 0, None),
{"active": True, "alert": 0, "reason": None},
),
(
di_B530,
fake_hidpp.r_keyboard_2,
4.5,
common.Battery(18, 52, None, None),
{"active": True, "alert": 0, "reason": None},
),
], ],
) )
def test_device_battery(device_info, responses, protocol, battery, changed, mocker): def test_device_battery(device_info, responses, protocol, battery, changed, mocker):

View File

@ -23,16 +23,18 @@ from logitech_receiver import hidpp20
from logitech_receiver import hidpp20_constants from logitech_receiver import hidpp20_constants
from logitech_receiver import special_keys from logitech_receiver import special_keys
from . import hidpp from . import fake_hidpp
_hidpp20 = hidpp20.Hidpp20() _hidpp20 = hidpp20.Hidpp20()
device_offline = hidpp.Device("REGISTERS", False) device_offline = fake_hidpp.Device("REGISTERS", False)
device_registers = hidpp.Device("OFFLINE", True, 1.0) device_registers = fake_hidpp.Device("OFFLINE", True, 1.0)
device_nofeatures = hidpp.Device("NOFEATURES", True, 4.5) device_nofeatures = fake_hidpp.Device("NOFEATURES", True, 4.5)
device_zerofeatures = hidpp.Device("ZEROFEATURES", True, 4.5, [hidpp.Response("0000", 0x0000, "0001")]) device_zerofeatures = fake_hidpp.Device("ZEROFEATURES", True, 4.5, [fake_hidpp.Response("0000", 0x0000, "0001")])
device_broken = hidpp.Device("BROKEN", True, 4.5, [hidpp.Response("0500", 0x0000, "0001"), hidpp.Response(None, 0x0100)]) device_broken = fake_hidpp.Device(
device_standard = hidpp.Device("STANDARD", True, 4.5, hidpp.r_keyboard_2) "BROKEN", True, 4.5, [fake_hidpp.Response("0500", 0x0000, "0001"), fake_hidpp.Response(None, 0x0100)]
)
device_standard = fake_hidpp.Device("STANDARD", True, 4.5, fake_hidpp.r_keyboard_2)
@pytest.mark.parametrize( @pytest.mark.parametrize(
@ -210,15 +212,15 @@ def test_ReprogrammableKeyV4_key(device, index, cid, tid, flags, pos, group, gma
@pytest.mark.parametrize( @pytest.mark.parametrize(
"responses, index, mapped_to, remappable_to, mapping_flags", "responses, index, mapped_to, remappable_to, mapping_flags",
[ [
(hidpp.responses_key, 1, "Right Click", common.UnsortedNamedInts(Right_Click=81, Left_Click=80), []), (fake_hidpp.responses_key, 1, "Right Click", common.UnsortedNamedInts(Right_Click=81, Left_Click=80), []),
(hidpp.responses_key, 2, "Left Click", None, ["diverted"]), (fake_hidpp.responses_key, 2, "Left Click", None, ["diverted"]),
(hidpp.responses_key, 3, "Mouse Back Button", None, ["diverted", "persistently diverted"]), (fake_hidpp.responses_key, 3, "Mouse Back Button", None, ["diverted", "persistently diverted"]),
(hidpp.responses_key, 4, "Mouse Forward Button", None, ["diverted", "raw XY diverted"]), (fake_hidpp.responses_key, 4, "Mouse Forward Button", None, ["diverted", "raw XY diverted"]),
], ],
) )
# these fields need access all the key data, so start by setting up a device and its key data # these fields need access all the key data, so start by setting up a device and its key data
def test_ReprogrammableKeyV4_query(responses, index, mapped_to, remappable_to, mapping_flags): def test_ReprogrammableKeyV4_query(responses, index, mapped_to, remappable_to, mapping_flags):
device = hidpp.Device("KEY", responses=responses, feature=hidpp20_constants.FEATURE.REPROG_CONTROLS_V4, offset=5) device = fake_hidpp.Device("KEY", responses=responses, feature=hidpp20_constants.FEATURE.REPROG_CONTROLS_V4, offset=5)
device._keys = _hidpp20.get_keys(device) device._keys = _hidpp20.get_keys(device)
key = device.keys[index] key = device.keys[index]
@ -231,15 +233,15 @@ def test_ReprogrammableKeyV4_query(responses, index, mapped_to, remappable_to, m
@pytest.mark.parametrize( @pytest.mark.parametrize(
"responses, index, diverted, persistently_diverted, rawXY_reporting, remap, sets", "responses, index, diverted, persistently_diverted, rawXY_reporting, remap, sets",
[ [
(hidpp.responses_key, 1, True, False, True, 0x52, ["0051080000"]), (fake_hidpp.responses_key, 1, True, False, True, 0x52, ["0051080000"]),
(hidpp.responses_key, 2, False, True, False, 0x51, ["0052020000", "0052200000", "0052000051"]), (fake_hidpp.responses_key, 2, False, True, False, 0x51, ["0052020000", "0052200000", "0052000051"]),
(hidpp.responses_key, 3, False, True, True, 0x50, ["0053020000", "00530C0000", "0053300000", "0053000050"]), (fake_hidpp.responses_key, 3, False, True, True, 0x50, ["0053020000", "00530C0000", "0053300000", "0053000050"]),
(hidpp.responses_key, 4, False, False, False, 0x50, ["0056020000", "0056080000", "0056200000", "0056000050"]), (fake_hidpp.responses_key, 4, False, False, False, 0x50, ["0056020000", "0056080000", "0056200000", "0056000050"]),
], ],
) )
def test_ReprogrammableKeyV4_set(responses, index, diverted, persistently_diverted, rawXY_reporting, remap, sets, mocker): def test_ReprogrammableKeyV4_set(responses, index, diverted, persistently_diverted, rawXY_reporting, remap, sets, mocker):
responses += [hidpp.Response(r, 0x530, r) for r in sets] responses += [fake_hidpp.Response(r, 0x530, r) for r in sets]
device = hidpp.Device("KEY", responses=responses, feature=hidpp20_constants.FEATURE.REPROG_CONTROLS_V4, offset=5) device = fake_hidpp.Device("KEY", responses=responses, feature=hidpp20_constants.FEATURE.REPROG_CONTROLS_V4, offset=5)
device._keys = _hidpp20.get_keys(device) device._keys = _hidpp20.get_keys(device)
device._keys._ensure_all_keys_queried() # do this now so that the last requests are sets device._keys._ensure_all_keys_queried() # do this now so that the last requests are sets
spy_request = mocker.spy(device, "request") spy_request = mocker.spy(device, "request")
@ -275,23 +277,26 @@ def test_ReprogrammableKeyV4_set(responses, index, diverted, persistently_divert
key.remap(remap) key.remap(remap)
assert (key.mapped_to == remap) or (remap not in key.remappable_to and remap != 0) assert (key.mapped_to == remap) or (remap not in key.remappable_to and remap != 0)
hidpp.match_requests(len(sets), responses, spy_request.call_args_list) fake_hidpp.match_requests(len(sets), responses, spy_request.call_args_list)
@pytest.mark.parametrize( @pytest.mark.parametrize(
"r, index, cid, actionId, remapped, mask, status, action, modifiers, byts, remap", "r, index, cid, actionId, remapped, mask, status, action, modifiers, byts, remap",
[ [
(hidpp.responses_key, 1, 0x0051, 0x02, 0x0002, 0x01, 0, "Mouse Button: 2", "Cntrl+", "02000201", "01000400"), (fake_hidpp.responses_key, 1, 0x0051, 0x02, 0x0002, 0x01, 0, "Mouse Button: 2", "Cntrl+", "02000201", "01000400"),
(hidpp.responses_key, 2, 0x0052, 0x01, 0x0001, 0x00, 1, "Key: 1", "", "01000100", "02005004"), (fake_hidpp.responses_key, 2, 0x0052, 0x01, 0x0001, 0x00, 1, "Key: 1", "", "01000100", "02005004"),
(hidpp.responses_key, 3, 0x0053, 0x02, 0x0001, 0x00, 1, "Mouse Button: 1", "", "02000100", "7FFFFFFF"), (fake_hidpp.responses_key, 3, 0x0053, 0x02, 0x0001, 0x00, 1, "Mouse Button: 1", "", "02000100", "7FFFFFFF"),
], ],
) )
def test_RemappableAction(r, index, cid, actionId, remapped, mask, status, action, modifiers, byts, remap, mocker): def test_RemappableAction(r, index, cid, actionId, remapped, mask, status, action, modifiers, byts, remap, mocker):
if int(remap, 16) == special_keys.KEYS_Default: if int(remap, 16) == special_keys.KEYS_Default:
responses = r + [hidpp.Response("040000", 0x0000, "1C00"), hidpp.Response("00", 0x450, f"{cid:04X}" + "FF")] responses = r + [fake_hidpp.Response("040000", 0x0000, "1C00"), fake_hidpp.Response("00", 0x450, f"{cid:04X}" + "FF")]
else: else:
responses = r + [hidpp.Response("040000", 0x0000, "1C00"), hidpp.Response("00", 0x440, f"{cid:04X}" + "FF" + remap)] responses = r + [
device = hidpp.Device("KEY", responses=responses, feature=hidpp20_constants.FEATURE.REPROG_CONTROLS_V4, offset=5) fake_hidpp.Response("040000", 0x0000, "1C00"),
fake_hidpp.Response("00", 0x440, f"{cid:04X}" + "FF" + remap),
]
device = fake_hidpp.Device("KEY", responses=responses, feature=hidpp20_constants.FEATURE.REPROG_CONTROLS_V4, offset=5)
key = hidpp20.PersistentRemappableAction(device, index, cid, actionId, remapped, mask, status) key = hidpp20.PersistentRemappableAction(device, index, cid, actionId, remapped, mask, status)
spy_request = mocker.spy(device, "request") spy_request = mocker.spy(device, "request")
@ -312,7 +317,7 @@ def test_RemappableAction(r, index, cid, actionId, remapped, mask, status, actio
assert key.data_bytes.hex().upper() == (byts if int(remap, 16) == special_keys.KEYS_Default else remap) assert key.data_bytes.hex().upper() == (byts if int(remap, 16) == special_keys.KEYS_Default else remap)
if int(remap, 16) != special_keys.KEYS_Default: if int(remap, 16) != special_keys.KEYS_Default:
hidpp.match_requests(1, responses, spy_request.call_args_list) fake_hidpp.match_requests(1, responses, spy_request.call_args_list)
# KeysArray methods tested in KeysArrayV4 # KeysArray methods tested in KeysArrayV4
@ -378,7 +383,9 @@ def test_KeysArrayV4_index(key, index):
assert result == index assert result == index
device_key = hidpp.Device("KEY", responses=hidpp.responses_key, feature=hidpp20_constants.FEATURE.REPROG_CONTROLS_V4, offset=5) device_key = fake_hidpp.Device(
"KEY", responses=fake_hidpp.responses_key, feature=hidpp20_constants.FEATURE.REPROG_CONTROLS_V4, offset=5
)
@pytest.mark.parametrize( @pytest.mark.parametrize(
@ -434,13 +441,13 @@ def test_KeysArrayPersistent_index_error(device, index):
@pytest.mark.parametrize( @pytest.mark.parametrize(
"responses, key, index, mapped_to, capabilities", "responses, key, index, mapped_to, capabilities",
[ [
(hidpp.responses_remap, special_keys.CONTROL.Left_Button, 0, common.NamedInt(0x01, "Mouse Button Left"), 0x41), (fake_hidpp.responses_remap, special_keys.CONTROL.Left_Button, 0, common.NamedInt(0x01, "Mouse Button Left"), 0x41),
(hidpp.responses_remap, special_keys.CONTROL.Right_Button, 1, common.NamedInt(0x01, "Mouse Button Left"), 0x41), (fake_hidpp.responses_remap, special_keys.CONTROL.Right_Button, 1, common.NamedInt(0x01, "Mouse Button Left"), 0x41),
(hidpp.responses_remap, special_keys.CONTROL.Middle_Button, 2, common.NamedInt(0x51, "DOWN"), 0x41), (fake_hidpp.responses_remap, special_keys.CONTROL.Middle_Button, 2, common.NamedInt(0x51, "DOWN"), 0x41),
], ],
) )
def test_KeysArrayPersistent_key(responses, key, index, mapped_to, capabilities): def test_KeysArrayPersistent_key(responses, key, index, mapped_to, capabilities):
device = hidpp.Device("REMAP", responses=responses, feature=hidpp20_constants.FEATURE.PERSISTENT_REMAPPABLE_ACTION) device = fake_hidpp.Device("REMAP", responses=responses, feature=hidpp20_constants.FEATURE.PERSISTENT_REMAPPABLE_ACTION)
device._remap_keys = _hidpp20.get_remap_keys(device) device._remap_keys = _hidpp20.get_remap_keys(device)
device._remap_keys._ensure_all_keys_queried() device._remap_keys._ensure_all_keys_queried()
@ -494,13 +501,13 @@ def test_Gesture(device, low, high, next_index, next_diversion_index, name, cbe,
@pytest.mark.parametrize( @pytest.mark.parametrize(
"responses, gest, enabled, diverted, set_result, unset_result, divert_result, undivert_result", "responses, gest, enabled, diverted, set_result, unset_result, divert_result, undivert_result",
[ [
(hidpp.responses_gestures, 20, None, None, None, None, None, None), (fake_hidpp.responses_gestures, 20, None, None, None, None, None, None),
(hidpp.responses_gestures, 1, True, False, "01", "00", "01", "00"), (fake_hidpp.responses_gestures, 1, True, False, "01", "00", "01", "00"),
(hidpp.responses_gestures, 45, False, None, "01", "00", None, None), (fake_hidpp.responses_gestures, 45, False, None, "01", "00", None, None),
], ],
) )
def test_Gesture_set(responses, gest, enabled, diverted, set_result, unset_result, divert_result, undivert_result): def test_Gesture_set(responses, gest, enabled, diverted, set_result, unset_result, divert_result, undivert_result):
device = hidpp.Device("GESTURE", responses=responses, feature=hidpp20_constants.FEATURE.GESTURE_2) device = fake_hidpp.Device("GESTURE", responses=responses, feature=hidpp20_constants.FEATURE.GESTURE_2)
gestures = _hidpp20.get_gestures(device) gestures = _hidpp20.get_gestures(device)
gesture = gestures.gesture(gest) gesture = gestures.gesture(gest)
@ -516,11 +523,11 @@ def test_Gesture_set(responses, gest, enabled, diverted, set_result, unset_resul
@pytest.mark.parametrize( @pytest.mark.parametrize(
"responses, prm, id, index, size, value, default_value, write1, write2", "responses, prm, id, index, size, value, default_value, write1, write2",
[ [
(hidpp.responses_gestures, 4, common.NamedInt(4, "ScaleFactor"), 0, 2, 256, 256, "0080", "0180"), (fake_hidpp.responses_gestures, 4, common.NamedInt(4, "ScaleFactor"), 0, 2, 256, 256, "0080", "0180"),
], ],
) )
def test_Param(responses, prm, id, index, size, value, default_value, write1, write2): def test_Param(responses, prm, id, index, size, value, default_value, write1, write2):
device = hidpp.Device("GESTURE", responses=responses, feature=hidpp20_constants.FEATURE.GESTURE_2) device = fake_hidpp.Device("GESTURE", responses=responses, feature=hidpp20_constants.FEATURE.GESTURE_2)
gestures = _hidpp20.get_gestures(device) gestures = _hidpp20.get_gestures(device)
param = gestures.param(prm) param = gestures.param(prm)
@ -539,13 +546,13 @@ def test_Param(responses, prm, id, index, size, value, default_value, write1, wr
@pytest.mark.parametrize( @pytest.mark.parametrize(
"responses, id, s, byte_count, value, string", "responses, id, s, byte_count, value, string",
[ [
(hidpp.responses_gestures, 1, "DVI field width", 1, 8, "[DVI field width=8]"), (fake_hidpp.responses_gestures, 1, "DVI field width", 1, 8, "[DVI field width=8]"),
(hidpp.responses_gestures, 2, "field widths", 1, 8, "[field widths=8]"), (fake_hidpp.responses_gestures, 2, "field widths", 1, 8, "[field widths=8]"),
(hidpp.responses_gestures, 3, "period unit", 2, 2048, "[period unit=2048]"), (fake_hidpp.responses_gestures, 3, "period unit", 2, 2048, "[period unit=2048]"),
], ],
) )
def test_Spec(responses, id, s, byte_count, value, string): def test_Spec(responses, id, s, byte_count, value, string):
device = hidpp.Device("GESTURE", responses=responses, feature=hidpp20_constants.FEATURE.GESTURE_2) device = fake_hidpp.Device("GESTURE", responses=responses, feature=hidpp20_constants.FEATURE.GESTURE_2)
gestures = _hidpp20.get_gestures(device) gestures = _hidpp20.get_gestures(device)
spec = gestures.specs[id] spec = gestures.specs[id]
@ -558,7 +565,9 @@ def test_Spec(responses, id, s, byte_count, value, string):
def test_Gestures(): def test_Gestures():
device = hidpp.Device("GESTURES", responses=hidpp.responses_gestures, feature=hidpp20_constants.FEATURE.GESTURE_2) device = fake_hidpp.Device(
"GESTURES", responses=fake_hidpp.responses_gestures, feature=hidpp20_constants.FEATURE.GESTURE_2
)
gestures = _hidpp20.get_gestures(device) gestures = _hidpp20.get_gestures(device)
assert gestures assert gestures
@ -584,11 +593,11 @@ def test_Gestures():
responses_backlight = [ responses_backlight = [
hidpp.Response("010118000001020003000400", 0x0400), fake_hidpp.Response("010118000001020003000400", 0x0400),
hidpp.Response("0101FF00020003000400", 0x0410, "0101FF00020003000400"), fake_hidpp.Response("0101FF00020003000400", 0x0410, "0101FF00020003000400"),
] ]
device_backlight = hidpp.Device("BACKLIGHT", responses=responses_backlight, feature=hidpp20_constants.FEATURE.BACKLIGHT2) device_backlight = fake_hidpp.Device("BACKLIGHT", responses=responses_backlight, feature=hidpp20_constants.FEATURE.BACKLIGHT2)
def test_Backlight(): def test_Backlight():
@ -642,12 +651,26 @@ def test_LEDEffectSetting(hex, ID, color, speed, period, intensity, ramp, form):
@pytest.mark.parametrize( @pytest.mark.parametrize(
"feature, function, response, ID, capabilities, period", "feature, function, response, ID, capabilities, period",
[ [
[hidpp20_constants.FEATURE.COLOR_LED_EFFECTS, 0x20, hidpp.Response("0102000300040005", 0x0420, "010200"), 3, 4, 5], [
[hidpp20_constants.FEATURE.COLOR_LED_EFFECTS, 0x20, hidpp.Response("0102000700080009", 0x0420, "010200"), 7, 8, 9], hidpp20_constants.FEATURE.COLOR_LED_EFFECTS,
0x20,
fake_hidpp.Response("0102000300040005", 0x0420, "010200"),
3,
4,
5,
],
[
hidpp20_constants.FEATURE.COLOR_LED_EFFECTS,
0x20,
fake_hidpp.Response("0102000700080009", 0x0420, "010200"),
7,
8,
9,
],
], ],
) )
def test_LEDEffectInfo(feature, function, response, ID, capabilities, period): def test_LEDEffectInfo(feature, function, response, ID, capabilities, period):
device = hidpp.Device(feature=feature, responses=[response]) device = fake_hidpp.Device(feature=feature, responses=[response])
info = hidpp20.LEDEffectInfo(feature, function, device, 1, 2) info = hidpp20.LEDEffectInfo(feature, function, device, 1, 2)
@ -661,12 +684,12 @@ def test_LEDEffectInfo(feature, function, response, ID, capabilities, period):
@pytest.mark.parametrize( @pytest.mark.parametrize(
"feature, function, offset, effect_function, responses, index, location, count, id_1", "feature, function, offset, effect_function, responses, index, location, count, id_1",
[ [
[hidpp20_constants.FEATURE.COLOR_LED_EFFECTS, 0x10, 0, 0x20, hidpp.zone_responses_1, 0, 1, 2, 0xB], [hidpp20_constants.FEATURE.COLOR_LED_EFFECTS, 0x10, 0, 0x20, fake_hidpp.zone_responses_1, 0, 1, 2, 0xB],
[hidpp20_constants.FEATURE.RGB_EFFECTS, 0x00, 1, 0x00, hidpp.zone_responses_2, 0, 1, 2, 2], [hidpp20_constants.FEATURE.RGB_EFFECTS, 0x00, 1, 0x00, fake_hidpp.zone_responses_2, 0, 1, 2, 2],
], ],
) )
def test_LEDZoneInfo(feature, function, offset, effect_function, responses, index, location, count, id_1): def test_LEDZoneInfo(feature, function, offset, effect_function, responses, index, location, count, id_1):
device = hidpp.Device(feature=feature, responses=responses, offset=0x07) device = fake_hidpp.Device(feature=feature, responses=responses, offset=0x07)
zone = hidpp20.LEDZoneInfo(feature, function, offset, effect_function, device, index) zone = hidpp20.LEDZoneInfo(feature, function, offset, effect_function, device, index)
@ -680,13 +703,17 @@ def test_LEDZoneInfo(feature, function, offset, effect_function, responses, inde
@pytest.mark.parametrize( @pytest.mark.parametrize(
"responses, setting, expected_command", "responses, setting, expected_command",
[ [
[hidpp.zone_responses_1, hidpp20.LEDEffectSetting(ID=0), None], [fake_hidpp.zone_responses_1, hidpp20.LEDEffectSetting(ID=0), None],
[hidpp.zone_responses_1, hidpp20.LEDEffectSetting(ID=3, period=0x20, intensity=0x50), "000000000000000020500000"], [fake_hidpp.zone_responses_1, hidpp20.LEDEffectSetting(ID=3, period=0x20, intensity=0x50), "000000000000000020500000"],
[hidpp.zone_responses_1, hidpp20.LEDEffectSetting(ID=0xB, color=0x808080, period=0x20), "000180808000002000000000"], [
fake_hidpp.zone_responses_1,
hidpp20.LEDEffectSetting(ID=0xB, color=0x808080, period=0x20),
"000180808000002000000000",
],
], ],
) )
def test_LEDZoneInfo_to_command(responses, setting, expected_command): def test_LEDZoneInfo_to_command(responses, setting, expected_command):
device = hidpp.Device(feature=hidpp20_constants.FEATURE.COLOR_LED_EFFECTS, responses=responses, offset=0x07) device = fake_hidpp.Device(feature=hidpp20_constants.FEATURE.COLOR_LED_EFFECTS, responses=responses, offset=0x07)
zone = hidpp20.LEDZoneInfo(hidpp20_constants.FEATURE.COLOR_LED_EFFECTS, 0x10, 0, 0x20, device, 0) zone = hidpp20.LEDZoneInfo(hidpp20_constants.FEATURE.COLOR_LED_EFFECTS, 0x10, 0, 0x20, device, 0)
command = zone.to_command(setting) command = zone.to_command(setting)
@ -697,12 +724,12 @@ def test_LEDZoneInfo_to_command(responses, setting, expected_command):
@pytest.mark.parametrize( @pytest.mark.parametrize(
"feature, cls, responses, readable, count, count_0", "feature, cls, responses, readable, count, count_0",
[ [
[hidpp20_constants.FEATURE.COLOR_LED_EFFECTS, hidpp20.LEDEffectsInfo, hidpp.effects_responses_1, 1, 1, 2], [hidpp20_constants.FEATURE.COLOR_LED_EFFECTS, hidpp20.LEDEffectsInfo, fake_hidpp.effects_responses_1, 1, 1, 2],
[hidpp20_constants.FEATURE.RGB_EFFECTS, hidpp20.RGBEffectsInfo, hidpp.effects_responses_2, 1, 1, 2], [hidpp20_constants.FEATURE.RGB_EFFECTS, hidpp20.RGBEffectsInfo, fake_hidpp.effects_responses_2, 1, 1, 2],
], ],
) )
def test_LED_RGB_EffectsInfo(feature, cls, responses, readable, count, count_0): def test_LED_RGB_EffectsInfo(feature, cls, responses, readable, count, count_0):
device = hidpp.Device(feature=feature, responses=responses, offset=0x07) device = fake_hidpp.Device(feature=feature, responses=responses, offset=0x07)
effects = cls(device) effects = cls(device)
@ -721,7 +748,7 @@ def test_LED_RGB_EffectsInfo(feature, cls, responses, readable, count, count_0):
("80020454", 0x8, None, None, 0x02, 0x54, 0x04, None, None), ("80020454", 0x8, None, None, 0x02, 0x54, 0x04, None, None),
("80030454", 0x8, None, None, 0x03, 0x0454, None, None, None), ("80030454", 0x8, None, None, 0x03, 0x0454, None, None, None),
("900AFF01", 0x9, None, None, None, 0x0A, None, 0x01, None), ("900AFF01", 0x9, None, None, None, 0x0A, None, 0x01, None),
("709090A0", 0x7, None, None, None, None, None, None, b"\x70\x90\x90\xA0"), ("709090A0", 0x7, None, None, None, None, None, None, b"\x70\x90\x90\xa0"),
], ],
) )
def test_button_bytes(hex, behavior, sector, address, typ, val, modifiers, data, byt): def test_button_bytes(hex, behavior, sector, address, typ, val, modifiers, data, byt):
@ -820,13 +847,15 @@ def test_OnboardProfile_bytes(hex, name, sector, enabled, buttons, gbuttons, res
@pytest.mark.parametrize( @pytest.mark.parametrize(
"responses, name, count, buttons, gbuttons, sectors, size", "responses, name, count, buttons, gbuttons, sectors, size",
[ [
(hidpp.responses_profiles, "ONB", 1, 2, 2, 1, 254), (fake_hidpp.responses_profiles, "ONB", 1, 2, 2, 1, 254),
(hidpp.responses_profiles_rom, "ONB", 1, 2, 2, 1, 254), (fake_hidpp.responses_profiles_rom, "ONB", 1, 2, 2, 1, 254),
(hidpp.responses_profiles_rom_2, "ONB", 1, 2, 2, 1, 254), (fake_hidpp.responses_profiles_rom_2, "ONB", 1, 2, 2, 1, 254),
], ],
) )
def test_OnboardProfiles_device(responses, name, count, buttons, gbuttons, sectors, size): def test_OnboardProfiles_device(responses, name, count, buttons, gbuttons, sectors, size):
device = hidpp.Device(name, True, 4.5, responses=responses, feature=hidpp20_constants.FEATURE.ONBOARD_PROFILES, offset=0x9) device = fake_hidpp.Device(
name, True, 4.5, responses=responses, feature=hidpp20_constants.FEATURE.ONBOARD_PROFILES, offset=0x9
)
device._profiles = None device._profiles = None
profiles = _hidpp20.get_profiles(device) profiles = _hidpp20.get_profiles(device)

View File

@ -20,18 +20,18 @@ from logitech_receiver import common
from logitech_receiver import hidpp20 from logitech_receiver import hidpp20
from logitech_receiver import hidpp20_constants from logitech_receiver import hidpp20_constants
from . import hidpp from . import fake_hidpp
_hidpp20 = hidpp20.Hidpp20() _hidpp20 = hidpp20.Hidpp20()
def test_get_firmware(): def test_get_firmware():
responses = [ responses = [
hidpp.Response("02FFFF", 0x0400), fake_hidpp.Response("02FFFF", 0x0400),
hidpp.Response("01414243030401000101000102030405", 0x0410, "00"), fake_hidpp.Response("01414243030401000101000102030405", 0x0410, "00"),
hidpp.Response("02414243030401000101000102030405", 0x0410, "01"), fake_hidpp.Response("02414243030401000101000102030405", 0x0410, "01"),
] ]
device = hidpp.Device(responses=responses, feature=hidpp20_constants.FEATURE.DEVICE_FW_VERSION) device = fake_hidpp.Device(responses=responses, feature=hidpp20_constants.FEATURE.DEVICE_FW_VERSION)
result = _hidpp20.get_firmware(device) result = _hidpp20.get_firmware(device)
@ -41,8 +41,8 @@ def test_get_firmware():
def test_get_ids(): def test_get_ids():
responses = [hidpp.Response("FF12345678000D123456789ABC", 0x0400)] responses = [fake_hidpp.Response("FF12345678000D123456789ABC", 0x0400)]
device = hidpp.Device(responses=responses, feature=hidpp20_constants.FEATURE.DEVICE_FW_VERSION) device = fake_hidpp.Device(responses=responses, feature=hidpp20_constants.FEATURE.DEVICE_FW_VERSION)
unitId, modelId, tid_map = _hidpp20.get_ids(device) unitId, modelId, tid_map = _hidpp20.get_ids(device)
@ -52,8 +52,8 @@ def test_get_ids():
def test_get_kind(): def test_get_kind():
responses = [hidpp.Response("00", 0x0420)] responses = [fake_hidpp.Response("00", 0x0420)]
device = hidpp.Device(responses=responses, feature=hidpp20_constants.FEATURE.DEVICE_NAME) device = fake_hidpp.Device(responses=responses, feature=hidpp20_constants.FEATURE.DEVICE_NAME)
result = _hidpp20.get_kind(device) result = _hidpp20.get_kind(device)
@ -63,11 +63,11 @@ def test_get_kind():
def test_get_name(): def test_get_name():
responses = [ responses = [
hidpp.Response("12", 0x0400), fake_hidpp.Response("12", 0x0400),
hidpp.Response("4142434445464748494A4B4C4D4E4F", 0x0410, "00"), fake_hidpp.Response("4142434445464748494A4B4C4D4E4F", 0x0410, "00"),
hidpp.Response("505152530000000000000000000000", 0x0410, "0F"), fake_hidpp.Response("505152530000000000000000000000", 0x0410, "0F"),
] ]
device = hidpp.Device(responses=responses, feature=hidpp20_constants.FEATURE.DEVICE_NAME) device = fake_hidpp.Device(responses=responses, feature=hidpp20_constants.FEATURE.DEVICE_NAME)
result = _hidpp20.get_name(device) result = _hidpp20.get_name(device)
@ -76,11 +76,11 @@ def test_get_name():
def test_get_friendly_name(): def test_get_friendly_name():
responses = [ responses = [
hidpp.Response("12", 0x0400), fake_hidpp.Response("12", 0x0400),
hidpp.Response("004142434445464748494A4B4C4D4E", 0x0410, "00"), fake_hidpp.Response("004142434445464748494A4B4C4D4E", 0x0410, "00"),
hidpp.Response("0E4F50515253000000000000000000", 0x0410, "0E"), fake_hidpp.Response("0E4F50515253000000000000000000", 0x0410, "0E"),
] ]
device = hidpp.Device(responses=responses, feature=hidpp20_constants.FEATURE.DEVICE_FRIENDLY_NAME) device = fake_hidpp.Device(responses=responses, feature=hidpp20_constants.FEATURE.DEVICE_FRIENDLY_NAME)
result = _hidpp20.get_friendly_name(device) result = _hidpp20.get_friendly_name(device)
@ -88,8 +88,8 @@ def test_get_friendly_name():
def test_get_battery_status(): def test_get_battery_status():
responses = [hidpp.Response("502000FFFF", 0x0400)] responses = [fake_hidpp.Response("502000FFFF", 0x0400)]
device = hidpp.Device(responses=responses, feature=hidpp20_constants.FEATURE.BATTERY_STATUS) device = fake_hidpp.Device(responses=responses, feature=hidpp20_constants.FEATURE.BATTERY_STATUS)
feature, battery = _hidpp20.get_battery_status(device) feature, battery = _hidpp20.get_battery_status(device)
@ -100,8 +100,8 @@ def test_get_battery_status():
def test_get_battery_voltage(): def test_get_battery_voltage():
responses = [hidpp.Response("1000FFFFFF", 0x0400)] responses = [fake_hidpp.Response("1000FFFFFF", 0x0400)]
device = hidpp.Device(responses=responses, feature=hidpp20_constants.FEATURE.BATTERY_VOLTAGE) device = fake_hidpp.Device(responses=responses, feature=hidpp20_constants.FEATURE.BATTERY_VOLTAGE)
feature, battery = _hidpp20.get_battery_voltage(device) feature, battery = _hidpp20.get_battery_voltage(device)
@ -112,8 +112,8 @@ def test_get_battery_voltage():
def test_get_battery_unified(): def test_get_battery_unified():
responses = [hidpp.Response("500100FFFF", 0x0410)] responses = [fake_hidpp.Response("500100FFFF", 0x0410)]
device = hidpp.Device(responses=responses, feature=hidpp20_constants.FEATURE.UNIFIED_BATTERY) device = fake_hidpp.Device(responses=responses, feature=hidpp20_constants.FEATURE.UNIFIED_BATTERY)
feature, battery = _hidpp20.get_battery_unified(device) feature, battery = _hidpp20.get_battery_unified(device)
@ -123,8 +123,8 @@ def test_get_battery_unified():
def test_get_adc_measurement(): def test_get_adc_measurement():
responses = [hidpp.Response("100003", 0x0400)] responses = [fake_hidpp.Response("100003", 0x0400)]
device = hidpp.Device(responses=responses, feature=hidpp20_constants.FEATURE.ADC_MEASUREMENT) device = fake_hidpp.Device(responses=responses, feature=hidpp20_constants.FEATURE.ADC_MEASUREMENT)
feature, battery = _hidpp20.get_adc_measurement(device) feature, battery = _hidpp20.get_adc_measurement(device)
@ -135,8 +135,8 @@ def test_get_adc_measurement():
def test_get_battery(): def test_get_battery():
responses = [hidpp.Response("502000FFFF", 0x0400)] responses = [fake_hidpp.Response("502000FFFF", 0x0400)]
device = hidpp.Device(responses=responses, feature=hidpp20_constants.FEATURE.BATTERY_STATUS) device = fake_hidpp.Device(responses=responses, feature=hidpp20_constants.FEATURE.BATTERY_STATUS)
feature, battery = _hidpp20.get_battery(device, hidpp20_constants.FEATURE.BATTERY_STATUS) feature, battery = _hidpp20.get_battery(device, hidpp20_constants.FEATURE.BATTERY_STATUS)
@ -148,11 +148,11 @@ def test_get_battery():
def test_get_battery_none(): def test_get_battery_none():
responses = [ responses = [
hidpp.Response(None, 0x0000, f"{hidpp20_constants.FEATURE.BATTERY_STATUS:0>4X}"), fake_hidpp.Response(None, 0x0000, f"{hidpp20_constants.FEATURE.BATTERY_STATUS:0>4X}"),
hidpp.Response(None, 0x0000, f"{hidpp20_constants.FEATURE.BATTERY_VOLTAGE:0>4X}"), fake_hidpp.Response(None, 0x0000, f"{hidpp20_constants.FEATURE.BATTERY_VOLTAGE:0>4X}"),
hidpp.Response("500100ffff", 0x0410), fake_hidpp.Response("500100ffff", 0x0410),
] ]
device = hidpp.Device(responses=responses, feature=hidpp20_constants.FEATURE.UNIFIED_BATTERY) device = fake_hidpp.Device(responses=responses, feature=hidpp20_constants.FEATURE.UNIFIED_BATTERY)
feature, battery = _hidpp20.get_battery(device, None) feature, battery = _hidpp20.get_battery(device, None)
@ -169,8 +169,8 @@ def test_get_battery_none():
def test_get_mouse_pointer_info(): def test_get_mouse_pointer_info():
responses = [hidpp.Response("01000A", 0x0400)] responses = [fake_hidpp.Response("01000A", 0x0400)]
device = hidpp.Device(responses=responses, feature=hidpp20_constants.FEATURE.MOUSE_POINTER) device = fake_hidpp.Device(responses=responses, feature=hidpp20_constants.FEATURE.MOUSE_POINTER)
result = _hidpp20.get_mouse_pointer_info(device) result = _hidpp20.get_mouse_pointer_info(device)
@ -183,8 +183,8 @@ def test_get_mouse_pointer_info():
def test_get_vertical_scrolling_info(): def test_get_vertical_scrolling_info():
responses = [hidpp.Response("01080C", 0x0400)] responses = [fake_hidpp.Response("01080C", 0x0400)]
device = hidpp.Device(responses=responses, feature=hidpp20_constants.FEATURE.VERTICAL_SCROLLING) device = fake_hidpp.Device(responses=responses, feature=hidpp20_constants.FEATURE.VERTICAL_SCROLLING)
result = _hidpp20.get_vertical_scrolling_info(device) result = _hidpp20.get_vertical_scrolling_info(device)
@ -192,8 +192,8 @@ def test_get_vertical_scrolling_info():
def test_get_hi_res_scrolling_info(): def test_get_hi_res_scrolling_info():
responses = [hidpp.Response("0102", 0x0400)] responses = [fake_hidpp.Response("0102", 0x0400)]
device = hidpp.Device(responses=responses, feature=hidpp20_constants.FEATURE.HI_RES_SCROLLING) device = fake_hidpp.Device(responses=responses, feature=hidpp20_constants.FEATURE.HI_RES_SCROLLING)
mode, resolution = _hidpp20.get_hi_res_scrolling_info(device) mode, resolution = _hidpp20.get_hi_res_scrolling_info(device)
@ -202,8 +202,8 @@ def test_get_hi_res_scrolling_info():
def test_get_pointer_speed_info(): def test_get_pointer_speed_info():
responses = [hidpp.Response("0102", 0x0400)] responses = [fake_hidpp.Response("0102", 0x0400)]
device = hidpp.Device(responses=responses, feature=hidpp20_constants.FEATURE.POINTER_SPEED) device = fake_hidpp.Device(responses=responses, feature=hidpp20_constants.FEATURE.POINTER_SPEED)
result = _hidpp20.get_pointer_speed_info(device) result = _hidpp20.get_pointer_speed_info(device)
@ -211,8 +211,8 @@ def test_get_pointer_speed_info():
def test_get_lowres_wheel_status(): def test_get_lowres_wheel_status():
responses = [hidpp.Response("01", 0x0400)] responses = [fake_hidpp.Response("01", 0x0400)]
device = hidpp.Device(responses=responses, feature=hidpp20_constants.FEATURE.LOWRES_WHEEL) device = fake_hidpp.Device(responses=responses, feature=hidpp20_constants.FEATURE.LOWRES_WHEEL)
result = _hidpp20.get_lowres_wheel_status(device) result = _hidpp20.get_lowres_wheel_status(device)
@ -221,11 +221,11 @@ def test_get_lowres_wheel_status():
def test_get_hires_wheel(): def test_get_hires_wheel():
responses = [ responses = [
hidpp.Response("010C", 0x0400), fake_hidpp.Response("010C", 0x0400),
hidpp.Response("05FF", 0x0410), fake_hidpp.Response("05FF", 0x0410),
hidpp.Response("03FF", 0x0430), fake_hidpp.Response("03FF", 0x0430),
] ]
device = hidpp.Device(responses=responses, feature=hidpp20_constants.FEATURE.HIRES_WHEEL) device = fake_hidpp.Device(responses=responses, feature=hidpp20_constants.FEATURE.HIRES_WHEEL)
multi, has_invert, has_ratchet, inv, res, target, ratchet = _hidpp20.get_hires_wheel(device) multi, has_invert, has_ratchet, inv, res, target, ratchet = _hidpp20.get_hires_wheel(device)
@ -239,8 +239,8 @@ def test_get_hires_wheel():
def test_get_new_fn_inversion(): def test_get_new_fn_inversion():
responses = [hidpp.Response("0300", 0x0400)] responses = [fake_hidpp.Response("0300", 0x0400)]
device = hidpp.Device(responses=responses, feature=hidpp20_constants.FEATURE.NEW_FN_INVERSION) device = fake_hidpp.Device(responses=responses, feature=hidpp20_constants.FEATURE.NEW_FN_INVERSION)
result = _hidpp20.get_new_fn_inversion(device) result = _hidpp20.get_new_fn_inversion(device)
@ -255,25 +255,25 @@ def mock_gethostname(mocker):
@pytest.mark.parametrize( @pytest.mark.parametrize(
"responses, expected_result", "responses, expected_result",
[ [
([hidpp.Response(None, 0x0400)], {}), ([fake_hidpp.Response(None, 0x0400)], {}),
([hidpp.Response("02000000", 0x0400)], {}), ([fake_hidpp.Response("02000000", 0x0400)], {}),
( (
[ [
hidpp.Response("03000200", 0x0400), fake_hidpp.Response("03000200", 0x0400),
hidpp.Response("FF01FFFF05FFFF", 0x0410, "00"), fake_hidpp.Response("FF01FFFF05FFFF", 0x0410, "00"),
hidpp.Response("0000414243444500FFFFFFFFFF", 0x0430, "0000"), fake_hidpp.Response("0000414243444500FFFFFFFFFF", 0x0430, "0000"),
hidpp.Response("FF01FFFF10FFFF", 0x0410, "01"), fake_hidpp.Response("FF01FFFF10FFFF", 0x0410, "01"),
hidpp.Response("01004142434445464748494A4B4C4D", 0x0430, "0100"), fake_hidpp.Response("01004142434445464748494A4B4C4D", 0x0430, "0100"),
hidpp.Response("01134E4F5000FFFFFFFFFFFFFFFFFF", 0x0430, "010E"), fake_hidpp.Response("01134E4F5000FFFFFFFFFFFFFFFFFF", 0x0430, "010E"),
hidpp.Response("000000000008", 0x0410, "00"), fake_hidpp.Response("000000000008", 0x0410, "00"),
hidpp.Response("0208", 0x0440, "000041424344454647"), fake_hidpp.Response("0208", 0x0440, "000041424344454647"),
], ],
{0: (True, "ABCDEFG"), 1: (True, "ABCDEFGHIJKLMNO")}, {0: (True, "ABCDEFG"), 1: (True, "ABCDEFGHIJKLMNO")},
), ),
], ],
) )
def test_get_host_names(responses, expected_result, mock_gethostname): def test_get_host_names(responses, expected_result, mock_gethostname):
device = hidpp.Device(responses=responses, feature=hidpp20_constants.FEATURE.HOSTS_INFO) device = fake_hidpp.Device(responses=responses, feature=hidpp20_constants.FEATURE.HOSTS_INFO)
result = _hidpp20.get_host_names(device) result = _hidpp20.get_host_names(device)
@ -283,28 +283,28 @@ def test_get_host_names(responses, expected_result, mock_gethostname):
@pytest.mark.parametrize( @pytest.mark.parametrize(
"responses, expected_result", "responses, expected_result",
[ [
([hidpp.Response(None, 0x0400)], None), ([fake_hidpp.Response(None, 0x0400)], None),
( (
[ [
hidpp.Response("03000002", 0x0400), fake_hidpp.Response("03000002", 0x0400),
hidpp.Response("000000000008", 0x0410, "02"), fake_hidpp.Response("000000000008", 0x0410, "02"),
hidpp.Response("020E", 0x0440, "02004142434445464748494A4B4C4D4E"), fake_hidpp.Response("020E", 0x0440, "02004142434445464748494A4B4C4D4E"),
], ],
True, True,
), ),
( (
[ [
hidpp.Response("03000002", 0x0400), fake_hidpp.Response("03000002", 0x0400),
hidpp.Response("000000000014", 0x0410, "02"), fake_hidpp.Response("000000000014", 0x0410, "02"),
hidpp.Response("020E", 0x0440, "02004142434445464748494A4B4C4D4E"), fake_hidpp.Response("020E", 0x0440, "02004142434445464748494A4B4C4D4E"),
hidpp.Response("0214", 0x0440, "020E4F505152535455565758"), fake_hidpp.Response("0214", 0x0440, "020E4F505152535455565758"),
], ],
True, True,
), ),
], ],
) )
def test_set_host_name(responses, expected_result): def test_set_host_name(responses, expected_result):
device = hidpp.Device(responses=responses, feature=hidpp20_constants.FEATURE.HOSTS_INFO) device = fake_hidpp.Device(responses=responses, feature=hidpp20_constants.FEATURE.HOSTS_INFO)
result = _hidpp20.set_host_name(device, "ABCDEFGHIJKLMNOPQRSTUVWX") result = _hidpp20.set_host_name(device, "ABCDEFGHIJKLMNOPQRSTUVWX")
@ -312,8 +312,8 @@ def test_set_host_name(responses, expected_result):
def test_get_onboard_mode(): def test_get_onboard_mode():
responses = [hidpp.Response("03FFFFFFFF", 0x0420)] responses = [fake_hidpp.Response("03FFFFFFFF", 0x0420)]
device = hidpp.Device(responses=responses, feature=hidpp20_constants.FEATURE.ONBOARD_PROFILES) device = fake_hidpp.Device(responses=responses, feature=hidpp20_constants.FEATURE.ONBOARD_PROFILES)
result = _hidpp20.get_onboard_mode(device) result = _hidpp20.get_onboard_mode(device)
@ -321,8 +321,8 @@ def test_get_onboard_mode():
def test_set_onboard_mode(): def test_set_onboard_mode():
responses = [hidpp.Response("03FFFFFFFF", 0x0410, "03")] responses = [fake_hidpp.Response("03FFFFFFFF", 0x0410, "03")]
device = hidpp.Device(responses=responses, feature=hidpp20_constants.FEATURE.ONBOARD_PROFILES) device = fake_hidpp.Device(responses=responses, feature=hidpp20_constants.FEATURE.ONBOARD_PROFILES)
res = _hidpp20.set_onboard_mode(device, 0x3) res = _hidpp20.set_onboard_mode(device, 0x3)
@ -332,11 +332,11 @@ def test_set_onboard_mode():
@pytest.mark.parametrize( @pytest.mark.parametrize(
"responses, expected_result", "responses, expected_result",
[ [
([hidpp.Response("03FFFF", 0x0420)], "1ms"), ([fake_hidpp.Response("03FFFF", 0x0420)], "1ms"),
( (
[ [
hidpp.Response(None, 0x0000, f"{hidpp20_constants.FEATURE.REPORT_RATE:0>4X}"), fake_hidpp.Response(None, 0x0000, f"{hidpp20_constants.FEATURE.REPORT_RATE:0>4X}"),
hidpp.Response("04FFFF", 0x0420), fake_hidpp.Response("04FFFF", 0x0420),
], ],
"500us", "500us",
), ),
@ -346,7 +346,7 @@ def test_get_polling_rate(
responses, responses,
expected_result, expected_result,
): ):
device = hidpp.Device(responses=responses, feature=hidpp20_constants.FEATURE.EXTENDED_ADJUSTABLE_REPORT_RATE) device = fake_hidpp.Device(responses=responses, feature=hidpp20_constants.FEATURE.EXTENDED_ADJUSTABLE_REPORT_RATE)
result = _hidpp20.get_polling_rate(device) result = _hidpp20.get_polling_rate(device)
@ -354,8 +354,8 @@ def test_get_polling_rate(
def test_get_remaining_pairing(): def test_get_remaining_pairing():
responses = [hidpp.Response("03FFFF", 0x0400)] responses = [fake_hidpp.Response("03FFFF", 0x0400)]
device = hidpp.Device(responses=responses, feature=hidpp20_constants.FEATURE.REMAINING_PAIRING) device = fake_hidpp.Device(responses=responses, feature=hidpp20_constants.FEATURE.REMAINING_PAIRING)
result = _hidpp20.get_remaining_pairing(device) result = _hidpp20.get_remaining_pairing(device)
@ -363,8 +363,8 @@ def test_get_remaining_pairing():
def test_config_change(): def test_config_change():
responses = [hidpp.Response("03FFFF", 0x0410, "02")] responses = [fake_hidpp.Response("03FFFF", 0x0410, "02")]
device = hidpp.Device(responses=responses, feature=hidpp20_constants.FEATURE.CONFIG_CHANGE) device = fake_hidpp.Device(responses=responses, feature=hidpp20_constants.FEATURE.CONFIG_CHANGE)
result = _hidpp20.config_change(device, 0x2) result = _hidpp20.config_change(device, 0x2)
@ -383,7 +383,7 @@ def test_decipher_battery_status():
def test_decipher_battery_voltage(): def test_decipher_battery_voltage():
report = b"\x10\x00\xFF\xff\xff" report = b"\x10\x00\xff\xff\xff"
feature, battery = hidpp20.decipher_battery_voltage(report) feature, battery = hidpp20.decipher_battery_voltage(report)

View File

@ -10,7 +10,7 @@ from logitech_receiver import common
from logitech_receiver import exceptions from logitech_receiver import exceptions
from logitech_receiver import receiver from logitech_receiver import receiver
from . import hidpp from . import fake_hidpp
@pytest.mark.parametrize( @pytest.mark.parametrize(
@ -55,38 +55,38 @@ def mock_base():
responses_unifying = [ responses_unifying = [
hidpp.Response("000000", 0x8003, "FF"), fake_hidpp.Response("000000", 0x8003, "FF"),
hidpp.Response("000300", 0x8102), fake_hidpp.Response("000300", 0x8102),
hidpp.Response("0316CC9CB40506220000000000000000", 0x83B5, "03"), fake_hidpp.Response("0316CC9CB40506220000000000000000", 0x83B5, "03"),
hidpp.Response("20200840820402020700000000000000", 0x83B5, "20"), fake_hidpp.Response("20200840820402020700000000000000", 0x83B5, "20"),
hidpp.Response("21211420110400010D1A000000000000", 0x83B5, "21"), fake_hidpp.Response("21211420110400010D1A000000000000", 0x83B5, "21"),
hidpp.Response("22220840660402010700000000020000", 0x83B5, "22"), fake_hidpp.Response("22220840660402010700000000020000", 0x83B5, "22"),
hidpp.Response("30198E3EB80600000001000000000000", 0x83B5, "30"), fake_hidpp.Response("30198E3EB80600000001000000000000", 0x83B5, "30"),
hidpp.Response("31811119511A40000002000000000000", 0x83B5, "31"), fake_hidpp.Response("31811119511A40000002000000000000", 0x83B5, "31"),
hidpp.Response("32112C46EA1E40000003000000000000", 0x83B5, "32"), fake_hidpp.Response("32112C46EA1E40000003000000000000", 0x83B5, "32"),
hidpp.Response("400B4D58204D61737465722033000000", 0x83B5, "40"), fake_hidpp.Response("400B4D58204D61737465722033000000", 0x83B5, "40"),
hidpp.Response("41044B35323020202020202020202020", 0x83B5, "41"), fake_hidpp.Response("41044B35323020202020202020202020", 0x83B5, "41"),
hidpp.Response("42054372616674000000000000000000", 0x83B5, "42"), fake_hidpp.Response("42054372616674000000000000000000", 0x83B5, "42"),
hidpp.Response("012411", 0x81F1, "01"), fake_hidpp.Response("012411", 0x81F1, "01"),
hidpp.Response("020036", 0x81F1, "02"), fake_hidpp.Response("020036", 0x81F1, "02"),
hidpp.Response("03AAAC", 0x81F1, "03"), fake_hidpp.Response("03AAAC", 0x81F1, "03"),
hidpp.Response("040209", 0x81F1, "04"), fake_hidpp.Response("040209", 0x81F1, "04"),
] ]
responses_c534 = [ responses_c534 = [
hidpp.Response("000000", 0x8003, "FF", handle=0x12), fake_hidpp.Response("000000", 0x8003, "FF", handle=0x12),
hidpp.Response("000209", 0x8102, handle=0x12), fake_hidpp.Response("000209", 0x8102, handle=0x12),
hidpp.Response("0316CC9CB40502220000000000000000", 0x83B5, "03", handle=0x12), fake_hidpp.Response("0316CC9CB40502220000000000000000", 0x83B5, "03", handle=0x12),
hidpp.Response("00000445AB", 0x83B5, "04", handle=0x12), fake_hidpp.Response("00000445AB", 0x83B5, "04", handle=0x12),
] ]
responses_unusual = [ responses_unusual = [
hidpp.Response("000000", 0x8003, "FF", handle=0x13), fake_hidpp.Response("000000", 0x8003, "FF", handle=0x13),
hidpp.Response("000300", 0x8102, handle=0x13), fake_hidpp.Response("000300", 0x8102, handle=0x13),
hidpp.Response("00000445AB", 0x83B5, "04", handle=0x13), fake_hidpp.Response("00000445AB", 0x83B5, "04", handle=0x13),
hidpp.Response("0326CC9CB40508220000000000000000", 0x83B5, "03", handle=0x13), fake_hidpp.Response("0326CC9CB40508220000000000000000", 0x83B5, "03", handle=0x13),
] ]
responses_lacking = [ responses_lacking = [
hidpp.Response("000000", 0x8003, "FF", handle=0x14), fake_hidpp.Response("000000", 0x8003, "FF", handle=0x14),
hidpp.Response("000300", 0x8102, handle=0x14), fake_hidpp.Response("000300", 0x8102, handle=0x14),
] ]
mouse_info = { mouse_info = {
@ -113,8 +113,8 @@ c534_info = {"kind": common.NamedInt(0, "unknown"), "polling": "", "power_switch
], ],
) )
def test_ReceiverFactory_create_receiver(device_info, responses, handle, serial, max_devices, mock_base): def test_ReceiverFactory_create_receiver(device_info, responses, handle, serial, max_devices, mock_base):
mock_base[0].side_effect = hidpp.open_path mock_base[0].side_effect = fake_hidpp.open_path
mock_base[1].side_effect = partial(hidpp.request, responses) mock_base[1].side_effect = partial(fake_hidpp.request, responses)
if handle is False: if handle is False:
with pytest.raises(Exception): # noqa: B017 with pytest.raises(Exception): # noqa: B017
@ -139,8 +139,8 @@ def test_ReceiverFactory_create_receiver(device_info, responses, handle, serial,
], ],
) )
def test_ReceiverFactory_props(device_info, responses, firmware, codename, remaining_pairings, pairing_info, count, mock_base): def test_ReceiverFactory_props(device_info, responses, firmware, codename, remaining_pairings, pairing_info, count, mock_base):
mock_base[0].side_effect = hidpp.open_path mock_base[0].side_effect = fake_hidpp.open_path
mock_base[1].side_effect = partial(hidpp.request, responses) mock_base[1].side_effect = partial(fake_hidpp.request, responses)
r = receiver.ReceiverFactory.create_receiver(device_info, lambda x: x) r = receiver.ReceiverFactory.create_receiver(device_info, lambda x: x)
@ -161,8 +161,8 @@ def test_ReceiverFactory_props(device_info, responses, firmware, codename, remai
], ],
) )
def test_ReceiverFactory_string(device_info, responses, status_str, strng, mock_base): def test_ReceiverFactory_string(device_info, responses, status_str, strng, mock_base):
mock_base[0].side_effect = hidpp.open_path mock_base[0].side_effect = fake_hidpp.open_path
mock_base[1].side_effect = partial(hidpp.request, responses) mock_base[1].side_effect = partial(fake_hidpp.request, responses)
r = receiver.ReceiverFactory.create_receiver(device_info, lambda x: x) r = receiver.ReceiverFactory.create_receiver(device_info, lambda x: x)
@ -179,8 +179,8 @@ def test_ReceiverFactory_string(device_info, responses, status_str, strng, mock_
], ],
) )
def test_ReceiverFactory_nodevice(device_info, responses, mock_base): def test_ReceiverFactory_nodevice(device_info, responses, mock_base):
mock_base[0].side_effect = hidpp.open_path mock_base[0].side_effect = fake_hidpp.open_path
mock_base[1].side_effect = partial(hidpp.request, responses) mock_base[1].side_effect = partial(fake_hidpp.request, responses)
r = receiver.ReceiverFactory.create_receiver(device_info, lambda x: x) r = receiver.ReceiverFactory.create_receiver(device_info, lambda x: x)

View File

@ -29,7 +29,7 @@ from logitech_receiver import hidpp20_constants
from logitech_receiver import settings_templates from logitech_receiver import settings_templates
from logitech_receiver import special_keys from logitech_receiver import special_keys
from . import hidpp from . import fake_hidpp
# TODO action part of DpiSlidingXY, MouseGesturesXY # TODO action part of DpiSlidingXY, MouseGesturesXY
@ -37,8 +37,8 @@ from . import hidpp
class Setup: class Setup:
def __init__(self, test, *params): def __init__(self, test, *params):
self.test = test self.test = test
self.responses = [r for r in params if isinstance(r, hidpp.Response)] self.responses = [r for r in params if isinstance(r, fake_hidpp.Response)]
self.choices = None if isinstance(params[0], hidpp.Response) else params[0] self.choices = None if isinstance(params[0], fake_hidpp.Response) else params[0]
@dataclass @dataclass
@ -52,42 +52,42 @@ class RegisterTest:
register_tests = [ register_tests = [
Setup( Setup(
RegisterTest(settings_templates.RegisterHandDetection, False, True, [b"\x00\x00\x00"]), RegisterTest(settings_templates.RegisterHandDetection, False, True, [b"\x00\x00\x00"]),
hidpp.Response("000030", 0x8101), # keyboard_hand_detection fake_hidpp.Response("000030", 0x8101), # keyboard_hand_detection
hidpp.Response("000000", 0x8001, "000000"), fake_hidpp.Response("000000", 0x8001, "000000"),
), ),
Setup( Setup(
RegisterTest(settings_templates.RegisterHandDetection, True, False, [b"\x00\x00\x30"]), RegisterTest(settings_templates.RegisterHandDetection, True, False, [b"\x00\x00\x30"]),
hidpp.Response("000000", 0x8101), # keyboard_hand_detection fake_hidpp.Response("000000", 0x8101), # keyboard_hand_detection
hidpp.Response("000030", 0x8001, "000030"), fake_hidpp.Response("000030", 0x8001, "000030"),
), ),
Setup( Setup(
RegisterTest(settings_templates.RegisterSmoothScroll, False, True, [b"\x40"]), RegisterTest(settings_templates.RegisterSmoothScroll, False, True, [b"\x40"]),
hidpp.Response("00", 0x8101), # mouse_button_flags fake_hidpp.Response("00", 0x8101), # mouse_button_flags
hidpp.Response("40", 0x8001, "40"), fake_hidpp.Response("40", 0x8001, "40"),
), ),
Setup( Setup(
RegisterTest(settings_templates.RegisterSideScroll, True, False, [b"\x00"]), RegisterTest(settings_templates.RegisterSideScroll, True, False, [b"\x00"]),
hidpp.Response("02", 0x8101), # mouse_button_flags fake_hidpp.Response("02", 0x8101), # mouse_button_flags
hidpp.Response("00", 0x8001, "00"), fake_hidpp.Response("00", 0x8001, "00"),
), ),
Setup( Setup(
RegisterTest(settings_templates.RegisterFnSwap, False, True, [b"\x00\x01"]), RegisterTest(settings_templates.RegisterFnSwap, False, True, [b"\x00\x01"]),
hidpp.Response("0000", 0x8109), # keyboard_fn_swap fake_hidpp.Response("0000", 0x8109), # keyboard_fn_swap
hidpp.Response("0001", 0x8009, "0001"), fake_hidpp.Response("0001", 0x8009, "0001"),
), ),
Setup( Setup(
RegisterTest( RegisterTest(
settings_templates._PerformanceMXDpi, common.NamedInt(0x88, "800"), common.NamedInt(0x89, "900"), [b"\x89"] settings_templates._PerformanceMXDpi, common.NamedInt(0x88, "800"), common.NamedInt(0x89, "900"), [b"\x89"]
), ),
hidpp.Response("88", 0x8163), # mouse_dpi fake_hidpp.Response("88", 0x8163), # mouse_dpi
hidpp.Response("89", 0x8063, "89"), fake_hidpp.Response("89", 0x8063, "89"),
), ),
] ]
@pytest.mark.parametrize("test", register_tests) @pytest.mark.parametrize("test", register_tests)
def test_register_template(test, mocker): def test_register_template(test, mocker):
device = hidpp.Device(protocol=1.0, responses=test.responses) device = fake_hidpp.Device(protocol=1.0, responses=test.responses)
spy_request = mocker.spy(device, "request") spy_request = mocker.spy(device, "request")
setting = test.test.sclass.build(device) setting = test.test.sclass.build(device)
@ -116,165 +116,165 @@ class FeatureTest:
simple_tests = [ simple_tests = [
Setup( Setup(
FeatureTest(settings_templates.K375sFnSwap, False, True, offset=0x06), FeatureTest(settings_templates.K375sFnSwap, False, True, offset=0x06),
hidpp.Response("FF0001", 0x0600, "FF"), fake_hidpp.Response("FF0001", 0x0600, "FF"),
hidpp.Response("FF0101", 0x0610, "FF01"), fake_hidpp.Response("FF0101", 0x0610, "FF01"),
), ),
Setup( Setup(
FeatureTest(settings_templates.K375sFnSwap, False, True, offset=0x06), FeatureTest(settings_templates.K375sFnSwap, False, True, offset=0x06),
hidpp.Response("050001", 0x0000, "1815"), # HOSTS_INFO fake_hidpp.Response("050001", 0x0000, "1815"), # HOSTS_INFO
hidpp.Response("FF0001", 0x0600, "FF"), fake_hidpp.Response("FF0001", 0x0600, "FF"),
hidpp.Response("FF0101", 0x0610, "FF01"), fake_hidpp.Response("FF0101", 0x0610, "FF01"),
), ),
Setup( Setup(
FeatureTest(settings_templates.K375sFnSwap, False, True, offset=0x06), FeatureTest(settings_templates.K375sFnSwap, False, True, offset=0x06),
hidpp.Response("050001", 0x0000, "1815"), # HOSTS_INFO fake_hidpp.Response("050001", 0x0000, "1815"), # HOSTS_INFO
hidpp.Response("07050301", 0x0500), # current host is 0x01, i.e., host 2 fake_hidpp.Response("07050301", 0x0500), # current host is 0x01, i.e., host 2
hidpp.Response("010001", 0x0600, "01"), fake_hidpp.Response("010001", 0x0600, "01"),
hidpp.Response("010101", 0x0610, "0101"), fake_hidpp.Response("010101", 0x0610, "0101"),
), ),
Setup( Setup(
FeatureTest(settings_templates.FnSwap, True, False), FeatureTest(settings_templates.FnSwap, True, False),
hidpp.Response("01", 0x0400), fake_hidpp.Response("01", 0x0400),
hidpp.Response("00", 0x0410, "00"), fake_hidpp.Response("00", 0x0410, "00"),
), ),
Setup( Setup(
FeatureTest(settings_templates.NewFnSwap, True, False), FeatureTest(settings_templates.NewFnSwap, True, False),
hidpp.Response("01", 0x0400), fake_hidpp.Response("01", 0x0400),
hidpp.Response("00", 0x0410, "00"), fake_hidpp.Response("00", 0x0410, "00"),
), ),
# Setup( # Backlight has caused problems # Setup( # Backlight has caused problems
# FeatureTest(settings_templates.Backlight, 0, 5, offset=0x06), # FeatureTest(settings_templates.Backlight, 0, 5, offset=0x06),
# hidpp.Response("00", 0x0600), # fake_hidpp.Response("00", 0x0600),
# hidpp.Response("05", 0x0610, "05"), # fake_hidpp.Response("05", 0x0610, "05"),
# ), # ),
Setup( Setup(
FeatureTest(settings_templates.Backlight2DurationHandsOut, 80, 160, version=0x03), FeatureTest(settings_templates.Backlight2DurationHandsOut, 80, 160, version=0x03),
hidpp.Response("011830000000100040006000", 0x0400), fake_hidpp.Response("011830000000100040006000", 0x0400),
hidpp.Response("0118FF00200040006000", 0x0410, "0118FF00200040006000"), fake_hidpp.Response("0118FF00200040006000", 0x0410, "0118FF00200040006000"),
), ),
Setup( Setup(
FeatureTest(settings_templates.Backlight2DurationHandsIn, 320, 160, version=0x03), FeatureTest(settings_templates.Backlight2DurationHandsIn, 320, 160, version=0x03),
hidpp.Response("011830000000200040006000", 0x0400), fake_hidpp.Response("011830000000200040006000", 0x0400),
hidpp.Response("0118FF00200020006000", 0x0410, "0118FF00200020006000"), fake_hidpp.Response("0118FF00200020006000", 0x0410, "0118FF00200020006000"),
), ),
Setup( Setup(
FeatureTest(settings_templates.Backlight2DurationPowered, 480, 80, version=0x03), FeatureTest(settings_templates.Backlight2DurationPowered, 480, 80, version=0x03),
hidpp.Response("011830000000200040006000", 0x0400), fake_hidpp.Response("011830000000200040006000", 0x0400),
hidpp.Response("0118FF00200040001000", 0x0410, "0118FF00200040001000"), fake_hidpp.Response("0118FF00200040001000", 0x0410, "0118FF00200040001000"),
), ),
Setup( Setup(
FeatureTest(settings_templates.Backlight3, 0x50, 0x70), FeatureTest(settings_templates.Backlight3, 0x50, 0x70),
hidpp.Response("50", 0x0410), fake_hidpp.Response("50", 0x0410),
hidpp.Response("70", 0x0420, "007009"), fake_hidpp.Response("70", 0x0420, "007009"),
), ),
Setup( Setup(
FeatureTest(settings_templates.HiResScroll, True, False), FeatureTest(settings_templates.HiResScroll, True, False),
hidpp.Response("01", 0x0400), fake_hidpp.Response("01", 0x0400),
hidpp.Response("00", 0x0410, "00"), fake_hidpp.Response("00", 0x0410, "00"),
), ),
Setup( Setup(
FeatureTest(settings_templates.LowresMode, False, True), FeatureTest(settings_templates.LowresMode, False, True),
hidpp.Response("00", 0x0400), fake_hidpp.Response("00", 0x0400),
hidpp.Response("01", 0x0410, "01"), fake_hidpp.Response("01", 0x0410, "01"),
), ),
Setup( Setup(
FeatureTest(settings_templates.HiresSmoothInvert, True, False), FeatureTest(settings_templates.HiresSmoothInvert, True, False),
hidpp.Response("06", 0x0410), fake_hidpp.Response("06", 0x0410),
hidpp.Response("02", 0x0420, "02"), fake_hidpp.Response("02", 0x0420, "02"),
), ),
Setup( Setup(
FeatureTest(settings_templates.HiresSmoothResolution, True, False), FeatureTest(settings_templates.HiresSmoothResolution, True, False),
hidpp.Response("06", 0x0410), fake_hidpp.Response("06", 0x0410),
hidpp.Response("04", 0x0420, "04"), fake_hidpp.Response("04", 0x0420, "04"),
), ),
Setup( Setup(
FeatureTest(settings_templates.HiresMode, False, True), FeatureTest(settings_templates.HiresMode, False, True),
hidpp.Response("06", 0x0410), fake_hidpp.Response("06", 0x0410),
hidpp.Response("07", 0x0420, "07"), fake_hidpp.Response("07", 0x0420, "07"),
), ),
Setup( Setup(
FeatureTest(settings_templates.PointerSpeed, 0x0100, 0x0120), FeatureTest(settings_templates.PointerSpeed, 0x0100, 0x0120),
hidpp.Response("0100", 0x0400), fake_hidpp.Response("0100", 0x0400),
hidpp.Response("0120", 0x0410, "0120"), fake_hidpp.Response("0120", 0x0410, "0120"),
), ),
Setup( Setup(
FeatureTest(settings_templates.ThumbMode, True, False), FeatureTest(settings_templates.ThumbMode, True, False),
hidpp.Response("0100", 0x0410), fake_hidpp.Response("0100", 0x0410),
hidpp.Response("0000", 0x0420, "0000"), fake_hidpp.Response("0000", 0x0420, "0000"),
), ),
Setup( Setup(
FeatureTest(settings_templates.ThumbInvert, False, True), FeatureTest(settings_templates.ThumbInvert, False, True),
hidpp.Response("0100", 0x0410), fake_hidpp.Response("0100", 0x0410),
hidpp.Response("0101", 0x0420, "0101"), fake_hidpp.Response("0101", 0x0420, "0101"),
), ),
Setup( Setup(
FeatureTest(settings_templates.DivertCrown, False, True), FeatureTest(settings_templates.DivertCrown, False, True),
hidpp.Response("01", 0x0410), fake_hidpp.Response("01", 0x0410),
hidpp.Response("02", 0x0420, "02"), fake_hidpp.Response("02", 0x0420, "02"),
), ),
Setup( Setup(
FeatureTest(settings_templates.CrownSmooth, True, False), FeatureTest(settings_templates.CrownSmooth, True, False),
hidpp.Response("0001", 0x0410), fake_hidpp.Response("0001", 0x0410),
hidpp.Response("0002", 0x0420, "0002"), fake_hidpp.Response("0002", 0x0420, "0002"),
), ),
Setup( Setup(
FeatureTest(settings_templates.DivertGkeys, False, True), FeatureTest(settings_templates.DivertGkeys, False, True),
hidpp.Response("01", 0x0420, "01"), fake_hidpp.Response("01", 0x0420, "01"),
), ),
Setup( Setup(
FeatureTest(settings_templates.ScrollRatchet, 2, 1), FeatureTest(settings_templates.ScrollRatchet, 2, 1),
hidpp.Response("02", 0x0400), fake_hidpp.Response("02", 0x0400),
hidpp.Response("01", 0x0410, "01"), fake_hidpp.Response("01", 0x0410, "01"),
), ),
Setup( Setup(
FeatureTest(settings_templates.SmartShift, 1, 10), FeatureTest(settings_templates.SmartShift, 1, 10),
hidpp.Response("0100", 0x0400), fake_hidpp.Response("0100", 0x0400),
hidpp.Response("000A", 0x0410, "000A"), fake_hidpp.Response("000A", 0x0410, "000A"),
), ),
Setup( Setup(
FeatureTest(settings_templates.SmartShift, 5, 50), FeatureTest(settings_templates.SmartShift, 5, 50),
hidpp.Response("0005", 0x0400), fake_hidpp.Response("0005", 0x0400),
hidpp.Response("00FF", 0x0410, "00FF"), fake_hidpp.Response("00FF", 0x0410, "00FF"),
), ),
Setup( Setup(
FeatureTest(settings_templates.SmartShiftEnhanced, 5, 50), FeatureTest(settings_templates.SmartShiftEnhanced, 5, 50),
hidpp.Response("0005", 0x0410), fake_hidpp.Response("0005", 0x0410),
hidpp.Response("00FF", 0x0420, "00FF"), fake_hidpp.Response("00FF", 0x0420, "00FF"),
), ),
Setup( Setup(
FeatureTest(settings_templates.DisableKeyboardKeys, {1: True, 8: True}, {1: False, 8: True}), FeatureTest(settings_templates.DisableKeyboardKeys, {1: True, 8: True}, {1: False, 8: True}),
hidpp.Response("09", 0x0400), fake_hidpp.Response("09", 0x0400),
hidpp.Response("09", 0x0410), fake_hidpp.Response("09", 0x0410),
hidpp.Response("08", 0x0420, "08"), fake_hidpp.Response("08", 0x0420, "08"),
), ),
Setup( Setup(
FeatureTest(settings_templates.DualPlatform, 0, 1), FeatureTest(settings_templates.DualPlatform, 0, 1),
hidpp.Response("00", 0x0400), fake_hidpp.Response("00", 0x0400),
hidpp.Response("01", 0x0420, "01"), fake_hidpp.Response("01", 0x0420, "01"),
), ),
Setup( Setup(
FeatureTest(settings_templates.MKeyLEDs, {1: False, 2: False, 4: False}, {1: False, 2: True, 4: True}), FeatureTest(settings_templates.MKeyLEDs, {1: False, 2: False, 4: False}, {1: False, 2: True, 4: True}),
hidpp.Response("03", 0x0400), fake_hidpp.Response("03", 0x0400),
hidpp.Response("06", 0x0410, "06"), fake_hidpp.Response("06", 0x0410, "06"),
), ),
Setup( Setup(
FeatureTest(settings_templates.MRKeyLED, False, True), FeatureTest(settings_templates.MRKeyLED, False, True),
hidpp.Response("01", 0x0400, "01"), fake_hidpp.Response("01", 0x0400, "01"),
), ),
Setup( Setup(
FeatureTest(settings_templates.Sidetone, 5, 0xA), FeatureTest(settings_templates.Sidetone, 5, 0xA),
hidpp.Response("05", 0x0400), fake_hidpp.Response("05", 0x0400),
hidpp.Response("0A", 0x0410, "0A"), fake_hidpp.Response("0A", 0x0410, "0A"),
), ),
Setup( Setup(
FeatureTest(settings_templates.ADCPower, 5, 0xA), FeatureTest(settings_templates.ADCPower, 5, 0xA),
hidpp.Response("05", 0x0410), fake_hidpp.Response("05", 0x0410),
hidpp.Response("0A", 0x0420, "0A"), fake_hidpp.Response("0A", 0x0420, "0A"),
), ),
Setup( Setup(
FeatureTest(settings_templates.LEDControl, 0, 1), FeatureTest(settings_templates.LEDControl, 0, 1),
hidpp.Response("00", 0x0470), fake_hidpp.Response("00", 0x0470),
hidpp.Response("01", 0x0480, "01"), fake_hidpp.Response("01", 0x0480, "01"),
), ),
Setup( Setup(
FeatureTest( FeatureTest(
@ -282,17 +282,17 @@ simple_tests = [
hidpp20.LEDEffectSetting(ID=3, intensity=0x50, period=0x100), hidpp20.LEDEffectSetting(ID=3, intensity=0x50, period=0x100),
hidpp20.LEDEffectSetting(ID=3, intensity=0x50, period=0x101), hidpp20.LEDEffectSetting(ID=3, intensity=0x50, period=0x101),
), ),
hidpp.Response("0100000001", 0x0400), fake_hidpp.Response("0100000001", 0x0400),
hidpp.Response("00000102", 0x0410, "00FF00"), fake_hidpp.Response("00000102", 0x0410, "00FF00"),
hidpp.Response("0000000300040005", 0x0420, "000000"), fake_hidpp.Response("0000000300040005", 0x0420, "000000"),
hidpp.Response("0001000B00080009", 0x0420, "000100"), fake_hidpp.Response("0001000B00080009", 0x0420, "000100"),
hidpp.Response("000000000000010050", 0x04E0, "00"), fake_hidpp.Response("000000000000010050", 0x04E0, "00"),
hidpp.Response("000000000000000101500000", 0x0430, "000000000000000101500000"), fake_hidpp.Response("000000000000000101500000", 0x0430, "000000000000000101500000"),
), ),
Setup( Setup(
FeatureTest(settings_templates.RGBControl, 0, 1), FeatureTest(settings_templates.RGBControl, 0, 1),
hidpp.Response("0000", 0x0450), fake_hidpp.Response("0000", 0x0450),
hidpp.Response("010100", 0x0450, "0101"), fake_hidpp.Response("010100", 0x0450, "0101"),
), ),
Setup( Setup(
FeatureTest( FeatureTest(
@ -300,181 +300,181 @@ simple_tests = [
hidpp20.LEDEffectSetting(ID=3, intensity=0x50, period=0x100), hidpp20.LEDEffectSetting(ID=3, intensity=0x50, period=0x100),
hidpp20.LEDEffectSetting(ID=2, color=0x505050, speed=0x50), hidpp20.LEDEffectSetting(ID=2, color=0x505050, speed=0x50),
), ),
hidpp.Response("FFFF0100000001", 0x0400, "FFFF00"), fake_hidpp.Response("FFFF0100000001", 0x0400, "FFFF00"),
hidpp.Response("0000000102", 0x0400, "00FF00"), fake_hidpp.Response("0000000102", 0x0400, "00FF00"),
hidpp.Response("0000000300040005", 0x0400, "000000"), fake_hidpp.Response("0000000300040005", 0x0400, "000000"),
hidpp.Response("0001000200080009", 0x0400, "000100"), fake_hidpp.Response("0001000200080009", 0x0400, "000100"),
hidpp.Response("000000000000010050", 0x04E0, "00"), fake_hidpp.Response("000000000000010050", 0x04E0, "00"),
hidpp.Response("00015050505000000000000001", 0x0410, "00015050505000000000000001"), fake_hidpp.Response("00015050505000000000000001", 0x0410, "00015050505000000000000001"),
), ),
Setup( Setup(
FeatureTest(settings_templates.RGBEffectSetting, None, hidpp20.LEDEffectSetting(ID=3, intensity=0x60, period=0x101)), FeatureTest(settings_templates.RGBEffectSetting, None, hidpp20.LEDEffectSetting(ID=3, intensity=0x60, period=0x101)),
hidpp.Response("FFFF0100000001", 0x0400, "FFFF00"), fake_hidpp.Response("FFFF0100000001", 0x0400, "FFFF00"),
hidpp.Response("0000000102", 0x0400, "00FF00"), fake_hidpp.Response("0000000102", 0x0400, "00FF00"),
hidpp.Response("0000000300040005", 0x0400, "000000"), fake_hidpp.Response("0000000300040005", 0x0400, "000000"),
hidpp.Response("0001000200080009", 0x0400, "000100"), fake_hidpp.Response("0001000200080009", 0x0400, "000100"),
hidpp.Response("00000000000000010160000001", 0x0410, "00000000000000010160000001"), fake_hidpp.Response("00000000000000010160000001", 0x0410, "00000000000000010160000001"),
), ),
Setup( Setup(
FeatureTest(settings_templates.RGBEffectSetting, None, hidpp20.LEDEffectSetting(ID=3, intensity=0x60, period=0x101)), FeatureTest(settings_templates.RGBEffectSetting, None, hidpp20.LEDEffectSetting(ID=3, intensity=0x60, period=0x101)),
hidpp.Response("FF000200020004000000000000000000", 0x0400, "FFFF00"), fake_hidpp.Response("FF000200020004000000000000000000", 0x0400, "FFFF00"),
hidpp.Response("00000002040000000000000000000000", 0x0400, "00FF00"), fake_hidpp.Response("00000002040000000000000000000000", 0x0400, "00FF00"),
hidpp.Response("00000000000000000000000000000000", 0x0400, "000000"), fake_hidpp.Response("00000000000000000000000000000000", 0x0400, "000000"),
hidpp.Response("00010001000000000000000000000000", 0x0400, "000100"), fake_hidpp.Response("00010001000000000000000000000000", 0x0400, "000100"),
hidpp.Response("00020003C00503E00000000000000000", 0x0400, "000200"), fake_hidpp.Response("00020003C00503E00000000000000000", 0x0400, "000200"),
hidpp.Response("0003000AC0011E0B0000000000000000", 0x0400, "000300"), fake_hidpp.Response("0003000AC0011E0B0000000000000000", 0x0400, "000300"),
hidpp.Response("01000001070000000000000000000000", 0x0400, "01FF00"), fake_hidpp.Response("01000001070000000000000000000000", 0x0400, "01FF00"),
hidpp.Response("01000000000000000000000000000000", 0x0400, "010000"), fake_hidpp.Response("01000000000000000000000000000000", 0x0400, "010000"),
hidpp.Response("01010001000000000000000000000000", 0x0400, "010100"), fake_hidpp.Response("01010001000000000000000000000000", 0x0400, "010100"),
hidpp.Response("0102000AC0011E0B0000000000000000", 0x0400, "010200"), fake_hidpp.Response("0102000AC0011E0B0000000000000000", 0x0400, "010200"),
hidpp.Response("01030003C00503E00000000000000000", 0x0400, "010300"), fake_hidpp.Response("01030003C00503E00000000000000000", 0x0400, "010300"),
hidpp.Response("01040004DCE1001E0000000000000000", 0x0400, "010400"), fake_hidpp.Response("01040004DCE1001E0000000000000000", 0x0400, "010400"),
hidpp.Response("0105000B000000320000000000000000", 0x0400, "010500"), fake_hidpp.Response("0105000B000000320000000000000000", 0x0400, "010500"),
hidpp.Response("0106000C001B02340000000000000000", 0x0400, "010600"), fake_hidpp.Response("0106000C001B02340000000000000000", 0x0400, "010600"),
hidpp.Response("00020000000000010160000001", 0x0410, "00020000000000010160000001"), fake_hidpp.Response("00020000000000010160000001", 0x0410, "00020000000000010160000001"),
), ),
Setup( Setup(
FeatureTest(settings_templates.Backlight2, 0xFF, 0x00), FeatureTest(settings_templates.Backlight2, 0xFF, 0x00),
common.NamedInts(Disabled=0xFF, Enabled=0x00), common.NamedInts(Disabled=0xFF, Enabled=0x00),
hidpp.Response("000201000000000000000000", 0x0400), fake_hidpp.Response("000201000000000000000000", 0x0400),
hidpp.Response("010201", 0x0410, "0102FF00000000000000"), fake_hidpp.Response("010201", 0x0410, "0102FF00000000000000"),
), ),
Setup( Setup(
FeatureTest(settings_templates.Backlight2, 0x03, 0xFF), FeatureTest(settings_templates.Backlight2, 0x03, 0xFF),
common.NamedInts(Disabled=0xFF, Automatic=0x01, Manual=0x03), common.NamedInts(Disabled=0xFF, Automatic=0x01, Manual=0x03),
hidpp.Response("011838000000000000000000", 0x0400), fake_hidpp.Response("011838000000000000000000", 0x0400),
hidpp.Response("001801", 0x0410, "0018FF00000000000000"), fake_hidpp.Response("001801", 0x0410, "0018FF00000000000000"),
), ),
Setup( Setup(
FeatureTest(settings_templates.Backlight2Level, 0, 3, version=0x03), FeatureTest(settings_templates.Backlight2Level, 0, 3, version=0x03),
[0, 4], [0, 4],
hidpp.Response("011830000000000000000000", 0x0400), fake_hidpp.Response("011830000000000000000000", 0x0400),
hidpp.Response("05", 0x0420), fake_hidpp.Response("05", 0x0420),
hidpp.Response("01180103000000000000", 0x0410, "0118FF03000000000000"), fake_hidpp.Response("01180103000000000000", 0x0410, "0118FF03000000000000"),
), ),
Setup( Setup(
FeatureTest(settings_templates.Backlight2Level, 0, 2, version=0x03), FeatureTest(settings_templates.Backlight2Level, 0, 2, version=0x03),
[0, 4], [0, 4],
hidpp.Response("011830000000000000000000", 0x0400), fake_hidpp.Response("011830000000000000000000", 0x0400),
hidpp.Response("05", 0x0420), fake_hidpp.Response("05", 0x0420),
hidpp.Response("01180102000000000000", 0x0410, "0118FF02000000000000"), fake_hidpp.Response("01180102000000000000", 0x0410, "0118FF02000000000000"),
), ),
Setup( Setup(
FeatureTest(settings_templates.OnboardProfiles, 0, 1, offset=0x0C), FeatureTest(settings_templates.OnboardProfiles, 0, 1, offset=0x0C),
common.NamedInts(**{"Disabled": 0, "Profile 1": 1, "Profile 2": 2}), common.NamedInts(**{"Disabled": 0, "Profile 1": 1, "Profile 2": 2}),
hidpp.Response("01030001010101000101", 0x0C00), fake_hidpp.Response("01030001010101000101", 0x0C00),
hidpp.Response("00010100000201FFFFFFFFFFFFFFFFFF", 0x0C50, "00000000"), fake_hidpp.Response("00010100000201FFFFFFFFFFFFFFFFFF", 0x0C50, "00000000"),
hidpp.Response("000201FFFFFFFFFFFFFFFFFFFFFFFFFF", 0x0C50, "00000004"), fake_hidpp.Response("000201FFFFFFFFFFFFFFFFFFFFFFFFFF", 0x0C50, "00000004"),
hidpp.Response("FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF", 0x0C50, "00000008"), fake_hidpp.Response("FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF", 0x0C50, "00000008"),
hidpp.Response("02", 0x0C20), fake_hidpp.Response("02", 0x0C20),
hidpp.Response("01", 0x0C10, "01"), fake_hidpp.Response("01", 0x0C10, "01"),
hidpp.Response("0001", 0x0C30, "0001"), fake_hidpp.Response("0001", 0x0C30, "0001"),
), ),
Setup( Setup(
FeatureTest(settings_templates.OnboardProfiles, 1, 0, offset=0x0C), FeatureTest(settings_templates.OnboardProfiles, 1, 0, offset=0x0C),
common.NamedInts(**{"Disabled": 0, "Profile 1": 1, "Profile 2": 2}), common.NamedInts(**{"Disabled": 0, "Profile 1": 1, "Profile 2": 2}),
hidpp.Response("01030001010101000101", 0x0C00), fake_hidpp.Response("01030001010101000101", 0x0C00),
hidpp.Response("00010100000201FFFFFFFFFFFFFFFFFF", 0x0C50, "00000000"), fake_hidpp.Response("00010100000201FFFFFFFFFFFFFFFFFF", 0x0C50, "00000000"),
hidpp.Response("000201FFFFFFFFFFFFFFFFFFFFFFFFFF", 0x0C50, "00000004"), fake_hidpp.Response("000201FFFFFFFFFFFFFFFFFFFFFFFFFF", 0x0C50, "00000004"),
hidpp.Response("FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF", 0x0C50, "00000008"), fake_hidpp.Response("FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF", 0x0C50, "00000008"),
hidpp.Response("01", 0x0C20), fake_hidpp.Response("01", 0x0C20),
hidpp.Response("0001", 0x0C40), fake_hidpp.Response("0001", 0x0C40),
hidpp.Response("02", 0x0C10, "02"), fake_hidpp.Response("02", 0x0C10, "02"),
), ),
Setup( Setup(
FeatureTest(settings_templates.ReportRate, 1, 5, offset=0x0C), FeatureTest(settings_templates.ReportRate, 1, 5, offset=0x0C),
common.NamedInts(**{"1ms": 1, "2ms": 2, "5ms": 5, "6ms": 6}), common.NamedInts(**{"1ms": 1, "2ms": 2, "5ms": 5, "6ms": 6}),
hidpp.Response("33", 0x0C00), fake_hidpp.Response("33", 0x0C00),
hidpp.Response("01", 0x0C10), fake_hidpp.Response("01", 0x0C10),
hidpp.Response("05", 0x0C20, "05"), fake_hidpp.Response("05", 0x0C20, "05"),
), ),
Setup( Setup(
FeatureTest(settings_templates.ExtendedReportRate, 1, 5, offset=0x0C), FeatureTest(settings_templates.ExtendedReportRate, 1, 5, offset=0x0C),
common.NamedInts(**{"8ms": 0, "4ms": 1, "500us": 4, "250us": 5}), common.NamedInts(**{"8ms": 0, "4ms": 1, "500us": 4, "250us": 5}),
hidpp.Response("33", 0x0C10), fake_hidpp.Response("33", 0x0C10),
hidpp.Response("01", 0x0C20), fake_hidpp.Response("01", 0x0C20),
hidpp.Response("05", 0x0C30, "05"), fake_hidpp.Response("05", 0x0C30, "05"),
), ),
Setup( Setup(
FeatureTest(settings_templates.AdjustableDpi, 800, 400, version=0x03), FeatureTest(settings_templates.AdjustableDpi, 800, 400, version=0x03),
common.NamedInts.list([400, 800, 1600]), common.NamedInts.list([400, 800, 1600]),
hidpp.Response("000190032006400000", 0x0410, "000000"), fake_hidpp.Response("000190032006400000", 0x0410, "000000"),
hidpp.Response("000320", 0x0420), fake_hidpp.Response("000320", 0x0420),
hidpp.Response("000190", 0x0430, "000190"), fake_hidpp.Response("000190", 0x0430, "000190"),
), ),
Setup( Setup(
FeatureTest(settings_templates.AdjustableDpi, 256, 512, version=0x03), FeatureTest(settings_templates.AdjustableDpi, 256, 512, version=0x03),
common.NamedInts.list([256, 512]), common.NamedInts.list([256, 512]),
hidpp.Response("000100e10002000000", 0x0410, "000000"), fake_hidpp.Response("000100e10002000000", 0x0410, "000000"),
hidpp.Response("000100", 0x0420), fake_hidpp.Response("000100", 0x0420),
hidpp.Response("000200", 0x0430, "000200"), fake_hidpp.Response("000200", 0x0430, "000200"),
), ),
Setup( Setup(
FeatureTest(settings_templates.AdjustableDpi, 400, 800, version=0x03), FeatureTest(settings_templates.AdjustableDpi, 400, 800, version=0x03),
common.NamedInts.list([400, 800, 1200, 1600]), common.NamedInts.list([400, 800, 1200, 1600]),
hidpp.Response("000190E19006400000000000000000", 0x0410, "000000"), fake_hidpp.Response("000190E19006400000000000000000", 0x0410, "000000"),
hidpp.Response("000190", 0x0420), fake_hidpp.Response("000190", 0x0420),
hidpp.Response("000320", 0x0430, "000320"), fake_hidpp.Response("000320", 0x0430, "000320"),
), ),
Setup( Setup(
FeatureTest(settings_templates.Multiplatform, 0, 1), FeatureTest(settings_templates.Multiplatform, 0, 1),
common.NamedInts(**{"MacOS 0.1-0.5": 0, "iOS 0.1-0.7": 1, "Linux 0.2-0.9": 2, "Windows 0.3-0.9": 3}), common.NamedInts(**{"MacOS 0.1-0.5": 0, "iOS 0.1-0.7": 1, "Linux 0.2-0.9": 2, "Windows 0.3-0.9": 3}),
hidpp.Response("020004000001", 0x0400), fake_hidpp.Response("020004000001", 0x0400),
hidpp.Response("00FF200000010005", 0x0410, "00"), fake_hidpp.Response("00FF200000010005", 0x0410, "00"),
hidpp.Response("01FF400000010007", 0x0410, "01"), fake_hidpp.Response("01FF400000010007", 0x0410, "01"),
hidpp.Response("02FF040000020009", 0x0410, "02"), fake_hidpp.Response("02FF040000020009", 0x0410, "02"),
hidpp.Response("03FF010000030009", 0x0410, "03"), fake_hidpp.Response("03FF010000030009", 0x0410, "03"),
hidpp.Response("FF01", 0x0430, "FF01"), fake_hidpp.Response("FF01", 0x0430, "FF01"),
), ),
Setup( Setup(
FeatureTest(settings_templates.ChangeHost, 1, 0), FeatureTest(settings_templates.ChangeHost, 1, 0),
common.NamedInts(**{"1:ABCDEF": 0, "2:GHIJKL": 1}), common.NamedInts(**{"1:ABCDEF": 0, "2:GHIJKL": 1}),
hidpp.Response("050003", 0x0000, "1815"), # HOSTS_INFO fake_hidpp.Response("050003", 0x0000, "1815"), # HOSTS_INFO
hidpp.Response("01000200", 0x0500), fake_hidpp.Response("01000200", 0x0500),
hidpp.Response("000100000600", 0x0510, "00"), fake_hidpp.Response("000100000600", 0x0510, "00"),
hidpp.Response("000041424344454600", 0x0530, "0000"), fake_hidpp.Response("000041424344454600", 0x0530, "0000"),
hidpp.Response("000100000600", 0x0510, "01"), fake_hidpp.Response("000100000600", 0x0510, "01"),
hidpp.Response("00004748494A4B4C00", 0x0530, "0100"), fake_hidpp.Response("00004748494A4B4C00", 0x0530, "0100"),
hidpp.Response("0201", 0x0400), fake_hidpp.Response("0201", 0x0400),
hidpp.Response(True, 0x0410, "00"), fake_hidpp.Response(True, 0x0410, "00"),
), ),
Setup( Setup(
FeatureTest(settings_templates.BrightnessControl, 0x10, 0x20), FeatureTest(settings_templates.BrightnessControl, 0x10, 0x20),
[0, 80], [0, 80],
hidpp.Response("00505100000000", 0x0400), # 0 to 80, all acceptable, no separate on/off fake_hidpp.Response("00505100000000", 0x0400), # 0 to 80, all acceptable, no separate on/off
hidpp.Response("10", 0x0410), # brightness 16 fake_hidpp.Response("10", 0x0410), # brightness 16
hidpp.Response("0020", 0x0420, "0020"), # set brightness 32 fake_hidpp.Response("0020", 0x0420, "0020"), # set brightness 32
), ),
Setup( Setup(
FeatureTest(settings_templates.BrightnessControl, 0x10, 0x00), FeatureTest(settings_templates.BrightnessControl, 0x10, 0x00),
[0, 80], [0, 80],
hidpp.Response("00505104000000", 0x0400), # 0 to 80, all acceptable, separate on/off fake_hidpp.Response("00505104000000", 0x0400), # 0 to 80, all acceptable, separate on/off
hidpp.Response("10", 0x0410), # brightness 16 fake_hidpp.Response("10", 0x0410), # brightness 16
hidpp.Response("01", 0x0430), # on fake_hidpp.Response("01", 0x0430), # on
hidpp.Response("00", 0x0440), # set off fake_hidpp.Response("00", 0x0440), # set off
hidpp.Response("0000", 0x0420, "0000"), # set brightness 0 fake_hidpp.Response("0000", 0x0420, "0000"), # set brightness 0
), ),
Setup( Setup(
FeatureTest(settings_templates.BrightnessControl, 0x00, 0x20), FeatureTest(settings_templates.BrightnessControl, 0x00, 0x20),
[0, 80], [0, 80],
hidpp.Response("00505104000000", 0x0400), # 0 to 80, all acceptable, separate on/off fake_hidpp.Response("00505104000000", 0x0400), # 0 to 80, all acceptable, separate on/off
hidpp.Response("10", 0x0410), # brightness 16 fake_hidpp.Response("10", 0x0410), # brightness 16
hidpp.Response("00", 0x0430), # off fake_hidpp.Response("00", 0x0430), # off
hidpp.Response("01", 0x0440), # set on fake_hidpp.Response("01", 0x0440), # set on
hidpp.Response("0020", 0x0420, "0020"), # set brightness 32 fake_hidpp.Response("0020", 0x0420, "0020"), # set brightness 32
), ),
Setup( Setup(
FeatureTest(settings_templates.BrightnessControl, 0x20, 0x08), FeatureTest(settings_templates.BrightnessControl, 0x20, 0x08),
[0, 80], [0, 80],
hidpp.Response("00504104001000", 0x0400), # 16 to 80, all acceptable, separate on/off fake_hidpp.Response("00504104001000", 0x0400), # 16 to 80, all acceptable, separate on/off
hidpp.Response("20", 0x0410), # brightness 32 fake_hidpp.Response("20", 0x0410), # brightness 32
hidpp.Response("01", 0x0430), # on fake_hidpp.Response("01", 0x0430), # on
hidpp.Response("00", 0x0440, "00"), # set off fake_hidpp.Response("00", 0x0440, "00"), # set off
), ),
Setup( Setup(
FeatureTest(settings_templates.SpeedChange, 0, None, 0), # need to set up all settings to successfully write FeatureTest(settings_templates.SpeedChange, 0, None, 0), # need to set up all settings to successfully write
common.NamedInts(**{"Off": 0, "DPI Change": 0xED}), common.NamedInts(**{"Off": 0, "DPI Change": 0xED}),
*hidpp.responses_speedchange, *fake_hidpp.responses_speedchange,
), ),
] ]
@ -488,7 +488,7 @@ def mock_gethostname(mocker):
def test_simple_template(test, mocker, mock_gethostname): def test_simple_template(test, mocker, mock_gethostname):
tst = test.test tst = test.test
print("TEST", tst.sclass.feature) print("TEST", tst.sclass.feature)
device = hidpp.Device(responses=test.responses, feature=tst.sclass.feature, offset=tst.offset, version=tst.version) device = fake_hidpp.Device(responses=test.responses, feature=tst.sclass.feature, offset=tst.offset, version=tst.version)
spy_request = mocker.spy(device, "request") spy_request = mocker.spy(device, "request")
setting = settings_templates.check_feature(device, tst.sclass) setting = settings_templates.check_feature(device, tst.sclass)
@ -510,20 +510,20 @@ def test_simple_template(test, mocker, mock_gethostname):
write_value = setting.write(tst.write_value) if tst.write_value is not None else None write_value = setting.write(tst.write_value) if tst.write_value is not None else None
assert write_value == tst.write_value assert write_value == tst.write_value
hidpp.match_requests(tst.matched_calls, test.responses, spy_request.call_args_list) fake_hidpp.match_requests(tst.matched_calls, test.responses, spy_request.call_args_list)
responses_reprog_controls = [ responses_reprog_controls = [
hidpp.Response("03", 0x0500), fake_hidpp.Response("03", 0x0500),
hidpp.Response("00500038010001010400000000000000", 0x0510, "00"), # left button fake_hidpp.Response("00500038010001010400000000000000", 0x0510, "00"), # left button
hidpp.Response("00510039010001010400000000000000", 0x0510, "01"), # right button fake_hidpp.Response("00510039010001010400000000000000", 0x0510, "01"), # right button
hidpp.Response("00C4009D310003070500000000000000", 0x0510, "02"), # smart shift fake_hidpp.Response("00C4009D310003070500000000000000", 0x0510, "02"), # smart shift
hidpp.Response("00500000000000000000000000000000", 0x0520, "0050"), # left button current fake_hidpp.Response("00500000000000000000000000000000", 0x0520, "0050"), # left button current
hidpp.Response("00510000500000000000000000000000", 0x0520, "0051"), # right button current fake_hidpp.Response("00510000500000000000000000000000", 0x0520, "0051"), # right button current
hidpp.Response("00C40000000000000000000000000000", 0x0520, "00C4"), # smart shift current fake_hidpp.Response("00C40000000000000000000000000000", 0x0520, "00C4"), # smart shift current
hidpp.Response("00500005000000000000000000000000", 0x0530, "0050000050"), # left button write fake_hidpp.Response("00500005000000000000000000000000", 0x0530, "0050000050"), # left button write
hidpp.Response("00510005000000000000000000000000", 0x0530, "0051000050"), # right button write fake_hidpp.Response("00510005000000000000000000000000", 0x0530, "0051000050"), # right button write
hidpp.Response("00C4000C400000000000000000000000", 0x0530, "00C40000C4"), # smart shift write fake_hidpp.Response("00C4000C400000000000000000000000", 0x0530, "00C40000C4"), # smart shift write
] ]
key_tests = [ key_tests = [
@ -535,22 +535,22 @@ key_tests = [
common.NamedInt(0xC4, "Smart Shift"): common.UnsortedNamedInts(Smart_Shift=0xC4, Left_Click=80, Right_Click=81), common.NamedInt(0xC4, "Smart Shift"): common.UnsortedNamedInts(Smart_Shift=0xC4, Left_Click=80, Right_Click=81),
}, },
*responses_reprog_controls, *responses_reprog_controls,
hidpp.Response("0051000051", 0x0530, "0051000051"), # right button set write fake_hidpp.Response("0051000051", 0x0530, "0051000051"), # right button set write
), ),
Setup( Setup(
FeatureTest(settings_templates.DivertKeys, {0xC4: 0}, {0xC4: 1}, 2, offset=0x05), FeatureTest(settings_templates.DivertKeys, {0xC4: 0}, {0xC4: 1}, 2, offset=0x05),
{common.NamedInt(0xC4, "Smart Shift"): common.NamedInts(Regular=0, Diverted=1, Mouse_Gestures=2)}, {common.NamedInt(0xC4, "Smart Shift"): common.NamedInts(Regular=0, Diverted=1, Mouse_Gestures=2)},
*responses_reprog_controls, *responses_reprog_controls,
hidpp.Response("00C4020000", 0x0530, "00C4020000"), # Smart Shift write fake_hidpp.Response("00C4020000", 0x0530, "00C4020000"), # Smart Shift write
hidpp.Response("00C4030000", 0x0530, "00C4030000"), # Smart Shift divert write fake_hidpp.Response("00C4030000", 0x0530, "00C4030000"), # Smart Shift divert write
), ),
Setup( Setup(
FeatureTest(settings_templates.DivertKeys, {0xC4: 0}, {0xC4: 2}, 2, offset=0x05), FeatureTest(settings_templates.DivertKeys, {0xC4: 0}, {0xC4: 2}, 2, offset=0x05),
{common.NamedInt(0xC4, "Smart Shift"): common.NamedInts(Regular=0, Diverted=1, Mouse_Gestures=2, Sliding_DPI=3)}, {common.NamedInt(0xC4, "Smart Shift"): common.NamedInts(Regular=0, Diverted=1, Mouse_Gestures=2, Sliding_DPI=3)},
*responses_reprog_controls, *responses_reprog_controls,
hidpp.Response("0A0001", 0x0000, "2201"), # ADJUSTABLE_DPI fake_hidpp.Response("0A0001", 0x0000, "2201"), # ADJUSTABLE_DPI
hidpp.Response("00C4300000", 0x0530, "00C4300000"), # Smart Shift write fake_hidpp.Response("00C4300000", 0x0530, "00C4300000"), # Smart Shift write
hidpp.Response("00C4030000", 0x0530, "00C4030000"), # Smart Shift divert write fake_hidpp.Response("00C4030000", 0x0530, "00C4030000"), # Smart Shift divert write
), ),
Setup( Setup(
FeatureTest(settings_templates.PersistentRemappableAction, {80: 16797696, 81: 16797696}, {0x51: 16797952}, 3), FeatureTest(settings_templates.PersistentRemappableAction, {80: 16797696, 81: 16797696}, {0x51: 16797952}, 3),
@ -558,18 +558,18 @@ key_tests = [
common.NamedInt(80, "Left Button"): special_keys.KEYS_KEYS_CONSUMER, common.NamedInt(80, "Left Button"): special_keys.KEYS_KEYS_CONSUMER,
common.NamedInt(81, "Right Button"): special_keys.KEYS_KEYS_CONSUMER, common.NamedInt(81, "Right Button"): special_keys.KEYS_KEYS_CONSUMER,
}, },
hidpp.Response("050001", 0x0000, "1B04"), # REPROG_CONTROLS_V4 fake_hidpp.Response("050001", 0x0000, "1B04"), # REPROG_CONTROLS_V4
*responses_reprog_controls, *responses_reprog_controls,
hidpp.Response("0041", 0x0400), fake_hidpp.Response("0041", 0x0400),
hidpp.Response("0201", 0x0410), fake_hidpp.Response("0201", 0x0410),
hidpp.Response("02", 0x0400), fake_hidpp.Response("02", 0x0400),
hidpp.Response("0050", 0x0420, "00FF"), # left button fake_hidpp.Response("0050", 0x0420, "00FF"), # left button
hidpp.Response("0051", 0x0420, "01FF"), # right button fake_hidpp.Response("0051", 0x0420, "01FF"), # right button
hidpp.Response("0050000100500000", 0x0430, "0050FF"), # left button current fake_hidpp.Response("0050000100500000", 0x0430, "0050FF"), # left button current
hidpp.Response("0051000100500001", 0x0430, "0051FF"), # right button current fake_hidpp.Response("0051000100500001", 0x0430, "0051FF"), # right button current
hidpp.Response("0050FF01005000", 0x0440, "0050FF01005000"), # left button write fake_hidpp.Response("0050FF01005000", 0x0440, "0050FF01005000"), # left button write
hidpp.Response("0051FF01005000", 0x0440, "0051FF01005000"), # right button write fake_hidpp.Response("0051FF01005000", 0x0440, "0051FF01005000"), # right button write
hidpp.Response("0051FF01005100", 0x0440, "0051FF01005100"), # right button set write fake_hidpp.Response("0051FF01005100", 0x0440, "0051FF01005100"), # right button set write
), ),
Setup( Setup(
FeatureTest( FeatureTest(
@ -591,11 +591,11 @@ key_tests = [
{45: True}, {45: True},
4, 4,
), ),
*hidpp.responses_gestures, *fake_hidpp.responses_gestures,
hidpp.Response("0001FF6F", 0x0420, "0001FF6F"), # write fake_hidpp.Response("0001FF6F", 0x0420, "0001FF6F"), # write
hidpp.Response("01010F04", 0x0420, "01010F04"), fake_hidpp.Response("01010F04", 0x0420, "01010F04"),
hidpp.Response("0001FF7F", 0x0420, "0001FF7F"), # write 45 fake_hidpp.Response("0001FF7F", 0x0420, "0001FF7F"), # write 45
hidpp.Response("01010F04", 0x0420, "01010F04"), fake_hidpp.Response("01010F04", 0x0420, "01010F04"),
), ),
Setup( Setup(
FeatureTest( FeatureTest(
@ -604,26 +604,26 @@ key_tests = [
{44: True}, {44: True},
4, 4,
), ),
*hidpp.responses_gestures, *fake_hidpp.responses_gestures,
hidpp.Response("0001FF00", 0x0440, "0001FF00"), # write fake_hidpp.Response("0001FF00", 0x0440, "0001FF00"), # write
hidpp.Response("01010300", 0x0440, "01010300"), fake_hidpp.Response("01010300", 0x0440, "01010300"),
hidpp.Response("0001FF08", 0x0440, "0001FF08"), # write 44 fake_hidpp.Response("0001FF08", 0x0440, "0001FF08"), # write 44
hidpp.Response("01010300", 0x0440, "01010300"), fake_hidpp.Response("01010300", 0x0440, "01010300"),
), ),
Setup( Setup(
FeatureTest(settings_templates.Gesture2Params, {4: {"scale": 256}}, {4: {"scale": 128}}, 2), FeatureTest(settings_templates.Gesture2Params, {4: {"scale": 256}}, {4: {"scale": 128}}, 2),
*hidpp.responses_gestures, *fake_hidpp.responses_gestures,
hidpp.Response("000100FF000000000000000000000000", 0x0480, "000100FF"), fake_hidpp.Response("000100FF000000000000000000000000", 0x0480, "000100FF"),
hidpp.Response("000080FF000000000000000000000000", 0x0480, "000080FF"), fake_hidpp.Response("000080FF000000000000000000000000", 0x0480, "000080FF"),
), ),
Setup( Setup(
FeatureTest(settings_templates.Equalizer, {0: -0x20, 1: 0x10}, {1: 0x18}, 2), FeatureTest(settings_templates.Equalizer, {0: -0x20, 1: 0x10}, {1: 0x18}, 2),
[-32, 32], [-32, 32],
hidpp.Response("0220000000", 0x0400), fake_hidpp.Response("0220000000", 0x0400),
hidpp.Response("0000800100000000000000", 0x0410, "00"), fake_hidpp.Response("0000800100000000000000", 0x0410, "00"),
hidpp.Response("E010", 0x0420, "00"), fake_hidpp.Response("E010", 0x0420, "00"),
hidpp.Response("E010", 0x0430, "02E010"), fake_hidpp.Response("E010", 0x0430, "02E010"),
hidpp.Response("E018", 0x0430, "02E018"), fake_hidpp.Response("E018", 0x0430, "02E018"),
), ),
Setup( Setup(
FeatureTest(settings_templates.PerKeyLighting, {1: -1, 2: -1, 9: -1, 10: -1, 113: -1}, {2: 0xFF0000}, 4, 4, 0, 1), FeatureTest(settings_templates.PerKeyLighting, {1: -1, 2: -1, 9: -1, 10: -1, 113: -1}, {2: 0xFF0000}, 4, 4, 0, 1),
@ -634,13 +634,13 @@ key_tests = [
common.NamedInt(10, "J"): special_keys.COLORSPLUS, common.NamedInt(10, "J"): special_keys.COLORSPLUS,
common.NamedInt(113, "KEY 113"): special_keys.COLORSPLUS, common.NamedInt(113, "KEY 113"): special_keys.COLORSPLUS,
}, },
hidpp.Response("00000606000000000000000000000000", 0x0400, "0000"), # first group of keys fake_hidpp.Response("00000606000000000000000000000000", 0x0400, "0000"), # first group of keys
hidpp.Response("00000200000000000000000000000000", 0x0400, "0001"), # second group of keys fake_hidpp.Response("00000200000000000000000000000000", 0x0400, "0001"), # second group of keys
hidpp.Response("00000000000000000000000000000000", 0x0400, "0002"), # last group of keys fake_hidpp.Response("00000000000000000000000000000000", 0x0400, "0002"), # last group of keys
hidpp.Response("02FF0000", 0x0410, "02FF0000"), # write one value fake_hidpp.Response("02FF0000", 0x0410, "02FF0000"), # write one value
hidpp.Response("00", 0x0470, "00"), # finish fake_hidpp.Response("00", 0x0470, "00"), # finish
hidpp.Response("02FF0000", 0x0410, "02FF0000"), # write one value fake_hidpp.Response("02FF0000", 0x0410, "02FF0000"), # write one value
hidpp.Response("00", 0x0470, "00"), # finish fake_hidpp.Response("00", 0x0470, "00"), # finish
), ),
Setup( Setup(
FeatureTest( FeatureTest(
@ -659,17 +659,17 @@ key_tests = [
common.NamedInt(10, "J"): special_keys.COLORSPLUS, common.NamedInt(10, "J"): special_keys.COLORSPLUS,
common.NamedInt(113, "KEY 113"): special_keys.COLORSPLUS, common.NamedInt(113, "KEY 113"): special_keys.COLORSPLUS,
}, },
hidpp.Response("00000606000000000000000000000000", 0x0400, "0000"), # first group of keys fake_hidpp.Response("00000606000000000000000000000000", 0x0400, "0000"), # first group of keys
hidpp.Response("00000200000000000000000000000000", 0x0400, "0001"), # second group of keys fake_hidpp.Response("00000200000000000000000000000000", 0x0400, "0001"), # second group of keys
hidpp.Response("00000000000000000000000000000000", 0x0400, "0002"), # last group of keys fake_hidpp.Response("00000000000000000000000000000000", 0x0400, "0002"), # last group of keys
hidpp.Response("02FF0000", 0x0410, "02FF0000"), # write one value fake_hidpp.Response("02FF0000", 0x0410, "02FF0000"), # write one value
hidpp.Response("00", 0x0470, "00"), # finish fake_hidpp.Response("00", 0x0470, "00"), # finish
hidpp.Response("09FF0000", 0x0410, "09FF0000"), # write one value fake_hidpp.Response("09FF0000", 0x0410, "09FF0000"), # write one value
hidpp.Response("00", 0x0470, "00"), # finish fake_hidpp.Response("00", 0x0470, "00"), # finish
hidpp.Response("0AFF0000", 0x0410, "0AFF0000"), # write one value fake_hidpp.Response("0AFF0000", 0x0410, "0AFF0000"), # write one value
hidpp.Response("00", 0x0470, "00"), # finish fake_hidpp.Response("00", 0x0470, "00"), # finish
hidpp.Response("02FF000009FF00000AFF0000", 0x0410, "02FF000009FF00000AFF0000"), # write three values fake_hidpp.Response("02FF000009FF00000AFF0000", 0x0410, "02FF000009FF00000AFF0000"), # write three values
hidpp.Response("00", 0x0470, "00"), # finish fake_hidpp.Response("00", 0x0470, "00"), # finish
), ),
Setup( Setup(
FeatureTest( FeatureTest(
@ -689,33 +689,33 @@ key_tests = [
common.NamedInt(113, "KEY 113"): special_keys.COLORSPLUS, common.NamedInt(113, "KEY 113"): special_keys.COLORSPLUS,
common.NamedInt(114, "KEY 114"): special_keys.COLORSPLUS, common.NamedInt(114, "KEY 114"): special_keys.COLORSPLUS,
}, },
hidpp.Response("00000606000000000000000000000000", 0x0400, "0000"), # first group of keys fake_hidpp.Response("00000606000000000000000000000000", 0x0400, "0000"), # first group of keys
hidpp.Response("00000600000000000000000000000000", 0x0400, "0001"), # second group of keys fake_hidpp.Response("00000600000000000000000000000000", 0x0400, "0001"), # second group of keys
hidpp.Response("00000000000000000000000000000000", 0x0400, "0002"), # last group of keys fake_hidpp.Response("00000000000000000000000000000000", 0x0400, "0002"), # last group of keys
hidpp.Response("01FF0000", 0x0410, "01FF0000"), # write one value fake_hidpp.Response("01FF0000", 0x0410, "01FF0000"), # write one value
hidpp.Response("00", 0x0470, "00"), # finish fake_hidpp.Response("00", 0x0470, "00"), # finish
hidpp.Response("02FF0000", 0x0410, "02FF0000"), # write one value fake_hidpp.Response("02FF0000", 0x0410, "02FF0000"), # write one value
hidpp.Response("00", 0x0470, "00"), # finish fake_hidpp.Response("00", 0x0470, "00"), # finish
hidpp.Response("09FF0000", 0x0410, "09FF0000"), # write one value fake_hidpp.Response("09FF0000", 0x0410, "09FF0000"), # write one value
hidpp.Response("00", 0x0470, "00"), # finish fake_hidpp.Response("00", 0x0470, "00"), # finish
hidpp.Response("0AFF0000", 0x0410, "0AFF0000"), # write one value fake_hidpp.Response("0AFF0000", 0x0410, "0AFF0000"), # write one value
hidpp.Response("00", 0x0470, "00"), # finish fake_hidpp.Response("00", 0x0470, "00"), # finish
hidpp.Response("7100FF00", 0x0410, "7100FF00"), # write one value fake_hidpp.Response("7100FF00", 0x0410, "7100FF00"), # write one value
hidpp.Response("00", 0x0470, "00"), # finish fake_hidpp.Response("00", 0x0470, "00"), # finish
hidpp.Response("72FF0000", 0x0410, "72FF0000"), # write one value fake_hidpp.Response("72FF0000", 0x0410, "72FF0000"), # write one value
hidpp.Response("00", 0x0470, "00"), # finish fake_hidpp.Response("00", 0x0470, "00"), # finish
hidpp.Response("FF00000102090A72", 0x460, "FF00000102090A72"), # write one value for five keys fake_hidpp.Response("FF00000102090A72", 0x460, "FF00000102090A72"), # write one value for five keys
hidpp.Response("7100FF00", 0x0410, "7100FF00"), # write one value fake_hidpp.Response("7100FF00", 0x0410, "7100FF00"), # write one value
hidpp.Response("00", 0x0470, "00"), # finish fake_hidpp.Response("00", 0x0470, "00"), # finish
), ),
Setup( Setup(
FeatureTest(settings_templates.ExtendedAdjustableDpi, {0: 256}, {0: 512}, 2, offset=0x9), FeatureTest(settings_templates.ExtendedAdjustableDpi, {0: 256}, {0: 512}, 2, offset=0x9),
{common.NamedInt(0, "X"): common.NamedInts.list([256, 512])}, {common.NamedInt(0, "X"): common.NamedInts.list([256, 512])},
hidpp.Response("000000", 0x0910, "00"), # no y direction, no lod fake_hidpp.Response("000000", 0x0910, "00"), # no y direction, no lod
hidpp.Response("0000000100e10002000000", 0x0920, "000000"), fake_hidpp.Response("0000000100e10002000000", 0x0920, "000000"),
hidpp.Response("00010000000000000000", 0x0950), fake_hidpp.Response("00010000000000000000", 0x0950),
hidpp.Response("000100000000", 0x0960, "000100000000"), fake_hidpp.Response("000100000000", 0x0960, "000100000000"),
hidpp.Response("000200000000", 0x0960, "000200000000"), fake_hidpp.Response("000200000000", 0x0960, "000200000000"),
), ),
Setup( Setup(
FeatureTest(settings_templates.ExtendedAdjustableDpi, {0: 0x64, 1: 0xE4}, {0: 0x164}, 2, offset=0x9), FeatureTest(settings_templates.ExtendedAdjustableDpi, {0: 0x64, 1: 0xE4}, {0: 0x164}, 2, offset=0x9),
@ -723,15 +723,15 @@ key_tests = [
common.NamedInt(0, "X"): common.NamedInts.list([0x064, 0x074, 0x084, 0x0A4, 0x0C4, 0x0E4, 0x0124, 0x0164, 0x01C4]), common.NamedInt(0, "X"): common.NamedInts.list([0x064, 0x074, 0x084, 0x0A4, 0x0C4, 0x0E4, 0x0124, 0x0164, 0x01C4]),
common.NamedInt(1, "Y"): common.NamedInts.list([0x064, 0x074, 0x084, 0x0A4, 0x0C4, 0x0E4, 0x0124, 0x0164]), common.NamedInt(1, "Y"): common.NamedInts.list([0x064, 0x074, 0x084, 0x0A4, 0x0C4, 0x0E4, 0x0124, 0x0164]),
}, },
hidpp.Response("000001", 0x0910, "00"), # supports y direction, no lod fake_hidpp.Response("000001", 0x0910, "00"), # supports y direction, no lod
hidpp.Response("0000000064E0100084E02000C4E02000", 0x0920, "000000"), fake_hidpp.Response("0000000064E0100084E02000C4E02000", 0x0920, "000000"),
hidpp.Response("000001E4E0400124E0400164E06001C4", 0x0920, "000001"), fake_hidpp.Response("000001E4E0400124E0400164E06001C4", 0x0920, "000001"),
hidpp.Response("00000000000000000000000000000000", 0x0920, "000002"), fake_hidpp.Response("00000000000000000000000000000000", 0x0920, "000002"),
hidpp.Response("0000000064E0100084E02000C4E02000", 0x0920, "000100"), fake_hidpp.Response("0000000064E0100084E02000C4E02000", 0x0920, "000100"),
hidpp.Response("000001E4E0400124E040016400000000", 0x0920, "000101"), fake_hidpp.Response("000001E4E0400124E040016400000000", 0x0920, "000101"),
hidpp.Response("000064007400E4007400", 0x0950), fake_hidpp.Response("000064007400E4007400", 0x0950),
hidpp.Response("00006400E400", 0x0960, "00006400E400"), fake_hidpp.Response("00006400E400", 0x0960, "00006400E400"),
hidpp.Response("00016400E400", 0x0960, "00016400E400"), fake_hidpp.Response("00016400E400", 0x0960, "00016400E400"),
), ),
Setup( Setup(
FeatureTest(settings_templates.ExtendedAdjustableDpi, {0: 0x64, 1: 0xE4, 2: 1}, {1: 0x164}, 2, offset=0x9), FeatureTest(settings_templates.ExtendedAdjustableDpi, {0: 0x64, 1: 0xE4, 2: 1}, {1: 0x164}, 2, offset=0x9),
@ -740,15 +740,15 @@ key_tests = [
common.NamedInt(1, "Y"): common.NamedInts.list([0x064, 0x074, 0x084, 0x0A4, 0x0C4, 0x0E4, 0x0124, 0x0164]), common.NamedInt(1, "Y"): common.NamedInts.list([0x064, 0x074, 0x084, 0x0A4, 0x0C4, 0x0E4, 0x0124, 0x0164]),
common.NamedInt(2, "LOD"): common.NamedInts(LOW=0, MEDIUM=1, HIGH=2), common.NamedInt(2, "LOD"): common.NamedInts(LOW=0, MEDIUM=1, HIGH=2),
}, },
hidpp.Response("000003", 0x0910, "00"), # supports y direction and lod fake_hidpp.Response("000003", 0x0910, "00"), # supports y direction and lod
hidpp.Response("0000000064E0100084E02000C4E02000", 0x0920, "000000"), fake_hidpp.Response("0000000064E0100084E02000C4E02000", 0x0920, "000000"),
hidpp.Response("000001E4E0400124E0400164E06001C4", 0x0920, "000001"), fake_hidpp.Response("000001E4E0400124E0400164E06001C4", 0x0920, "000001"),
hidpp.Response("00000000000000000000000000000000", 0x0920, "000002"), fake_hidpp.Response("00000000000000000000000000000000", 0x0920, "000002"),
hidpp.Response("0000000064E0100084E02000C4E02000", 0x0920, "000100"), fake_hidpp.Response("0000000064E0100084E02000C4E02000", 0x0920, "000100"),
hidpp.Response("000001E4E0400124E040016400000000", 0x0920, "000101"), fake_hidpp.Response("000001E4E0400124E040016400000000", 0x0920, "000101"),
hidpp.Response("000064007400E4007401", 0x0950), fake_hidpp.Response("000064007400E4007401", 0x0950),
hidpp.Response("00006400E401", 0x0960, "00006400E401"), fake_hidpp.Response("00006400E401", 0x0960, "00006400E401"),
hidpp.Response("000064016401", 0x0960, "000064016401"), fake_hidpp.Response("000064016401", 0x0960, "000064016401"),
), ),
] ]
@ -756,7 +756,7 @@ key_tests = [
@pytest.mark.parametrize("test", key_tests) @pytest.mark.parametrize("test", key_tests)
def test_key_template(test, mocker): def test_key_template(test, mocker):
tst = test.test tst = test.test
device = hidpp.Device(responses=test.responses, feature=tst.sclass.feature, offset=tst.offset, version=tst.version) device = fake_hidpp.Device(responses=test.responses, feature=tst.sclass.feature, offset=tst.offset, version=tst.version)
spy_request = mocker.spy(device, "request") spy_request = mocker.spy(device, "request")
print("FEATURE", tst.sclass.feature) print("FEATURE", tst.sclass.feature)
@ -784,18 +784,18 @@ def test_key_template(test, mocker):
if tst.rewrite: if tst.rewrite:
write_value = setting.write(value) write_value = setting.write(value)
hidpp.match_requests(tst.matched_calls, test.responses, spy_request.call_args_list) fake_hidpp.match_requests(tst.matched_calls, test.responses, spy_request.call_args_list)
@pytest.mark.parametrize( @pytest.mark.parametrize(
"responses, currentSpeed, newSpeed", "responses, currentSpeed, newSpeed",
[ [
(hidpp.responses_speedchange, 100, 200), (fake_hidpp.responses_speedchange, 100, 200),
(hidpp.responses_speedchange, None, 250), (fake_hidpp.responses_speedchange, None, 250),
], ],
) )
def test_SpeedChange_action(responses, currentSpeed, newSpeed, mocker): def test_SpeedChange_action(responses, currentSpeed, newSpeed, mocker):
device = hidpp.Device(responses=responses, feature=hidpp20_constants.FEATURE.POINTER_SPEED) device = fake_hidpp.Device(responses=responses, feature=hidpp20_constants.FEATURE.POINTER_SPEED)
spy_setting_callback = mocker.spy(device, "setting_callback") spy_setting_callback = mocker.spy(device, "setting_callback")
settings_templates.check_feature_settings(device, device.settings) # need to set up all the settings settings_templates.check_feature_settings(device, device.settings) # need to set up all the settings
device.persister = {"pointer_speed": currentSpeed, "_speed-change": newSpeed} device.persister = {"pointer_speed": currentSpeed, "_speed-change": newSpeed}
@ -814,7 +814,7 @@ def test_SpeedChange_action(responses, currentSpeed, newSpeed, mocker):
@pytest.mark.parametrize("test", simple_tests + key_tests) @pytest.mark.parametrize("test", simple_tests + key_tests)
def test_check_feature_settings(test, mocker): def test_check_feature_settings(test, mocker):
tst = test.test tst = test.test
device = hidpp.Device(responses=test.responses, feature=tst.sclass.feature, offset=tst.offset, version=tst.version) device = fake_hidpp.Device(responses=test.responses, feature=tst.sclass.feature, offset=tst.offset, version=tst.version)
already_known = [] already_known = []
setting = settings_templates.check_feature_settings(device, already_known) setting = settings_templates.check_feature_settings(device, already_known)
@ -828,14 +828,14 @@ def test_check_feature_settings(test, mocker):
[ [
Setup( Setup(
FeatureTest(settings_templates.K375sFnSwap, False, True, offset=0x06), FeatureTest(settings_templates.K375sFnSwap, False, True, offset=0x06),
hidpp.Response("FF0001", 0x0600, "FF"), fake_hidpp.Response("FF0001", 0x0600, "FF"),
hidpp.Response("FF0101", 0x0610, "FF01"), fake_hidpp.Response("FF0101", 0x0610, "FF01"),
) )
], ],
) )
def test_check_feature_setting(test, mocker): def test_check_feature_setting(test, mocker):
tst = test.test tst = test.test
device = hidpp.Device(responses=test.responses, feature=tst.sclass.feature, offset=tst.offset, version=tst.version) device = fake_hidpp.Device(responses=test.responses, feature=tst.sclass.feature, offset=tst.offset, version=tst.version)
setting = settings_templates.check_feature_setting(device, tst.sclass.name) setting = settings_templates.check_feature_setting(device, tst.sclass.name)