mirror of
https://gitlab.com/fabinfra/fabaccess/initiators/shelly-timeout.git
synced 2025-03-12 14:51:51 +01:00
Changed MQTT Lib
This commit is contained in:
parent
a2a2c1f16d
commit
5a176fbd91
29
main.py
29
main.py
@ -1,9 +1,7 @@
|
||||
import asyncio
|
||||
import signal
|
||||
import datetime
|
||||
import sys
|
||||
|
||||
from gmqtt import Client as MQTTClient
|
||||
import paho.mqtt.client as mqtt
|
||||
|
||||
SHELLY_ID = ""
|
||||
POWER_THRESHOLD = 0
|
||||
@ -11,11 +9,12 @@ TIME_THRESHOLD = 15 * 60
|
||||
|
||||
LAST_TIME = None
|
||||
|
||||
STOP = asyncio.Event()
|
||||
|
||||
def on_message(client, topic, payload, qos, properties):
|
||||
def on_message(client, userdata, msg):
|
||||
global LAST_TIME
|
||||
|
||||
topic = msg.topic
|
||||
payload = msg.payload
|
||||
|
||||
print(topic)
|
||||
print(payload)
|
||||
|
||||
@ -42,26 +41,20 @@ def on_message(client, topic, payload, qos, properties):
|
||||
def ask_exit(*args):
|
||||
STOP.set()
|
||||
|
||||
async def main(host):
|
||||
client = MQTTClient("shelly_client")
|
||||
def main(host):
|
||||
client = client = mqtt.Client("shelly_client")
|
||||
|
||||
client.on_message = on_message
|
||||
|
||||
await client.connect(host)
|
||||
client.connect(host)
|
||||
client.subscribe(f"shellies/{SHELLY_ID}/relay/0")
|
||||
client.subscribe(f"shellies/{SHELLY_ID}/relay/0/energy")
|
||||
client.subscribe(f"shellies/{SHELLY_ID}/relay/0/power")
|
||||
|
||||
await STOP.wait()
|
||||
await client.disconnect()
|
||||
client.loop_forever()
|
||||
|
||||
if __name__ == '__main__':
|
||||
loop = asyncio.get_event_loop()
|
||||
|
||||
host = sys.argv[1]
|
||||
SHELLY_ID = sys.argv[2]
|
||||
POWER_THRESHOLD = int(sys.argv[3])
|
||||
|
||||
loop.add_signal_handler(signal.SIGINT, ask_exit)
|
||||
loop.add_signal_handler(signal.SIGTERM, ask_exit)
|
||||
|
||||
loop.run_until_complete(main(host))
|
||||
main(host)
|
||||
|
@ -1 +1 @@
|
||||
gmqtt
|
||||
paho-mqtt
|
Loading…
x
Reference in New Issue
Block a user