Add support for mqtt birth message

This commit is contained in:
zewelor
2017-12-06 10:14:43 +01:00
parent 2295cdc1df
commit b32897f949
5 changed files with 74 additions and 27 deletions
+6 -1
View File
@@ -1,11 +1,15 @@
import paho.mqtt.publish as publish
import paho.mqtt.client as mqtt
class MqttClient:
def __init__(self, config):
self._config = config
def publish(self, messages):
if messages is None:
return
publish.multiple(list(map(lambda m: m.as_dict, messages)),
hostname=self.hostname,
auth={'username': self.username, 'password': self.password})
@@ -34,6 +38,7 @@ class MqttClient:
mqttc.loop_start()
class MqttMessage:
def __init__(self, topic=None, payload=None):
self._topic = topic
@@ -59,7 +64,7 @@ class MqttMessage:
}
def __repr__(self):
return self.as_dict.__str__()
return self.as_dict.__str__()
def __str__(self):
return self.__repr__()