Skip to content

Commit

Permalink
Fix issue #210 - change remote to never retain messages.
Browse files Browse the repository at this point in the history
  • Loading branch information
TD22057 committed Aug 15, 2020
1 parent b80b9d1 commit 774f348
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 7 deletions.
4 changes: 4 additions & 0 deletions HISTORY.md
Original file line number Diff line number Diff line change
Expand Up @@ -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]

Expand Down Expand Up @@ -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
10 changes: 7 additions & 3 deletions insteon_mqtt/mqtt/Remote.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
8 changes: 4 additions & 4 deletions tests/mqtt/test_Remote.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 774f348

Please sign in to comment.