From c0c2001f9f481209f62e32a3b1f9eaa7e1932684 Mon Sep 17 00:00:00 2001 From: polyfloyd Date: Wed, 20 Sep 2023 18:48:22 +0200 Subject: [PATCH] Do not relay retained messages on startup --- main.py | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/main.py b/main.py index 9eb633b..bfc6bc8 100755 --- a/main.py +++ b/main.py @@ -104,12 +104,24 @@ def webhook_message(msg): webhook.execute() +retained = { + 'bitlair/photos', + 'bitlair/state', + 'bitlair/state/djo', +} + # post to mqtt discord channel when state changes def on_message(client, userdata, msg): try: topic = msg.topic msg = msg.payload.decode() + # Retained messages trigger an initial message on connecting. Prevent relaying them to + # Discord on startup. + if topic in retained: + retained.remove(topic) + return + if topic == 'bitlair/state': webhook_message('Bitlair is now %s' % msg.upper()) elif topic == 'bitlair/state/djo':