Do not relay retained messages on startup
This commit is contained in:
parent
1bae2d2c02
commit
c0c2001f9f
1 changed files with 12 additions and 0 deletions
12
main.py
12
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':
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue