Skip to content
Snippets Groups Projects
Commit 3d325d90 authored by Matthias Bodenbenner's avatar Matthias Bodenbenner
Browse files

removed badly integrated publisher

parent 5dbcc318
No related branches found
No related tags found
No related merge requests found
Pipeline #17735 passed
No preview for this file type
from setuptools import setup, find_packages
setup(name='wzl-mqtt',
version='1.1.3',
version='1.2.0',
url='',
author='Benjamin Montavon, Matthias Bodenbenner',
author_email='m.bodenbenner@wzl.rwth-aachen.de',
......
......@@ -11,4 +11,3 @@ from .exceptions import PublishError as PublishError
from .client import MQTTPublisher
from .client import MQTTReceiver
from .specialized import ScheduledMQTTPublisher
import datetime
import json
from typing import Dict
from .client import MQTTPublisher
class ScheduledMQTTPublisher(MQTTPublisher):
def __init__(self, loop, duid, schedule: Dict, *args, **kwargs):
MQTTPublisher.__init__(self, duid, *args, **kwargs)
self._loop = loop
self._schedule = schedule
if len(self._schedule.keys()) > 0:
self._update()
def _update(self):
now = datetime.datetime.now()
next = None
for luid in self._schedule:
data = self._schedule[luid]
if data['next'] is not None and data['next'] <= now:
try:
value = data['method']()
ret = {'uuid': luid, 'value': value}
self.publish(luid, json.dumps(ret), 1)
except Exception as e:
pass
try:
if callable(data['interval']):
data['next'] = now + datetime.timedelta(seconds=data['interval']())
else:
data['next'] = now + datetime.timedelta(seconds=data['interval'])
except Exception as e:
# if the next time for publishing can not be set, deactivate publising by setting 'next' to None
data['next'] = None
if next is None or (data['next'] is not None and data['next'] < next):
next = data['next']
if next is None:
next = now + datetime.timedelta(seconds=10)
self._loop.call_later((next - now).seconds + (next - now).microseconds / 1e6, self._update)
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment