parent
9c76a6c5ba
commit
a29f2b8614
|
@ -26,6 +26,7 @@ from .device import Device
|
||||||
|
|
||||||
logger = logging.getLogger(__name__)
|
logger = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
_hidpp10 = hidpp10.Hidpp10()
|
||||||
_R = hidpp10_constants.REGISTERS
|
_R = hidpp10_constants.REGISTERS
|
||||||
_IR = hidpp10_constants.INFO_SUBREGISTERS
|
_IR = hidpp10_constants.INFO_SUBREGISTERS
|
||||||
|
|
||||||
|
@ -98,7 +99,7 @@ class Receiver:
|
||||||
@property
|
@property
|
||||||
def firmware(self):
|
def firmware(self):
|
||||||
if self._firmware is None and self.handle:
|
if self._firmware is None and self.handle:
|
||||||
self._firmware = hidpp10.get_firmware(self)
|
self._firmware = _hidpp10.get_firmware(self)
|
||||||
return self._firmware
|
return self._firmware
|
||||||
|
|
||||||
# how many pairings remain (None for unknown, -1 for unlimited)
|
# how many pairings remain (None for unknown, -1 for unlimited)
|
||||||
|
@ -124,12 +125,12 @@ class Receiver:
|
||||||
)
|
)
|
||||||
else:
|
else:
|
||||||
set_flag_bits = 0
|
set_flag_bits = 0
|
||||||
ok = hidpp10.set_notification_flags(self, set_flag_bits)
|
ok = _hidpp10.set_notification_flags(self, set_flag_bits)
|
||||||
if ok is None:
|
if ok is None:
|
||||||
logger.warning("%s: failed to %s receiver notifications", self, "enable" if enable else "disable")
|
logger.warning("%s: failed to %s receiver notifications", self, "enable" if enable else "disable")
|
||||||
return None
|
return None
|
||||||
|
|
||||||
flag_bits = hidpp10.get_notification_flags(self)
|
flag_bits = _hidpp10.get_notification_flags(self)
|
||||||
flag_names = None if flag_bits is None else tuple(hidpp10_constants.NOTIFICATION_FLAG.flag_names(flag_bits))
|
flag_names = None if flag_bits is None else tuple(hidpp10_constants.NOTIFICATION_FLAG.flag_names(flag_bits))
|
||||||
if logger.isEnabledFor(logging.INFO):
|
if logger.isEnabledFor(logging.INFO):
|
||||||
logger.info("%s: receiver notifications %s => %s", self, "enabled" if enable else "disabled", flag_names)
|
logger.info("%s: receiver notifications %s => %s", self, "enabled" if enable else "disabled", flag_names)
|
||||||
|
|
2
setup.py
2
setup.py
|
@ -86,7 +86,7 @@ For instructions on installing Solaar see https://pwr-solaar.github.io/Solaar/in
|
||||||
"report-descriptor": ["hid-parser"],
|
"report-descriptor": ["hid-parser"],
|
||||||
"desktop-notifications": ["Notify (>= 0.7)"],
|
"desktop-notifications": ["Notify (>= 0.7)"],
|
||||||
"git-commit": ["python-git-info"],
|
"git-commit": ["python-git-info"],
|
||||||
"test": ["pytest", "pytest-cov"],
|
"test": ["pytest", "pytest-mock", "pytest-cov"],
|
||||||
"dev": ["ruff"],
|
"dev": ["ruff"],
|
||||||
},
|
},
|
||||||
package_dir={"": "lib"},
|
package_dir={"": "lib"},
|
||||||
|
|
|
@ -0,0 +1,42 @@
|
||||||
|
import pytest
|
||||||
|
|
||||||
|
from logitech_receiver import hidpp10, hidpp10_constants
|
||||||
|
|
||||||
|
|
||||||
|
class FakeDevice:
|
||||||
|
kind = "fake"
|
||||||
|
online = True
|
||||||
|
registers = [hidpp10_constants.REGISTERS.three_leds]
|
||||||
|
|
||||||
|
def request(self, *params):
|
||||||
|
return b"fake request"
|
||||||
|
|
||||||
|
def read_register(self, register_number, *params):
|
||||||
|
return "fake register"
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.fixture
|
||||||
|
def setup_hidpp10():
|
||||||
|
device = FakeDevice()
|
||||||
|
hid = hidpp10.Hidpp10()
|
||||||
|
|
||||||
|
yield device, hid
|
||||||
|
|
||||||
|
|
||||||
|
def test_hidpp10(setup_hidpp10):
|
||||||
|
device, hid = setup_hidpp10
|
||||||
|
|
||||||
|
firmwares = hid.get_firmware(device)
|
||||||
|
|
||||||
|
assert len(firmwares) == 3
|
||||||
|
for firmware in firmwares:
|
||||||
|
assert firmware.kind in ["Firmware", "Bootloader", "Other"]
|
||||||
|
|
||||||
|
|
||||||
|
def test_set_3leds(setup_hidpp10, mocker):
|
||||||
|
device, hid = setup_hidpp10
|
||||||
|
spy_write_register = mocker.spy(hidpp10, "write_register")
|
||||||
|
|
||||||
|
hid.set_3leds(device)
|
||||||
|
|
||||||
|
spy_write_register.assert_called_once_with(device, hidpp10_constants.REGISTERS.three_leds, 17, 17)
|
Loading…
Reference in New Issue