device: report symbolic names for pairing errors (#2886)

* device: report symbolic names for pairing errors

* testing: fix testing of notifications
This commit is contained in:
Peter F. Patel-Schneider 2025-05-31 08:12:42 -04:00 committed by GitHub
parent 1a9725f540
commit 694513832d
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 4 additions and 4 deletions

View File

@ -433,7 +433,7 @@ 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)
receiver.pairing.error = error_string = hidpp10_constants.PairingError(pair_error).name
receiver.pairing.new_device = None
logger.warning("pairing error %d: %s", pair_error, error_string)
receiver.changed(reason=reason)
@ -453,7 +453,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)
receiver.pairing.error = discover_string = hidpp10_constants.BoltPairingError(discover_error).name
logger.warning("bolt discovering error %d: %s", discover_error, discover_string)
receiver.changed(reason=reason)
return True
@ -495,7 +495,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)
receiver.pairing.error = error_string = hidpp10_constants.BoltPairingError(pair_error).name
receiver.pairing.new_device = None
logger.warning("pairing error %d: %s", pair_error, error_string)
receiver.changed(reason=reason)

View File

@ -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 == expected_error
assert receiver.pairing.error == (None if expected_error is None else expected_error.name)
assert receiver.pairing.new_device is expected_new_device