Test receiver notification info
This commit is contained in:
parent
a822b2f237
commit
41768d9616
|
@ -41,6 +41,8 @@ from .hidpp10_constants import Registers
|
||||||
if typing.TYPE_CHECKING:
|
if typing.TYPE_CHECKING:
|
||||||
from logitech_receiver import common
|
from logitech_receiver import common
|
||||||
|
|
||||||
|
from .base import HIDPPNotification
|
||||||
|
|
||||||
logger = logging.getLogger(__name__)
|
logger = logging.getLogger(__name__)
|
||||||
|
|
||||||
_hidpp10 = hidpp10.Hidpp10()
|
_hidpp10 = hidpp10.Hidpp10()
|
||||||
|
@ -198,7 +200,7 @@ class Receiver:
|
||||||
if not self.write_register(Registers.RECEIVER_CONNECTION, 0x02):
|
if not self.write_register(Registers.RECEIVER_CONNECTION, 0x02):
|
||||||
logger.warning("%s: failed to trigger device link notifications", self)
|
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"""
|
"""Extract information from unifying-style notification"""
|
||||||
assert notification.address != 0x02
|
assert notification.address != 0x02
|
||||||
online = not bool(notification.data[0] & 0x40)
|
online = not bool(notification.data[0] & 0x40)
|
||||||
|
|
|
@ -12,6 +12,13 @@ from logitech_receiver import receiver
|
||||||
from . import fake_hidpp
|
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:
|
class LowLevelInterfaceFake:
|
||||||
def __init__(self, responses=None):
|
def __init__(self, responses=None):
|
||||||
self.responses = responses
|
self.responses = responses
|
||||||
|
@ -189,3 +196,27 @@ def test_receiver_factory_no_device(device_info, responses):
|
||||||
|
|
||||||
with pytest.raises(exceptions.NoSuchDevice):
|
with pytest.raises(exceptions.NoSuchDevice):
|
||||||
r.device_pairing_information(1)
|
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"
|
||||||
|
|
Loading…
Reference in New Issue