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()
|
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':
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue