refactor: Get receiver product info before instantiation

Related #2350
This commit is contained in:
Matthias Hagmann 2024-03-02 17:45:53 +01:00 committed by Peter F. Patel-Schneider
parent 8f6e8eef4c
commit c3b6802373
1 changed files with 7 additions and 6 deletions

View File

@ -39,9 +39,14 @@ class ReceiverFactory:
:returns: An open file handle for the found receiver, or ``None``. :returns: An open file handle for the found receiver, or ``None``.
""" """
try: try:
product_info = _base.product_information(device_info.product_id)
if not product_info:
logger.warning("Unknown receiver type: %s", device_info.product_id)
product_info = {}
handle = _base.open_path(device_info.path) handle = _base.open_path(device_info.path)
if handle: if handle:
return Receiver(handle, device_info.path, device_info.product_id, setting_callback) return Receiver(product_info, handle, device_info.path, device_info.product_id, setting_callback)
except OSError as e: except OSError as e:
logger.exception("open %s", device_info) logger.exception("open %s", device_info)
if e.errno == _errno.EACCES: if e.errno == _errno.EACCES:
@ -59,17 +64,13 @@ class Receiver:
number = 0xFF number = 0xFF
kind = None kind = None
def __init__(self, handle, path, product_id, setting_callback=None): def __init__(self, product_info, handle, path, product_id, setting_callback=None):
assert handle assert handle
self.isDevice = False # some devices act as receiver so we need a property to distinguish them self.isDevice = False # some devices act as receiver so we need a property to distinguish them
self.handle = handle self.handle = handle
self.path = path self.path = path
self.product_id = product_id self.product_id = product_id
self.setting_callback = setting_callback self.setting_callback = setting_callback
product_info = _base.product_information(self.product_id)
if not product_info:
logger.warning("Unknown receiver type: %s", self.product_id)
product_info = {}
self.receiver_kind = product_info.get("receiver_kind", "unknown") self.receiver_kind = product_info.get("receiver_kind", "unknown")
# read the serial immediately, so we can find out max_devices # read the serial immediately, so we can find out max_devices