diff options
-rw-r--r-- | platformio/common/libs/mqtt_module_relay/homekit/mqtt/module/relay.h | 5 | ||||
-rw-r--r-- | platformio/common/libs/mqtt_module_relay/library.json | 2 | ||||
-rw-r--r-- | src/home/mqtt/module/relay.py | 14 |
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 |