diff --git a/lib/logitech_receiver/receiver.py b/lib/logitech_receiver/receiver.py index 758327fcc1..8cff67f675 100644 --- a/lib/logitech_receiver/receiver.py +++ b/lib/logitech_receiver/receiver.py @@ -31,6 +31,25 @@ _IR = hidpp10_constants.INFO_SUBREGISTERS +class ReceiverFactory: + @staticmethod + def create_receiver(device_info, setting_callback=None): + """Opens a Logitech Receiver found attached to the machine, by Linux device path. + + :returns: An open file handle for the found receiver, or ``None``. + """ + try: + handle = _base.open_path(device_info.path) + if handle: + return Receiver(handle, device_info.path, device_info.product_id, setting_callback) + except OSError as e: + logger.exception("open %s", device_info) + if e.errno == _errno.EACCES: + raise + except Exception: + logger.exception("open %s", device_info) + + class Receiver: """A Unifying Receiver instance. @@ -376,20 +395,3 @@ def __str__(self): __repr__ = __str__ __bool__ = __nonzero__ = lambda self: self.handle is not None - - @classmethod - def open(self, device_info, setting_callback=None): - """Opens a Logitech Receiver found attached to the machine, by Linux device path. - - :returns: An open file handle for the found receiver, or ``None``. - """ - try: - handle = _base.open_path(device_info.path) - if handle: - return Receiver(handle, device_info.path, device_info.product_id, setting_callback) - except OSError as e: - logger.exception("open %s", device_info) - if e.errno == _errno.EACCES: - raise - except Exception: - logger.exception("open %s", device_info) diff --git a/lib/solaar/cli/__init__.py b/lib/solaar/cli/__init__.py index 8662836e85..282155c2e1 100644 --- a/lib/solaar/cli/__init__.py +++ b/lib/solaar/cli/__init__.py @@ -110,7 +110,7 @@ def _receivers(dev_path=None): if dev_path is not None and dev_path != dev_info.path: continue try: - r = _receiver.Receiver.open(dev_info) + r = _receiver.ReceiverFactory.create_receiver(dev_info) if logger.isEnabledFor(logging.DEBUG): logger.debug("[%s] => %s", dev_info.path, r) if r: @@ -125,7 +125,11 @@ def _receivers_and_devices(dev_path=None): if dev_path is not None and dev_path != dev_info.path: continue try: - d = _device.Device.open(dev_info) if dev_info.isDevice else _receiver.Receiver.open(dev_info) + if dev_info.isDevice: + d = _device.Device.open(dev_info) + else: + d = _receiver.ReceiverFactory.create_receiver(dev_info) + if logger.isEnabledFor(logging.DEBUG): logger.debug("[%s] => %s", dev_info.path, d) if d is not None: diff --git a/lib/solaar/listener.py b/lib/solaar/listener.py index fe2231b3d6..65c36721a6 100644 --- a/lib/solaar/listener.py +++ b/lib/solaar/listener.py @@ -244,7 +244,7 @@ def _start(device_info): assert _status_callback and _setting_callback isDevice = device_info.isDevice if not isDevice: - receiver = _receiver.Receiver.open(device_info, _setting_callback) + receiver = _receiver.ReceiverFactory.create_receiver(device_info, _setting_callback) else: receiver = _device.Device.open(device_info, _setting_callback) configuration.attach_to(receiver)