global topic_prefix fix try 2

This commit is contained in:
unconfigured
2018-12-20 12:33:29 +01:00
parent fabc48784b
commit f9f95a756b
2 changed files with 7 additions and 3 deletions
+3 -1
View File
@@ -5,7 +5,9 @@ class MqttClient:
def __init__(self, config):
self._config = config
self._mqttc = mqtt.Client(client_id=self.client_id, clean_session=False)
self._mqttc = mqtt.Client(client_id=self.client_id,
clean_session=False,
userdata = {'global_topic_prefix': self.topic_prefix})
if self.username and self.password:
self.mqttc.username_pw_set(self.username, self.password)
+4 -2
View File
@@ -102,6 +102,8 @@ class WorkersManager:
for package in package_names:
pip_main(['install', '-q', package])
def _on_command_wrapper(self, worker_obj, client, _, c):
def _on_command_wrapper(self, worker_obj, client, userdata, c):
_LOGGER.debug("on command wrapper for with %s: %s", c.topic, c.payload)
self._queue_command(self.Command(worker_obj.on_command, [c.topic, c.payload]))
global_topic_prefix = userdata['global_topic_prefix']
topic = c.topic[len(global_topic_prefix+'/'):] if global_topic_prefix is not None else c.topic
self._queue_command(self.Command(worker_obj.on_command, [topic, c.payload]))