Code: Select all
try:
while 1:
c.check_msg()
if door_has_opened(): # Detect change of state
c.publish(b"door", b"open")
if door_has_closed():
c.publish(b"door", b"closed")
time.sleep(0.2) # Avoid 100% CPU usage
finally:
c.disconnect()