Cleanups and add support for mysensors

This commit is contained in:
zewelor
2018-01-14 12:14:55 +01:00
parent 4b05c1521e
commit 7e5ed968b6
4 changed files with 35 additions and 10 deletions
-6
View File
@@ -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])
+20
View File
@@ -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)])