From 77c6f699a0170d4064d41284f670f69489376cdf Mon Sep 17 00:00:00 2001 From: Fabio Manganiello Date: Sat, 13 Feb 2021 15:54:21 +0100 Subject: [PATCH] Keep track of the last state of the Zigbee controller so that new messages on the `bridge/state` topic won't trigger new events unless the state has actually changed [see #183] --- platypush/backend/zigbee/mqtt.py | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/platypush/backend/zigbee/mqtt.py b/platypush/backend/zigbee/mqtt.py index 2637bb759c..9b58c0b4ed 100644 --- a/platypush/backend/zigbee/mqtt.py +++ b/platypush/backend/zigbee/mqtt.py @@ -86,6 +86,7 @@ class ZigbeeMqttBackend(MqttBackend): self.base_topic = base_topic or plugin.base_topic self._devices = {} self._groups = {} + self._last_state = None self.server_info = { 'host': host or plugin.host, 'port': port or plugin.port or self._default_mqtt_port, @@ -109,6 +110,9 @@ class ZigbeeMqttBackend(MqttBackend): super().__init__(subscribe_default_topic=False, listeners=listeners, *args, **kwargs) def _process_state_message(self, client, msg): + if msg == self._last_state: + return + if msg == 'online': evt = ZigbeeMqttOnlineEvent elif msg == 'offline': @@ -119,6 +123,7 @@ class ZigbeeMqttBackend(MqttBackend): # noinspection PyProtectedMember self.bus.post(evt(host=client._host, port=client._port)) + self._last_state = msg def _process_log_message(self, client, msg): msg_type = msg.get('type')