Skip to content
Snippets Groups Projects
Commit 973336db authored by fxk8y's avatar fxk8y :spider:
Browse files

Publish automatically converts most types now

parent 058e0768
No related branches found
No related tags found
No related merge requests found
......@@ -348,11 +348,15 @@ class SpiderMQTT:
def isConnected(self):
return self.connected
def publish(self, topic, payload=None, qos=0, retain=False):
def publish(self, topic, payload=None, qos=0, retain=False, prettyPrintYAML=False):
if type(payload) is str:
pl = message.encode('utf-8')
pl = payload.encode('utf-8')
elif type(payload) in [bool, int, float, complex]:
pl = str(payload).encode('utf-8')
elif type(payload) in [list, set, dict]:
pl = yaml.dump(payload, default_flow_style=not prettyPrintYAML).encode('utf-8')
else:
pl = message
pl = payload
if self.isConnected():
self.mqtt.publish(topic, pl, qos, retain)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment