Test mqtt topic subscription problem (#41)

This commit is contained in:
zewelor
2018-12-31 07:19:52 +01:00
committed by GitHub
parent 6496e88d7b
commit 6faf7ec141
+4 -3
View File
@@ -13,9 +13,6 @@ class MqttClient:
if self.username and self.password:
self.mqttc.username_pw_set(self.username, self.password)
self.mqttc.connect(self.hostname, port=self.port)
self.mqttc.loop_start()
def publish(self, messages):
if not messages:
return
@@ -53,12 +50,16 @@ class MqttClient:
return self._mqttc
def callbacks_subscription(self, callbacks):
self.mqttc.connect(self.hostname, port=self.port)
for topic, callback in callbacks:
topic = "{}/{}".format(self.topic_prefix, topic) if self.topic_prefix else topic
_LOGGER.debug("Subscribing to: %s" % topic)
self.mqttc.message_callback_add(topic, callback)
self.mqttc.subscribe(topic)
self.mqttc.loop_start()
class MqttMessage:
def __init__(self, topic=None, payload=None):