diff --git a/insteon_mqtt/handler/Broadcast.py b/insteon_mqtt/handler/Broadcast.py index 67b87546..422fd3c1 100644 --- a/insteon_mqtt/handler/Broadcast.py +++ b/insteon_mqtt/handler/Broadcast.py @@ -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 #----------------------------------------------------------------------- @@ -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 diff --git a/tests/handler/test_Broadcast.py b/tests/handler/test_Broadcast.py index 67e571cc..61b89f82 100644 --- a/tests/handler/test_Broadcast.py +++ b/tests/handler/test_Broadcast.py @@ -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) @@ -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 + #----------------------------------------------------------------------- #===========================================================================