Remove factory wrapper classes
A module level function is sufficient, no wrapper needed.
This commit is contained in:
parent
ef6b7dec2c
commit
cba3533869
|
|
@ -60,9 +60,7 @@ class LowLevelInterface(Protocol):
|
||||||
...
|
...
|
||||||
|
|
||||||
|
|
||||||
class DeviceFactory:
|
def create_device(low_level: LowLevelInterface, device_info, setting_callback=None):
|
||||||
@staticmethod
|
|
||||||
def create_device(low_level: LowLevelInterface, device_info, setting_callback=None):
|
|
||||||
"""Opens a Logitech Device found attached to the machine, by Linux device path.
|
"""Opens a Logitech Device found attached to the machine, by Linux device path.
|
||||||
:returns: An open file handle for the found receiver, or None.
|
:returns: An open file handle for the found receiver, or None.
|
||||||
"""
|
"""
|
||||||
|
|
|
||||||
|
|
@ -512,9 +512,7 @@ receiver_class_mapping = {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
class ReceiverFactory:
|
def create_receiver(low_level: LowLevelInterface, device_info, setting_callback=None) -> Optional[Receiver]:
|
||||||
@staticmethod
|
|
||||||
def create_receiver(low_level: LowLevelInterface, device_info, setting_callback=None) -> Optional[Receiver]:
|
|
||||||
"""Opens a Logitech Receiver found attached to the machine, by Linux device path."""
|
"""Opens a Logitech Receiver found attached to the machine, by Linux device path."""
|
||||||
|
|
||||||
try:
|
try:
|
||||||
|
|
|
||||||
|
|
@ -106,7 +106,7 @@ def _receivers(dev_path=None):
|
||||||
if dev_path is not None and dev_path != dev_info.path:
|
if dev_path is not None and dev_path != dev_info.path:
|
||||||
continue
|
continue
|
||||||
try:
|
try:
|
||||||
r = receiver.ReceiverFactory.create_receiver(base, dev_info)
|
r = receiver.create_receiver(base, dev_info)
|
||||||
if logger.isEnabledFor(logging.DEBUG):
|
if logger.isEnabledFor(logging.DEBUG):
|
||||||
logger.debug("[%s] => %s", dev_info.path, r)
|
logger.debug("[%s] => %s", dev_info.path, r)
|
||||||
if r:
|
if r:
|
||||||
|
|
@ -122,9 +122,9 @@ def _receivers_and_devices(dev_path=None):
|
||||||
continue
|
continue
|
||||||
try:
|
try:
|
||||||
if dev_info.isDevice:
|
if dev_info.isDevice:
|
||||||
d = device.DeviceFactory.create_device(base, dev_info)
|
d = device.create_device(base, dev_info)
|
||||||
else:
|
else:
|
||||||
d = receiver.ReceiverFactory.create_receiver(base, dev_info)
|
d = receiver.create_receiver(base, dev_info)
|
||||||
|
|
||||||
if logger.isEnabledFor(logging.DEBUG):
|
if logger.isEnabledFor(logging.DEBUG):
|
||||||
logger.debug("[%s] => %s", dev_info.path, d)
|
logger.debug("[%s] => %s", dev_info.path, d)
|
||||||
|
|
|
||||||
|
|
@ -255,9 +255,9 @@ def _start(device_info):
|
||||||
assert _status_callback and _setting_callback
|
assert _status_callback and _setting_callback
|
||||||
isDevice = device_info.isDevice
|
isDevice = device_info.isDevice
|
||||||
if not isDevice:
|
if not isDevice:
|
||||||
receiver_ = logitech_receiver.receiver.ReceiverFactory.create_receiver(base, device_info, _setting_callback)
|
receiver_ = logitech_receiver.receiver.create_receiver(base, device_info, _setting_callback)
|
||||||
else:
|
else:
|
||||||
receiver_ = logitech_receiver.device.DeviceFactory.create_device(base, device_info, _setting_callback)
|
receiver_ = logitech_receiver.device.create_device(base, device_info, _setting_callback)
|
||||||
if receiver_:
|
if receiver_:
|
||||||
configuration.attach_to(receiver_)
|
configuration.attach_to(receiver_)
|
||||||
if receiver_.bluetooth and receiver_.hid_serial:
|
if receiver_.bluetooth and receiver_.hid_serial:
|
||||||
|
|
|
||||||
|
|
@ -82,12 +82,12 @@ def test_create_device(device_info, responses, expected_success):
|
||||||
low_level_mock = LowLevelInterfaceFake(responses)
|
low_level_mock = LowLevelInterfaceFake(responses)
|
||||||
if expected_success is None:
|
if expected_success is None:
|
||||||
with pytest.raises(PermissionError):
|
with pytest.raises(PermissionError):
|
||||||
device.DeviceFactory.create_device(low_level_mock, device_info)
|
device.create_device(low_level_mock, device_info)
|
||||||
elif not expected_success:
|
elif not expected_success:
|
||||||
with pytest.raises(TypeError):
|
with pytest.raises(TypeError):
|
||||||
device.DeviceFactory.create_device(low_level_mock, device_info)
|
device.create_device(low_level_mock, device_info)
|
||||||
else:
|
else:
|
||||||
test_device = device.DeviceFactory.create_device(low_level_mock, device_info)
|
test_device = device.create_device(low_level_mock, device_info)
|
||||||
assert bool(test_device) == expected_success
|
assert bool(test_device) == expected_success
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -98,7 +98,7 @@ def test_create_device(device_info, responses, expected_success):
|
||||||
def test_device_name(device_info, responses, expected_codename, expected_name, expected_kind):
|
def test_device_name(device_info, responses, expected_codename, expected_name, expected_kind):
|
||||||
low_level = LowLevelInterfaceFake(responses)
|
low_level = LowLevelInterfaceFake(responses)
|
||||||
|
|
||||||
test_device = device.DeviceFactory.create_device(low_level, device_info)
|
test_device = device.create_device(low_level, device_info)
|
||||||
|
|
||||||
assert test_device.codename == expected_codename
|
assert test_device.codename == expected_codename
|
||||||
assert test_device.name == expected_name
|
assert test_device.name == expected_name
|
||||||
|
|
|
||||||
|
|
@ -133,12 +133,12 @@ def test_receiver_factory_create_receiver(device_info, responses, handle, serial
|
||||||
|
|
||||||
if handle is False:
|
if handle is False:
|
||||||
with pytest.raises(Exception): # noqa: B017
|
with pytest.raises(Exception): # noqa: B017
|
||||||
receiver.ReceiverFactory.create_receiver(mock_low_level, device_info, lambda x: x)
|
receiver.create_receiver(mock_low_level, device_info, lambda x: x)
|
||||||
elif handle is None:
|
elif handle is None:
|
||||||
r = receiver.ReceiverFactory.create_receiver(mock_low_level, device_info, lambda x: x)
|
r = receiver.create_receiver(mock_low_level, device_info, lambda x: x)
|
||||||
assert r is None
|
assert r is None
|
||||||
else:
|
else:
|
||||||
r = receiver.ReceiverFactory.create_receiver(mock_low_level, device_info, lambda x: x)
|
r = receiver.create_receiver(mock_low_level, device_info, lambda x: x)
|
||||||
assert r.handle == handle
|
assert r.handle == handle
|
||||||
assert r.serial == serial
|
assert r.serial == serial
|
||||||
assert r.max_devices == max_devices
|
assert r.max_devices == max_devices
|
||||||
|
|
@ -155,7 +155,7 @@ def test_receiver_factory_create_receiver(device_info, responses, handle, serial
|
||||||
def test_receiver_factory_props(device_info, responses, firmware, codename, remaining_pairings, pairing_info, count):
|
def test_receiver_factory_props(device_info, responses, firmware, codename, remaining_pairings, pairing_info, count):
|
||||||
mock_low_level = LowLevelInterfaceFake(responses)
|
mock_low_level = LowLevelInterfaceFake(responses)
|
||||||
|
|
||||||
r = receiver.ReceiverFactory.create_receiver(mock_low_level, device_info, lambda x: x)
|
r = receiver.create_receiver(mock_low_level, device_info, lambda x: x)
|
||||||
|
|
||||||
assert len(r.firmware) == firmware if firmware is not None else firmware is None
|
assert len(r.firmware) == firmware if firmware is not None else firmware is None
|
||||||
assert r.device_codename(2) == codename
|
assert r.device_codename(2) == codename
|
||||||
|
|
@ -175,7 +175,7 @@ def test_receiver_factory_props(device_info, responses, firmware, codename, rema
|
||||||
def test_receiver_factory_string(device_info, responses, status_str, strng):
|
def test_receiver_factory_string(device_info, responses, status_str, strng):
|
||||||
mock_low_level = LowLevelInterfaceFake(responses)
|
mock_low_level = LowLevelInterfaceFake(responses)
|
||||||
|
|
||||||
r = receiver.ReceiverFactory.create_receiver(mock_low_level, device_info, lambda x: x)
|
r = receiver.create_receiver(mock_low_level, device_info, lambda x: x)
|
||||||
|
|
||||||
assert r.status_string() == status_str
|
assert r.status_string() == status_str
|
||||||
assert str(r) == strng
|
assert str(r) == strng
|
||||||
|
|
@ -191,7 +191,7 @@ def test_receiver_factory_string(device_info, responses, status_str, strng):
|
||||||
def test_receiver_factory_no_device(device_info, responses):
|
def test_receiver_factory_no_device(device_info, responses):
|
||||||
mock_low_level = LowLevelInterfaceFake(responses)
|
mock_low_level = LowLevelInterfaceFake(responses)
|
||||||
|
|
||||||
r = receiver.ReceiverFactory.create_receiver(mock_low_level, device_info, lambda x: x)
|
r = receiver.create_receiver(mock_low_level, device_info, lambda x: x)
|
||||||
|
|
||||||
with pytest.raises(exceptions.NoSuchDevice):
|
with pytest.raises(exceptions.NoSuchDevice):
|
||||||
r.device_pairing_information(1)
|
r.device_pairing_information(1)
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue