Test mqtt topic subscription problem (#41)
This commit is contained in:
@@ -13,9 +13,6 @@ class MqttClient:
|
|||||||
if self.username and self.password:
|
if self.username and self.password:
|
||||||
self.mqttc.username_pw_set(self.username, 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):
|
def publish(self, messages):
|
||||||
if not messages:
|
if not messages:
|
||||||
return
|
return
|
||||||
@@ -53,12 +50,16 @@ class MqttClient:
|
|||||||
return self._mqttc
|
return self._mqttc
|
||||||
|
|
||||||
def callbacks_subscription(self, callbacks):
|
def callbacks_subscription(self, callbacks):
|
||||||
|
self.mqttc.connect(self.hostname, port=self.port)
|
||||||
|
|
||||||
for topic, callback in callbacks:
|
for topic, callback in callbacks:
|
||||||
topic = "{}/{}".format(self.topic_prefix, topic) if self.topic_prefix else topic
|
topic = "{}/{}".format(self.topic_prefix, topic) if self.topic_prefix else topic
|
||||||
_LOGGER.debug("Subscribing to: %s" % topic)
|
_LOGGER.debug("Subscribing to: %s" % topic)
|
||||||
self.mqttc.message_callback_add(topic, callback)
|
self.mqttc.message_callback_add(topic, callback)
|
||||||
self.mqttc.subscribe(topic)
|
self.mqttc.subscribe(topic)
|
||||||
|
|
||||||
|
self.mqttc.loop_start()
|
||||||
|
|
||||||
|
|
||||||
class MqttMessage:
|
class MqttMessage:
|
||||||
def __init__(self, topic=None, payload=None):
|
def __init__(self, topic=None, payload=None):
|
||||||
|
|||||||
Reference in New Issue
Block a user