Skip to content

Commit

Permalink
Merge branch 'develop'
Browse files Browse the repository at this point in the history
  • Loading branch information
rroemhild committed Oct 31, 2019
2 parents 378dc58 + 713cb36 commit 9ae1de1
Showing 1 changed file with 9 additions and 5 deletions.
14 changes: 9 additions & 5 deletions homie/device.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,12 +100,12 @@ def format_topic(self, topic):

async def subscribe(self, topic):
topic = self.format_topic(topic)
# print("MQTT SUBSCRIBE: {}".format(topic))
self.dprint("MQTT SUBSCRIBE: {}".format(topic))
await self.mqtt.subscribe(topic, QOS)

async def unsubscribe(self, topic):
topic = self.format_topic(topic)
# print("MQTT UNSUBSCRIBE: {}".format(topic))
self.dprint("MQTT UNSUBSCRIBE: {}".format(topic))
await self.mqtt.unsubscribe(topic)

async def add_node_cb(self, node):
Expand Down Expand Up @@ -169,7 +169,7 @@ async def connection_handler(self, client):
await self.publish(DEVICE_STATE, STATE_READY)

def sub_cb(self, topic, msg, retained):
# print("MQTT MESSAGE: {} --> {}, {}".format(topic, msg, retained))
self.dprint("MQTT MESSAGE: {} --> {}, {}".format(topic, msg, retained))

# broadcast callback passed to nodes
if b"/$broadcast" in topic:
Expand All @@ -188,7 +188,7 @@ async def publish(self, topic, payload, retain=True):
payload = bytes(str(payload), UTF8)

t = SLASH.join((self.dtopic, topic))
# print('MQTT PUBLISH: {} --> {}'.format(t, payload))
self.dprint('MQTT PUBLISH: {} --> {}'.format(t, payload))
await self.mqtt.publish(t, payload, retain, QOS)

async def broadcast(self, payload, level=None):
Expand All @@ -200,7 +200,7 @@ async def broadcast(self, payload, level=None):
if isinstance(level, str):
level = level.encode()
topic = SLASH.join((topic, level))
# print("MQTT BROADCAST: {} --> {}".format(topic, payload))
self.dprint("MQTT BROADCAST: {} --> {}".format(topic, payload))
await self.mqtt.publish(topic, payload, retain=False, qos=QOS)

async def publish_properties(self):
Expand Down Expand Up @@ -270,6 +270,10 @@ async def wdt(self):
wdt.feed()
await sleep_ms(WDT_DELAY)

def dprint(self, *args):
if self.DEBUG:
print(*args)

def start(self):
# DeprecationWarning
self.run_forever()

0 comments on commit 9ae1de1

Please sign in to comment.