Skip to content

Commit

Permalink
refactoring(logitech_receiver/notifications): fix pre-commits
Browse files Browse the repository at this point in the history
  • Loading branch information
rloutrel committed Oct 13, 2024
1 parent 5f4adbb commit 01f5650
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 8 deletions.
6 changes: 3 additions & 3 deletions lib/logitech_receiver/notifications.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import logging
import struct
import threading
import typing

from solaar.i18n import _

Expand All @@ -36,7 +37,6 @@
from .common import Notification
from .hidpp10_constants import Registers

import typing
if typing.TYPE_CHECKING:
from .base import HIDPPNotification
from .receiver import Receiver
Expand Down Expand Up @@ -74,7 +74,7 @@ def _process_receiver_notification(receiver: "Receiver", hidpp_notification: "HI
Registers.DISCOVERY_STATUS_NOTIFICATION,
Registers.PAIRING_STATUS_NOTIFICATION,
Registers.PASSKEY_PRESSED_NOTIFICATION,
Registers.PASSKEY_REQUEST_NOTIFICATION
Registers.PASSKEY_REQUEST_NOTIFICATION,
]

if hidpp_notification.sub_id == Notification.PAIRING_LOCK:
Expand Down Expand Up @@ -124,7 +124,7 @@ def _process_receiver_notification(receiver: "Receiver", hidpp_notification: "HI
receiver.pairing.device_address = hidpp_notification.data[6:12]
receiver.pairing.device_authentication = hidpp_notification.data[14]
elif hidpp_notification.data[1] == 1:
receiver.pairing.device_name = hidpp_notification.data[3: 3 + hidpp_notification.data[2]].decode("utf-8")
receiver.pairing.device_name = hidpp_notification.data[3 : 3 + hidpp_notification.data[2]].decode("utf-8")
return True

elif hidpp_notification.sub_id == Registers.PAIRING_STATUS_NOTIFICATION: # Bolt pairing
Expand Down
12 changes: 7 additions & 5 deletions tests/logitech_receiver/test_notifications.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,13 @@

import pytest

from logitech_receiver import notifications, hidpp10_constants
from logitech_receiver import hidpp10_constants
from logitech_receiver import notifications
from logitech_receiver.base import HIDPPNotification

from logitech_receiver.hidpp10_constants import Registers
from logitech_receiver.receiver import Receiver, LowLevelInterface
from logitech_receiver.receiver import LowLevelInterface
from logitech_receiver.receiver import Receiver


# Create a mock LowLevelInterface for testing
Expand All @@ -27,13 +29,13 @@ def request(self, handle, devnumber, request_id, *params, **kwargs):
@pytest.mark.parametrize(
"sub_id, notification_data, expected_error, expected_new_device",
[
(Registers.DISCOVERY_STATUS_NOTIFICATION, b'\x01', 'device_timeout', None),
(Registers.PAIRING_STATUS_NOTIFICATION, b'\x02', 'failed', None),
(Registers.DISCOVERY_STATUS_NOTIFICATION, b'\x01', "device_timeout", None),
(Registers.PAIRING_STATUS_NOTIFICATION, b'\x02', "failed", None),
]
)
def test_process_receiver_notification_bolt_pairing_error(sub_id, notification_data, expected_error, expected_new_device):
low_level_mock = mock.Mock(spec=LowLevelInterface)
serial_reply = b'\x00\x00\x00\x00\x00\x00\x00\x00'
serial_reply = b"\x00\x00\x00\x00\x00\x00\x00\x00"
low_level_mock.read_register = mock.Mock(return_value=serial_reply)

receiver: Receiver = Receiver(MockLowLevelInterface(), None, {}, True, None, None)
Expand Down

0 comments on commit 01f5650

Please sign in to comment.