platypush/platypush/backend/serial/__init__.py

34 lines
782 B
Python
Raw Normal View History

2018-04-07 03:08:52 +02:00
import serial
from platypush.backend import Backend
from platypush.context import get_plugin
2018-04-07 03:08:52 +02:00
from platypush.message.event.serial import SerialDataEvent
2018-06-06 20:09:18 +02:00
2018-04-07 03:08:52 +02:00
class SerialBackend(Backend):
def __init__(self, **kwargs):
2018-04-07 03:08:52 +02:00
super().__init__(**kwargs)
self.data = None
2018-04-07 03:08:52 +02:00
def send_message(self, msg):
pass
def get_data(self):
plugin = get_plugin('serial')
return plugin.get_data().output
2018-04-07 03:08:52 +02:00
def run(self):
super().run()
2018-06-06 20:09:18 +02:00
self.logger.info('Initialized serial backend')
2018-04-07 03:08:52 +02:00
while not self.should_stop():
new_data = self.get_data()
if self.data is None or self.data != new_data:
self.bus.post(SerialDataEvent(data=new_data))
2018-04-07 03:08:52 +02:00
self.data = new_data
2018-04-07 03:08:52 +02:00
# vim:sw=4:ts=4:et: