Compare commits

..

1 Commits

Author SHA1 Message Date
Viktor Walter
111faaaaae Adding variation for compatibility with Python3 < 3.10 2023-06-10 15:35:52 +02:00
3 changed files with 5 additions and 6 deletions

View File

@ -11,10 +11,10 @@ DEVICE_IDENTIFIERS: Final[Dict[int, Device]] = {
T = TypeVar("T", bound=Device) T = TypeVar("T", bound=Device)
def find_devices(device_cls: Type[T], address_space: Iterable[Any], dev="/dev/rs485", baudrate=19200) -> list[T]: def find_devices(device_cls: Type[T], address_space: Iterable[Any]) -> list[T]:
""" """
Look for devices in given address space Look for devices in given address space
""" """
return list(filter(lambda x: device_cls.probe(x,dev,baudrate), address_space)) return list(filter(device_cls.probe, address_space))
# TODO add device args # TODO add device args

View File

@ -53,16 +53,15 @@ class Device(ABC):
""" """
@classmethod @classmethod
def probe(cls, address, dev="/dev/rs485", baudrate=19200) -> bool: def probe(cls, address) -> bool:
""" """
Probe given address, return True if device detected, Probe given address, return True if device detected,
False otherwise False otherwise
""" """
# try instantiating; this raises NoResponseError # try instantiating; this raises NoResponseError
# if device not detected # if device not detected
print(f'Probing address {address}')
try: try:
_ = cls(address,dev,baudrate) _ = cls(address)
except NoResponseError: except NoResponseError:
return False return False
return True return True

View File

@ -83,7 +83,7 @@ class SensorWiredIAQ(ModbusRTUDevice):
deleted_registers = list(filter(lambda x: sensor in x, self.input_registers)) deleted_registers = list(filter(lambda x: sensor in x, self.input_registers))
_ = list((self.input_registers.pop(x) for x in deleted_registers)) _ = list((self.input_registers.pop(x) for x in deleted_registers))
def __init__(self, modbus_address, dev="/dev/rs485", baudrate=19200): def __init__(self, modbus_address, baudrate=19200, dev="/dev/rs485"):
super().__init__(modbus_address, baudrate, dev) super().__init__(modbus_address, baudrate, dev)
# detect sensor configuration and modify input_registers accordingly # detect sensor configuration and modify input_registers accordingly
# Check if VOC sensor present # Check if VOC sensor present