Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Don't treat different broadcast msgs from same device as duplicate #256

Merged
merged 3 commits into from
Dec 18, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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