From 06fd32b5016c00c4d4c6362d4031276791d18c56 Mon Sep 17 00:00:00 2001 From: MattHag <16444067+MattHag@users.noreply.github.com> Date: Sun, 13 Oct 2024 12:06:35 +0200 Subject: [PATCH] Test and refactor process_notification Related #2273 --- lib/logitech_receiver/diversion.py | 85 ++++++++++++----------- tests/logitech_receiver/test_diversion.py | 29 ++++++++ 2 files changed, 72 insertions(+), 42 deletions(-) diff --git a/lib/logitech_receiver/diversion.py b/lib/logitech_receiver/diversion.py index 8652814a..b9c368ab 100644 --- a/lib/logitech_receiver/diversion.py +++ b/lib/logitech_receiver/diversion.py @@ -1495,51 +1495,52 @@ def evaluate_rules(feature, notification: HIDPPNotification, device): rules.evaluate(feature, notification, device, True) -# process a notification -def process_notification(device, notification: HIDPPNotification, feature): +def process_notification(device, notification: HIDPPNotification, feature) -> None: + """Processes HID++ notifications.""" global keys_down, g_keys_down, m_keys_down, mr_key_down, key_down, key_up, thumb_wheel_displacement key_down, key_up = None, None # need to keep track of keys that are down to find a new key down - if feature == FEATURE.REPROG_CONTROLS_V4 and notification.address == 0x00: - new_keys_down = struct.unpack("!4H", notification.data[:8]) - for key in new_keys_down: - if key and key not in keys_down: - key_down = key - for key in keys_down: - if key and key not in new_keys_down: - key_up = key - keys_down = new_keys_down - # and also G keys down - elif feature == FEATURE.GKEY and notification.address == 0x00: - new_g_keys_down = struct.unpack("