Skip to content

Commit

Permalink
Test receiver notification info
Browse files Browse the repository at this point in the history
  • Loading branch information
MattHag authored and pfps committed Jan 1, 2025
1 parent a822b2f commit 41768d9
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 1 deletion.
4 changes: 3 additions & 1 deletion lib/logitech_receiver/receiver.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@
if typing.TYPE_CHECKING:
from logitech_receiver import common

from .base import HIDPPNotification

logger = logging.getLogger(__name__)

_hidpp10 = hidpp10.Hidpp10()
Expand Down Expand Up @@ -198,7 +200,7 @@ def notify_devices(self):
if not self.write_register(Registers.RECEIVER_CONNECTION, 0x02):
logger.warning("%s: failed to trigger device link notifications", self)

def notification_information(self, number, notification):
def notification_information(self, number, notification: HIDPPNotification) -> tuple[bool, bool, typing.Any, str]:
"""Extract information from unifying-style notification"""
assert notification.address != 0x02
online = not bool(notification.data[0] & 0x40)
Expand Down
31 changes: 31 additions & 0 deletions tests/logitech_receiver/test_receiver.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,13 @@
from . import fake_hidpp


@pytest.fixture
def nano_recv():
device_info = DeviceInfo("12", product_id=0xC534)
mock_low_level = LowLevelInterfaceFake(responses_lacking)
yield receiver.create_receiver(mock_low_level, device_info, lambda x: x)


class LowLevelInterfaceFake:
def __init__(self, responses=None):
self.responses = responses
Expand Down Expand Up @@ -189,3 +196,27 @@ def test_receiver_factory_no_device(device_info, responses):

with pytest.raises(exceptions.NoSuchDevice):
r.device_pairing_information(1)


@pytest.mark.parametrize(
"address, data, expected_online, expected_encrypted",
[
(0x03, b"\x01\x02\x03", True, False),
(0x10, b"\x61\x02\x03", False, True),
],
)
def test_notification_information_nano_receiver(nano_recv, address, data, expected_online, expected_encrypted):
_number = 0
notification = base.HIDPPNotification(
report_id=0x01,
devnumber=0x52C,
sub_id=0,
address=address,
data=data,
)
online, encrypted, wpid, kind = nano_recv.notification_information(_number, notification)

assert online == expected_online
assert encrypted == expected_encrypted
assert wpid == "0302"
assert kind == "keyboard"

0 comments on commit 41768d9

Please sign in to comment.