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]

This commit is contained in:
Fabio Manganiello 2021-02-13 15:54:21 +01:00
parent 4c69a1e579
commit add1bd05cb
1 changed files with 5 additions and 0 deletions

View File

@ -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')