Do not relay retained messages on startup

This commit is contained in:
polyfloyd 2023-09-20 18:48:22 +02:00
parent 1bae2d2c02
commit c0c2001f9f

12
main.py
View file

@ -104,12 +104,24 @@ def webhook_message(msg):
webhook.execute() webhook.execute()
retained = {
'bitlair/photos',
'bitlair/state',
'bitlair/state/djo',
}
# post to mqtt discord channel when state changes # post to mqtt discord channel when state changes
def on_message(client, userdata, msg): def on_message(client, userdata, msg):
try: try:
topic = msg.topic topic = msg.topic
msg = msg.payload.decode() 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': if topic == 'bitlair/state':
webhook_message('Bitlair is now %s' % msg.upper()) webhook_message('Bitlair is now %s' % msg.upper())
elif topic == 'bitlair/state/djo': elif topic == 'bitlair/state/djo':