should work so far
This commit is contained in:
@@ -13,17 +13,26 @@ class ToDevices(AbstractMqttPublisher):
|
||||
sleep(60.0)
|
||||
|
||||
def onMessage(self, topic, payload):
|
||||
logger.info("mqtt message received: {} -> {}".format(topic, str(payload)))
|
||||
if payload == b'On':
|
||||
self.modbusHandler.writeCoil(1, 0, 1)
|
||||
elif payload == b'Off':
|
||||
self.modbusHandler.writeCoil(1, 0, 0)
|
||||
else:
|
||||
logger.warning(f"Illegal command {payload} received")
|
||||
|
||||
try:
|
||||
logger.debug("mqtt message received: {} -> {}".format(topic, str(payload)))
|
||||
for device in self.config.input:
|
||||
if topic != device.subscribe_topic:
|
||||
continue
|
||||
logger.debug(f"{topic=} matches {device.subscribe_topic=}, processing")
|
||||
if not device.enabled:
|
||||
logger.debug(f" device disabled, skipping")
|
||||
continue
|
||||
if device.register_type != 'coil':
|
||||
raise Exception(f"Unsupported register type {device.register_type} for input device {device.name}")
|
||||
value = payload == b'On'
|
||||
self.modbusHandler.writeCoil(device.slave_id, device.address, value)
|
||||
except Exception as e:
|
||||
logger.error(f"Caught exception in onMessage: {str(e)}")
|
||||
|
||||
|
||||
def onConnect(self):
|
||||
logger.info("mqtt connected")
|
||||
self.client.subscribe("{}".format(self.config["relaisSubscribeTopic"]))
|
||||
for device in self.config.input:
|
||||
self.client.subscribe(device.subscribe_topic)
|
||||
logger.info(f"subscribed to topic: {device.subscribe_topic}")
|
||||
logger.info("subscribed")
|
||||
|
||||
Reference in New Issue
Block a user