summaryrefslogtreecommitdiff
path: root/src/relay_mqtt_util.py
diff options
context:
space:
mode:
Diffstat (limited to 'src/relay_mqtt_util.py')
-rwxr-xr-xsrc/relay_mqtt_util.py23
1 files changed, 17 insertions, 6 deletions
diff --git a/src/relay_mqtt_util.py b/src/relay_mqtt_util.py
index 430af2c..29a0532 100755
--- a/src/relay_mqtt_util.py
+++ b/src/relay_mqtt_util.py
@@ -5,16 +5,27 @@ 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
+from home.mqtt.payload.relay import (
+ InitialStatPayload, StatPayload, OTAResultPayload
+)
mqtt_relay: Optional[MQTTRelay] = None
-def on_mqtt_message(device_id, message: MQTTPayload):
- if isinstance(message, InitialStatPayload) or isinstance(message, StatPayload):
- message = f'[{device_id}] state={message.flags.state} rssi={message.rssi}'
- if isinstance(message, InitialStatPayload):
- message += f' fw={message.fw_version}'
+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)