summaryrefslogtreecommitdiff
path: root/src/relay_mqtt_util.py
diff options
context:
space:
mode:
authorEvgeny Zinoviev <me@ch1p.io>2023-05-11 04:18:08 +0300
committerEvgeny Zinoviev <me@ch1p.io>2023-05-11 04:18:12 +0300
commit0aba139aeff8ff80757c5d36502413299a0b449e (patch)
tree2b8e760ff14d4691783eb7c7d341f093199aab82 /src/relay_mqtt_util.py
parent586d84b0c0a8b4dc1b5057733892b754397234ec (diff)
mqtt, esp: add new esp8266-based device
Diffstat (limited to 'src/relay_mqtt_util.py')
-rwxr-xr-xsrc/relay_mqtt_util.py45
1 files changed, 0 insertions, 45 deletions
diff --git a/src/relay_mqtt_util.py b/src/relay_mqtt_util.py
deleted file mode 100755
index 45d2405..0000000
--- a/src/relay_mqtt_util.py
+++ /dev/null
@@ -1,45 +0,0 @@
-#!/usr/bin/env python3
-from typing import Optional
-from argparse import ArgumentParser
-
-from home.config import config
-from home.mqtt import MQTTRelay, MQTTRelayDevice
-from home.mqtt.payload import MQTTPayload
-from home.mqtt.payload.relay import (
- InitialStatPayload, StatPayload, OTAResultPayload
-)
-
-mqtt_relay: Optional[MQTTRelay] = None
-
-
-def on_mqtt_message(device_id, p: MQTTPayload):
- message = None
-
- if isinstance(p, InitialStatPayload) or isinstance(p, StatPayload):
- message = f'[stat] state={"on" if p.flags.state else "off"}'
- message += f' rssi={p.rssi}'
- message += f' free_heap={p.free_heap}'
- if isinstance(p, InitialStatPayload):
- message += f' fw={p.fw_version}'
-
- elif isinstance(p, OTAResultPayload):
- message = f'[otares] result={p.result} error_code={p.error_code}'
-
- if message:
- print(message)
-
-
-if __name__ == '__main__':
- parser = ArgumentParser()
- parser.add_argument('--device-id', type=str, required=True)
-
- config.load('relay_mqtt_util', parser=parser)
- arg = parser.parse_args()
-
- mqtt_relay = MQTTRelay(devices=MQTTRelayDevice(id=arg.device_id))
- mqtt_relay.set_message_callback(on_mqtt_message)
- mqtt_relay.configure_tls()
- try:
- mqtt_relay.connect_and_loop()
- except KeyboardInterrupt:
- mqtt_relay.disconnect()