Skip to content

Commit

Permalink
Merge pull request #256 from tstabrawa/cleanup-fix
Browse files Browse the repository at this point in the history
Don't treat different broadcast msgs from same device as duplicate
  • Loading branch information
krkeegan authored Dec 18, 2020
2 parents 0ddef77 + 56285da commit 5c083fa
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 5 deletions.
10 changes: 6 additions & 4 deletions insteon_mqtt/handler/Broadcast.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ def msg_received(self, protocol, msg):
self._last_broadcast = None
return Msg.CONTINUE

# Different message flags than we exepcted.
# Different message flags than we expected.
return Msg.UNKNOWN

#-----------------------------------------------------------------------
Expand Down Expand Up @@ -125,9 +125,11 @@ def _should_process(self, msg):
if not self._last_broadcast:
return True

# If we just got a broadcast from the same device, don't process the
# cleanup.
if self._last_broadcast.from_addr == msg.from_addr:
# Don't process the cleanup if we just got the corresponding broadcast
# message from the same device.
if (self._last_broadcast.from_addr == msg.from_addr and
self._last_broadcast.group == msg.group and
self._last_broadcast.cmd1 == msg.cmd1):
return False

return True
22 changes: 21 additions & 1 deletion tests/handler/test_Broadcast.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,14 @@ def test_acks(self, tmpdir):
modem.save_path = str(tmpdir)

addr = IM.Address('0a.12.34')
broadcast_to_addr = IM.Address('00.00.01')
handler = IM.handler.Broadcast(modem)

r = handler.msg_received(proto, "dummy")
assert r == Msg.UNKNOWN

flags = Msg.Flags(Msg.Flags.Type.ALL_LINK_BROADCAST, False)
msg = Msg.InpStandard(addr, addr, flags, 0x11, 0x01)
msg = Msg.InpStandard(addr, broadcast_to_addr, flags, 0x11, 0x01)

# no device
r = handler.msg_received(proto, msg)
Expand Down Expand Up @@ -56,6 +57,25 @@ def test_acks(self, tmpdir):
r = handler.msg_received(proto, msg)
assert r == Msg.UNKNOWN

# Success Report Broadcast
flags = Msg.Flags(Msg.Flags.Type.ALL_LINK_BROADCAST, False)
success_report_to_addr = IM.Address(0x11, 1, 0x1)
msg = Msg.InpStandard(addr, addr, flags, 0x06, 0x00)
r = handler.msg_received(proto, msg)

assert r == Msg.CONTINUE
assert len(calls) == 3

# Pretend that a new broadcast message dropped / not received by PLM

# Cleanup should be handled since corresponding broadcast was missed
flags = Msg.Flags(Msg.Flags.Type.ALL_LINK_CLEANUP, False)
msg = Msg.InpStandard(addr, addr, flags, 0x13, 0x01)
r = handler.msg_received(proto, msg)

assert r == Msg.CONTINUE
assert len(calls) == 4

#-----------------------------------------------------------------------

#===========================================================================
Expand Down

0 comments on commit 5c083fa

Please sign in to comment.