summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEvgeny Zinoviev <me@ch1p.io>2023-05-31 23:47:01 +0300
committerEvgeny Zinoviev <me@ch1p.io>2023-05-31 23:47:01 +0300
commitbc98775dd7a3417f24ad1369a8e1a60994d131cc (patch)
tree6b9e75813989ec1c1256173bfe2f71cef50a1edb
parent081cd0d4bb4625c75b356ab8474364d922cbc991 (diff)
upd
-rw-r--r--platformio/common/libs/mqtt_module_relay/homekit/mqtt/module/relay.h5
-rw-r--r--platformio/common/libs/mqtt_module_relay/library.json2
-rw-r--r--src/home/mqtt/module/relay.py14
3 files changed, 15 insertions, 6 deletions
diff --git a/platformio/common/libs/mqtt_module_relay/homekit/mqtt/module/relay.h b/platformio/common/libs/mqtt_module_relay/homekit/mqtt/module/relay.h
index 6420de1..1e80987 100644
--- a/platformio/common/libs/mqtt_module_relay/homekit/mqtt/module/relay.h
+++ b/platformio/common/libs/mqtt_module_relay/homekit/mqtt/module/relay.h
@@ -10,6 +10,10 @@ struct MqttRelaySwitchPayload {
uint8_t state;
} __attribute__((packed));
+struct MqttRelayStatusPayload {
+ uint8_t opened;
+} __attribute__((packed));
+
class MqttRelayModule : public MqttModule {
public:
MqttRelayModule() : MqttModule(0) {}
@@ -21,3 +25,4 @@ public:
}
#endif //HOMEKIT_LIB_MQTT_MODULE_RELAY_H
+
diff --git a/platformio/common/libs/mqtt_module_relay/library.json b/platformio/common/libs/mqtt_module_relay/library.json
index e71cf95..431bb49 100644
--- a/platformio/common/libs/mqtt_module_relay/library.json
+++ b/platformio/common/libs/mqtt_module_relay/library.json
@@ -1,6 +1,6 @@
{
"name": "homekit_mqtt_module_relay",
- "version": "1.0.3",
+ "version": "1.0.4",
"build": {
"flags": "-I../../include"
},
diff --git a/src/home/mqtt/module/relay.py b/src/home/mqtt/module/relay.py
index 721ceac..bf22bfe 100644
--- a/src/home/mqtt/module/relay.py
+++ b/src/home/mqtt/module/relay.py
@@ -60,6 +60,7 @@ class MqttRelayState:
class MqttRelayModule(MqttModule):
def init(self, mqtt: MqttNode):
mqtt.subscribe_module('relay/switch', self)
+ mqtt.subscribe_module('relay/status', self)
@staticmethod
def switchpower(mqtt: MqttNode,
@@ -69,10 +70,13 @@ class MqttRelayModule(MqttModule):
mqtt.publish('relay/switch', payload=payload.pack())
def handle_payload(self, mqtt: MqttNode, topic: str, payload: bytes) -> Optional[MqttPayload]:
- if topic != 'relay/switch':
- return
+ message = None
- message = MqttPowerSwitchPayload.unpack(payload)
- self._logger.debug(message)
+ if topic == 'relay/switch':
+ message = MqttPowerSwitchPayload.unpack(payload)
+ elif topic == 'relay/status':
+ message = MqttPowerStatusPayload.unpack(payload)
- return message \ No newline at end of file
+ if message is not None:
+ self._logger.debug(message)
+ return message