diff --git a/mqtt.py b/mqtt.py index 0ff9c13..0d9e4c8 100644 --- a/mqtt.py +++ b/mqtt.py @@ -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) diff --git a/workers_manager.py b/workers_manager.py index 616d77e..15c039d 100644 --- a/workers_manager.py +++ b/workers_manager.py @@ -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]))