mirror of
https://gitlab.com/fabinfra/fabaccess/initiators/shelly-timeout.git
synced 2025-03-12 14:51:51 +01:00
Improve
This commit is contained in:
parent
505fc6e07f
commit
e9637bcce3
10
main.py
10
main.py
@ -18,11 +18,11 @@ def on_message(client, userdata, msg):
|
|||||||
print(topic, file=sys.stderr)
|
print(topic, file=sys.stderr)
|
||||||
print(payload, file=sys.stderr)
|
print(payload, file=sys.stderr)
|
||||||
|
|
||||||
if topic.endswith("/relay/0/command") and payload.decode("UTF-8") == "on":
|
if topic.endswith("/relay/0") and payload.decode("UTF-8") == "on":
|
||||||
if LAST_TIME == None:
|
if LAST_TIME == None:
|
||||||
LAST_TIME = datetime.datetime.now()
|
LAST_TIME = datetime.datetime.now()
|
||||||
print("UPDATE TIME", file=sys.stderr)
|
print("UPDATE TIME", file=sys.stderr)
|
||||||
if topic.endswith("/relay/0/command") and payload.decode("UTF-8") == "off":
|
if topic.endswith("/relay/0") and payload.decode("UTF-8") == "off":
|
||||||
LAST_TIME = None
|
LAST_TIME = None
|
||||||
print("RESET TIME", file=sys.stderr)
|
print("RESET TIME", file=sys.stderr)
|
||||||
|
|
||||||
@ -40,16 +40,14 @@ def on_message(client, userdata, msg):
|
|||||||
print("WAITING TIME", file=sys.stderr)
|
print("WAITING TIME", file=sys.stderr)
|
||||||
sys.stderr.flush()
|
sys.stderr.flush()
|
||||||
|
|
||||||
def ask_exit(*args):
|
|
||||||
STOP.set()
|
|
||||||
|
|
||||||
def main(host):
|
def main(host):
|
||||||
client = client = mqtt.Client(f"shelly_client_{SHELLY_ID}")
|
client = client = mqtt.Client(f"shelly_client_{SHELLY_ID}")
|
||||||
|
|
||||||
client.on_message = on_message
|
client.on_message = on_message
|
||||||
|
|
||||||
client.connect(host)
|
client.connect(host)
|
||||||
client.subscribe(f"shellies/{SHELLY_ID}/relay/0/#")
|
client.subscribe(f"shellies/{SHELLY_ID}/relay/0")
|
||||||
|
client.subscribe(f"shellies/{SHELLY_ID}/relay/0/power")
|
||||||
|
|
||||||
client.loop_forever()
|
client.loop_forever()
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user