Compare commits

..

5 Commits

3 changed files with 6 additions and 5 deletions

View File

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

View File

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

View File

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