From a5a4797a1d4f5408deb9a116a1281837c050a8ff Mon Sep 17 00:00:00 2001 From: Friedo <8314092+unconfigured@users.noreply.github.com> Date: Wed, 28 Nov 2018 15:52:52 +0100 Subject: [PATCH] Fix mqtt prefix handling on thermostat worker (#30) --- mqtt.py | 2 ++ workers/thermostat.py | 4 +++- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/mqtt.py b/mqtt.py index 88037ed..2f94792 100644 --- a/mqtt.py +++ b/mqtt.py @@ -59,6 +59,8 @@ class MqttClient: self.mqttc.connect(self.hostname, port=self.port) for topic, callback in callbacks: + if self.topic_prefix is not None: + topic = "{}/{}".format(self.topic_prefix, topic) self.mqttc.message_callback_add(topic, callback) self.mqttc.subscribe(topic) diff --git a/workers/thermostat.py b/workers/thermostat.py index de4fc14..3f4dc8e 100644 --- a/workers/thermostat.py +++ b/workers/thermostat.py @@ -71,7 +71,9 @@ class ThermostatWorker(BaseWorker): return ret def on_command(self, topic, value): - _, device_name, method, _ = topic.split('/') + if self.topic_prefix is not None: + _, device_name, method, _ = topic[len(self.topic_prefix+"/"):].split('/') + thermostat = self.devices[device_name] value = value.decode('utf-8')