Fix mqtt prefix handling on thermostat worker (#30)

This commit is contained in:
Friedo
2018-11-28 15:52:52 +01:00
committed by zewelor
parent 7a3fedac36
commit a5a4797a1d
2 changed files with 5 additions and 1 deletions
+2
View File
@@ -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)
+3 -1
View File
@@ -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')