Skip to content

Commit

Permalink
Merge branch 'Pre_NAK' into Jon_Branch
Browse files Browse the repository at this point in the history
  • Loading branch information
krkeegan committed Dec 13, 2020
2 parents b6c2c17 + 373c1ae commit 5f1274f
Show file tree
Hide file tree
Showing 7 changed files with 67 additions and 17 deletions.
14 changes: 11 additions & 3 deletions insteon_mqtt/handler/BroadcastCmdResponse.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,9 +82,17 @@ def msg_received(self, protocol, msg):
return Msg.CONTINUE

elif msg.flags.type == Msg.Flags.Type.DIRECT_NAK:
LOG.error("%s device NAK error: %s", msg.from_addr, msg)
self.on_done(False, "Device command NAK", None)
return Msg.FINISHED
if msg.cmd2 == 0xFC:
# This is a "Pre NAK in case database search takes
# too long". This happens when the device database is
# large. Just ignore it, add more wait time and wait.
LOG.warning("%s Pre-NAK: %s, Message: %s", msg.from_addr,
msg.nak_str(), msg)
return Msg.CONTINUE
else:
LOG.error("%s device NAK error: %s", msg.from_addr, msg)
self.on_done(False, "Device command NAK", None)
return Msg.FINISHED

else:
LOG.warning("%s device unexpected msg: %s", msg.from_addr, msg)
Expand Down
18 changes: 13 additions & 5 deletions insteon_mqtt/handler/DeviceDbGet.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,11 +103,19 @@ def msg_received(self, protocol, msg):
return Msg.CONTINUE

elif msg.flags.type == Msg.Flags.Type.DIRECT_NAK:
LOG.error("%s device NAK error: %s, Message: %s",
msg.from_addr, msg.nak_str(), msg)
self.on_done(False, "Database command NAK. " + msg.nak_str(),
None)
return Msg.FINISHED
if msg.cmd2 == 0xFC:
# This is a "Pre NAK in case database search takes
# too long". This happens when the device database is
# large. Just ignore it, add more wait time and wait.
LOG.warning("%s Pre-NAK: %s, Message: %s", msg.from_addr,
msg.nak_str(), msg)
return Msg.CONTINUE
else:
LOG.error("%s device NAK error: %s, Message: %s",
msg.from_addr, msg.nak_str(), msg)
self.on_done(False, "Database command NAK. " +
msg.nak_str(), None)
return Msg.FINISHED

else:
LOG.warning("%s device unexpected msg: %s", msg.from_addr, msg)
Expand Down
16 changes: 12 additions & 4 deletions insteon_mqtt/handler/DeviceDbModify.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,10 +78,18 @@ def msg_received(self, protocol, msg):
self.entry)

elif msg.flags.type == Msg.Flags.Type.DIRECT_NAK:
LOG.error("%s db mod NAK: %s, Message: %s", self.db.addr,
msg.nak_str(), msg)
self.on_done(False, "Device database update failed. " +
msg.nak_str(), None)
if msg.cmd2 == 0xFC:
# This is a "Pre NAK in case database search takes
# too long". This happens when the device database is
# large. Just ignore it, add more wait time and wait.
LOG.warning("%s Pre-NAK: %s, Message: %s",
self.db.addr, msg.nak_str(), msg)
return Msg.CONTINUE
else:
LOG.error("%s db mod NAK: %s, Message: %s",
self.db.addr, msg.nak_str(), msg)
self.on_done(False, "Device database update failed. " +
msg.nak_str(), None)

else:
LOG.error("%s db mod unexpected msg type: %s",
Expand Down
18 changes: 13 additions & 5 deletions insteon_mqtt/handler/ExtendedCmdResponse.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,11 +88,19 @@ def msg_received(self, protocol, msg):
return Msg.CONTINUE

elif msg.flags.type == Msg.Flags.Type.DIRECT_NAK:
LOG.error("%s device NAK error: %s, Message: %s",
msg.from_addr, msg.nak_str(), msg)
self.on_done(False, "Device command NAK. " + msg.nak_str(),
None)
return Msg.FINISHED
if msg.cmd2 == 0xFC:
# This is a "Pre NAK in case database search takes
# too long". This happens when the device database is
# large. Just ignore it, add more wait time and wait.
LOG.warning("%s Pre-NAK: %s, Message: %s", msg.from_addr,
msg.nak_str(), msg)
return Msg.CONTINUE
else:
LOG.error("%s device NAK error: %s, Message: %s",
msg.from_addr, msg.nak_str(), msg)
self.on_done(False, "Device command NAK. " + msg.nak_str(),
None)
return Msg.FINISHED

else:
LOG.warning("%s device unexpected msg: %s", msg.from_addr, msg)
Expand Down
6 changes: 6 additions & 0 deletions tests/handler/test_BroadcastCmdResponse.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,12 @@ def callback(msg, on_done=None):
r = handler.msg_received(proto, msg)
assert r == Msg.FINISHED

# direct Pre NAK
flags = Msg.Flags(Msg.Flags.Type.DIRECT_NAK, False)
msg = Msg.InpStandard(addr, addr, flags, 0x10, 0xFC)
r = handler.msg_received(proto, msg)
assert r == Msg.CONTINUE

# unexpected
flags = Msg.Flags(Msg.Flags.Type.ALL_LINK_BROADCAST, False)
msg = Msg.InpStandard(addr, addr, flags, 0x10, 0x00)
Expand Down
6 changes: 6 additions & 0 deletions tests/handler/test_DeviceDbGet.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,12 @@ def callback(success, msg, value):
r = handler.msg_received(proto, std_ack)
assert r == Msg.UNKNOWN

# direct Pre NAK
flags = Msg.Flags(Msg.Flags.Type.DIRECT_NAK, False)
msg = Msg.InpStandard(addr, addr, flags, 0x2f, 0xFC)
r = handler.msg_received(proto, msg)
assert r == Msg.CONTINUE

# Try w/ an extended msg.
ext_data = bytes(14)
ext_ack = Msg.OutExtended.direct(addr, 0x2f, 0x00, ext_data)
Expand Down
6 changes: 6 additions & 0 deletions tests/handler/test_ExtendedCmdResponse.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,12 @@ def callback(msg, on_done=None):
r = handler.msg_received(proto, msg)
assert r == Msg.FINISHED

# direct Pre NAK
flags = Msg.Flags(Msg.Flags.Type.DIRECT_NAK, False)
msg = Msg.InpStandard(addr, addr, flags, 0x2e, 0xFC)
r = handler.msg_received(proto, msg)
assert r == Msg.CONTINUE

# unexpected
flags = Msg.Flags(Msg.Flags.Type.BROADCAST, False)
msg = Msg.InpStandard(addr, addr, flags, 0x2e, 0x00)
Expand Down

0 comments on commit 5f1274f

Please sign in to comment.