From 74364cf0ea25957692d8bb6a58b5e8e14bf514cd Mon Sep 17 00:00:00 2001 From: MattHag <16444067+MattHag@users.noreply.github.com> Date: Sat, 15 Mar 2025 21:57:47 +0100 Subject: [PATCH] Fix: Show pairing error str Fixes #2827 --- lib/logitech_receiver/hidpp10_constants.py | 4 ++++ lib/logitech_receiver/notifications.py | 3 ++- tests/logitech_receiver/test_hidpp10.py | 9 +++++++++ 3 files changed, 15 insertions(+), 1 deletion(-) diff --git a/lib/logitech_receiver/hidpp10_constants.py b/lib/logitech_receiver/hidpp10_constants.py index c60d36f9..13a769d1 100644 --- a/lib/logitech_receiver/hidpp10_constants.py +++ b/lib/logitech_receiver/hidpp10_constants.py @@ -156,6 +156,10 @@ 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 diff --git a/lib/logitech_receiver/notifications.py b/lib/logitech_receiver/notifications.py index 976d50d5..2d6a62ec 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) 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