Skip to content

Commit

Permalink
Fix runtime error if mqtt broker is not available on first start
Browse files Browse the repository at this point in the history
  • Loading branch information
rroemhild committed Oct 31, 2019
1 parent 9ae1de1 commit 210a6da
Showing 1 changed file with 8 additions and 9 deletions.
17 changes: 8 additions & 9 deletions homie/device.py
Original file line number Diff line number Diff line change
Expand Up @@ -248,15 +248,14 @@ async def publish_stats(self):
await sleep_ms(delay)

async def run(self):
try:
await self.mqtt.connect()
except OSError:
print("ERROR: can not connect to MQTT")
await sleep_ms(5000)
self.run_forever()

while True:
await sleep_ms(MAIN_DELAY)
try:
await self.mqtt.connect()
while True:
await sleep_ms(MAIN_DELAY)
except OSError:
print("ERROR: can not connect to MQTT")
await sleep_ms(5000)

def run_forever(self):
loop = get_event_loop()
Expand All @@ -271,7 +270,7 @@ async def wdt(self):
await sleep_ms(WDT_DELAY)

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

def start(self):
Expand Down

0 comments on commit 210a6da

Please sign in to comment.