From 4c63bdb6eedd1effd320ae69d0f66ff6122719f0 Mon Sep 17 00:00:00 2001 From: "Peter F. Patel-Schneider" Date: Wed, 10 Dec 2025 11:18:50 -0500 Subject: [PATCH] show better pairing errors (#3063) * Fix: Show pairing error str Fixes #2827 * device: also show bolt pairing errors --------- Co-authored-by: MattHag <16444067+MattHag@users.noreply.github.com> --- lib/logitech_receiver/hidpp10_constants.py | 8 ++++++++ lib/logitech_receiver/notifications.py | 7 ++++--- tests/logitech_receiver/test_hidpp10.py | 9 +++++++++ tests/logitech_receiver/test_notifications.py | 2 +- 4 files changed, 22 insertions(+), 4 deletions(-) diff --git a/lib/logitech_receiver/hidpp10_constants.py b/lib/logitech_receiver/hidpp10_constants.py index c60d36f9..3677b8b4 100644 --- a/lib/logitech_receiver/hidpp10_constants.py +++ b/lib/logitech_receiver/hidpp10_constants.py @@ -156,11 +156,19 @@ class PairingError(IntEnum): TOO_MANY_DEVICES = 0x03 SEQUENCE_TIMEOUT = 0x06 + @property + def label(self) -> str: + return self.name.lower().replace("_", " ") + class BoltPairingError(IntEnum): DEVICE_TIMEOUT = 0x01 FAILED = 0x02 + @property + def label(self) -> str: + return self.name.lower().replace("_", " ") + class Registers(IntEnum): """Known HID registers. diff --git a/lib/logitech_receiver/notifications.py b/lib/logitech_receiver/notifications.py index 976d50d5..1cc46248 100644 --- a/lib/logitech_receiver/notifications.py +++ b/lib/logitech_receiver/notifications.py @@ -433,7 +433,8 @@ def handle_pairing_lock(receiver: Receiver, notification: HIDPPNotification) -> receiver.pairing.new_device = None pair_error = ord(notification.data[:1]) if pair_error: - receiver.pairing.error = error_string = hidpp10_constants.PairingError(pair_error).name + error_string = hidpp10_constants.PairingError(pair_error).label + receiver.pairing.error = error_string receiver.pairing.new_device = None logger.warning("pairing error %d: %s", pair_error, error_string) receiver.changed(reason=reason) @@ -453,7 +454,7 @@ def handle_discovery_status(receiver: Receiver, notification: HIDPPNotification) receiver.pairing.device_passkey = None discover_error = ord(notification.data[:1]) if discover_error: - receiver.pairing.error = discover_string = hidpp10_constants.BoltPairingError(discover_error).name + receiver.pairing.error = discover_string = hidpp10_constants.BoltPairingError(discover_error).label logger.warning("bolt discovering error %d: %s", discover_error, discover_string) receiver.changed(reason=reason) return True @@ -495,7 +496,7 @@ def handle_pairing_status(receiver: Receiver, notification: HIDPPNotification) - elif notification.address == 0x02 and not pair_error: receiver.pairing.new_device = receiver.register_new_device(notification.data[7]) if pair_error: - receiver.pairing.error = error_string = hidpp10_constants.BoltPairingError(pair_error).name + receiver.pairing.error = error_string = hidpp10_constants.BoltPairingError(pair_error).label receiver.pairing.new_device = None logger.warning("pairing error %d: %s", pair_error, error_string) receiver.changed(reason=reason) diff --git a/tests/logitech_receiver/test_hidpp10.py b/tests/logitech_receiver/test_hidpp10.py index b642608a..f6d2015a 100644 --- a/tests/logitech_receiver/test_hidpp10.py +++ b/tests/logitech_receiver/test_hidpp10.py @@ -9,6 +9,7 @@ import pytest from logitech_receiver import common from logitech_receiver import hidpp10 from logitech_receiver import hidpp10_constants +from logitech_receiver.hidpp10_constants import PairingError from logitech_receiver.hidpp10_constants import Registers _hidpp10 = hidpp10.Hidpp10() @@ -338,3 +339,11 @@ def test_set_configuration_pending_flags(device, expected_result): result = hidpp10.set_configuration_pending_flags(device, 0x00) assert result == expected_result + + +def test_pairing_error(): + expected_label = "device not supported" + + res = PairingError.DEVICE_NOT_SUPPORTED.label + + assert res == expected_label diff --git a/tests/logitech_receiver/test_notifications.py b/tests/logitech_receiver/test_notifications.py index 89c758c8..cbe51aab 100644 --- a/tests/logitech_receiver/test_notifications.py +++ b/tests/logitech_receiver/test_notifications.py @@ -58,7 +58,7 @@ def test_process_receiver_notification(sub_id, notification_data, expected_error result = notifications.process_receiver_notification(receiver, notification) assert result - assert receiver.pairing.error == (None if expected_error is None else expected_error.name) + assert receiver.pairing.error == (None if expected_error is None else expected_error.label) assert receiver.pairing.new_device is expected_new_device