This commit is contained in:
2020-07-09 21:11:52 +02:00
parent 8dfda3080d
commit 20abf8e8c0
7 changed files with 630 additions and 8 deletions
+10 -6
View File
@@ -83,10 +83,14 @@ class WorkersManager:
raise "%s cannot be initialized, it has to define run or status_update method" % worker_name
if 'topic_subscription' in worker_config:
self._mqtt_callbacks.append((
worker_config['topic_subscription'],
partial(self._on_command_wrapper, worker_obj)
))
topics = worker_config['topic_subscription']
if isinstance(topics, str):
topics = [topics]
for topic in topics:
self._mqtt_callbacks.append((
topic,
partial(self._on_command_wrapper, worker_obj)
))
if 'topic_subscription' in self._config:
for (callback_name, options) in self._config['topic_subscription'].items():
@@ -148,6 +152,6 @@ class WorkersManager:
for command in self._config_commands:
messages = command.execute()
for msg in messages:
msg.topic = "{}/{}".format(self._config['sensor_config'].get('topic', 'homeassistant'), msg.topic)
#msg.topic = "{}/{}".format(self._config['sensor_config'].get('topic', 'homeassistant'), msg.topic)
msg.retain = self._config['sensor_config'].get('retain', True)
mqtt.publish(messages)
mqtt.publish(messages)