Cleanups and add support for mysensors
This commit is contained in:
@@ -1,5 +1,3 @@
|
||||
from abc import abstractmethod
|
||||
|
||||
class BaseWorker:
|
||||
def __init__(self, **args):
|
||||
for arg, value in args.items():
|
||||
@@ -9,9 +7,5 @@ class BaseWorker:
|
||||
def _setup(self):
|
||||
return
|
||||
|
||||
@abstractmethod
|
||||
def status_update(self, **args):
|
||||
...
|
||||
|
||||
def format_topic(self, *args):
|
||||
return '/'.join([self.topic_prefix, *args])
|
||||
|
||||
@@ -0,0 +1,20 @@
|
||||
from mqtt import MqttMessage
|
||||
from workers.base import BaseWorker
|
||||
from logger import _LOGGER
|
||||
import serial
|
||||
|
||||
REQUIREMENTS = ['pyserial']
|
||||
|
||||
|
||||
class MysensorsWorker(BaseWorker):
|
||||
def run(self, mqtt):
|
||||
with serial.Serial(self.port, self.baudrate, timeout=10) as ser:
|
||||
_LOGGER.debug("Starting mysensors at: %s" % ser.name)
|
||||
while True:
|
||||
line = ser.readline()
|
||||
if not line:
|
||||
continue
|
||||
splited_line = self.format_topic(line.decode('utf-8').strip()).split(';')
|
||||
topic = '/'.join(splited_line[0:-1])
|
||||
payload = ''.join(splited_line[-1])
|
||||
mqtt.publish([MqttMessage(topic=topic, payload=payload)])
|
||||
Reference in New Issue
Block a user