diff --git a/HISTORY.md b/HISTORY.md index 929fd073..4580fe35 100644 --- a/HISTORY.md +++ b/HISTORY.md @@ -12,6 +12,9 @@ - Fixed a bug in the modem database class when removing an entry (thanks @krkeegan) ([PR#196][P196]) +- Changed the MQTT remote to never mark messages for retain so the broker + doesn't get out of sync with the device. ([Issue #I210][I210]) + ## [0.7.2] @@ -378,4 +381,5 @@ [I193]: https://github.com/TD22057/insteon-mqtt/issues/193 [I195]: https://github.com/TD22057/insteon-mqtt/issues/195 [P196]: https://github.com/TD22057/insteon-mqtt/pull/196 +[I210]: https://github.com/TD22057/insteon-mqtt/issues/210 [P220]: https://github.com/TD22057/insteon-mqtt/pull/220 diff --git a/insteon_mqtt/mqtt/Remote.py b/insteon_mqtt/mqtt/Remote.py index 92b5499f..1e5e7076 100644 --- a/insteon_mqtt/mqtt/Remote.py +++ b/insteon_mqtt/mqtt/Remote.py @@ -136,9 +136,13 @@ def _insteon_pressed(self, device, button, is_on, mode=on_off.Mode.NORMAL): LOG.info("MQTT received button press %s = btn %s on %s %s", device.label, button, is_on, mode) - # For manual mode messages, don't retain them because they don't - # represent persistent state - they're momentary events. - retain = False if mode == on_off.Mode.MANUAL else None + # For the remote control, there is no way to know it's state on start + # up so we don't want to retain those messages. If we did, then a + # remote that got out of sync (because of the device changing state + # and the remote not knowing about it) would cause problems when HA + # is restarted because the remotes retain message would still be in + # the broker. + retain = False data = self.template_data(button, is_on, mode) self.msg_state.publish(self.mqtt, data, retain=retain) diff --git a/tests/mqtt/test_Remote.py b/tests/mqtt/test_Remote.py index df10029b..86b1a1cd 100644 --- a/tests/mqtt/test_Remote.py +++ b/tests/mqtt/test_Remote.py @@ -91,9 +91,9 @@ def test_mqtt(self, setup): dev.signal_pressed.emit(dev, 4, False) assert len(link.client.pub) == 2 assert link.client.pub[0] == dict( - topic='%s/state/2' % topic, payload='on', qos=0, retain=True) + topic='%s/state/2' % topic, payload='on', qos=0, retain=False) assert link.client.pub[1] == dict( - topic='%s/state/4' % topic, payload='off', qos=0, retain=True) + topic='%s/state/4' % topic, payload='off', qos=0, retain=False) link.client.clear() # Send a manual mode signal - should do nothing w/ the default config. @@ -121,9 +121,9 @@ def test_config(self, setup): dev.signal_pressed.emit(dev, 4, False) assert len(link.client.pub) == 2 assert link.client.pub[0] == dict( - topic="%s/2" % stopic, payload='1 ON', qos=qos, retain=True) + topic="%s/2" % stopic, payload='1 ON', qos=qos, retain=False) assert link.client.pub[1] == dict( - topic="%s/4" % stopic, payload='0 OFF', qos=qos, retain=True) + topic="%s/4" % stopic, payload='0 OFF', qos=qos, retain=False) link.client.clear() # Send a manual signal