relais support
This commit is contained in:
29
src/pv_controller/RelaisSubscribe.py
Normal file
29
src/pv_controller/RelaisSubscribe.py
Normal file
@ -0,0 +1,29 @@
|
||||
from MqttBase import AbstractMqttPublisher
|
||||
from loguru import logger
|
||||
from time import sleep
|
||||
|
||||
|
||||
class RelaisSubscribe(AbstractMqttPublisher):
|
||||
def __init__(self, config, modbusHandler):
|
||||
super().__init__(config)
|
||||
self.modbusHandler = modbusHandler
|
||||
|
||||
def localLoop(self):
|
||||
while not self.killBill:
|
||||
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")
|
||||
|
||||
|
||||
|
||||
def onConnect(self):
|
||||
logger.info("mqtt connected")
|
||||
self.client.subscribe("{}".format(self.config["relaisSubscribeTopic"]))
|
||||
logger.info("subscribed")
|
Reference in New Issue
Block a user