summaryrefslogtreecommitdiff
path: root/src/esp_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/esp_mqtt_util.py
parent586d84b0c0a8b4dc1b5057733892b754397234ec (diff)
mqtt, esp: add new esp8266-based device
Diffstat (limited to 'src/esp_mqtt_util.py')
-rwxr-xr-xsrc/esp_mqtt_util.py42
1 files changed, 42 insertions, 0 deletions
diff --git a/src/esp_mqtt_util.py b/src/esp_mqtt_util.py
new file mode 100755
index 0000000..263128c
--- /dev/null
+++ b/src/esp_mqtt_util.py
@@ -0,0 +1,42 @@
+#!/usr/bin/env python3
+from typing import Optional
+from argparse import ArgumentParser
+from enum import Enum
+
+from home.config import config
+from home.mqtt import MqttRelay
+from home.mqtt.esp import MqttEspBase
+from home.mqtt.temphum import MqttTempHum
+from home.mqtt.esp import MqttEspDevice
+
+mqtt_client: Optional[MqttEspBase] = None
+
+
+class NodeType(Enum):
+ RELAY = 'relay'
+ TEMPHUM = 'temphum'
+
+
+if __name__ == '__main__':
+ parser = ArgumentParser()
+ parser.add_argument('--device-id', type=str, required=True)
+ parser.add_argument('--type', type=str, required=True,
+ choices=[i.name.lower() for i in NodeType])
+
+ config.load('mqtt_util', parser=parser)
+ arg = parser.parse_args()
+
+ mqtt_node_type = NodeType(arg.type)
+ devices = MqttEspDevice(id=arg.device_id)
+
+ if mqtt_node_type == NodeType.RELAY:
+ mqtt_client = MqttRelay(devices=devices)
+ elif mqtt_node_type == NodeType.TEMPHUM:
+ mqtt_client = MqttTempHum(devices=devices)
+
+ mqtt_client.set_message_callback(lambda device_id, payload: print(payload))
+ mqtt_client.configure_tls()
+ try:
+ mqtt_client.connect_and_loop()
+ except KeyboardInterrupt:
+ mqtt_client.disconnect()