Skip to content

Commit

Permalink
Message SeqNo=0 Fix #505
Browse files Browse the repository at this point in the history
  • Loading branch information
jasonacox committed Jun 11, 2024
1 parent a75324b commit 2c3600b
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 20 deletions.
4 changes: 4 additions & 0 deletions RELEASE.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# RELEASE NOTES

## v1.14.1 - SeqNo 0 Fix

* Ignore SeqNo=0 messages and wait for SeqNo=1. Accepting the first message will often not include all the DPS values. This was raised by @leweafan in https://github.com/jasonacox/tinytuya/issues/505

## v1.14.0 - Command Line Updates

* PyPI 1.14.0 rewrite of main to use argparse and add additional options by @uzlonewolf in https://github.com/jasonacox/tinytuya/pull/503
Expand Down
46 changes: 26 additions & 20 deletions tinytuya/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@
# Colorama terminal color capability for all platforms
init()

version_tuple = (1, 14, 0)
version_tuple = (1, 14, 1)
version = __version__ = "%d.%d.%d" % version_tuple
__author__ = "jasonacox"

Expand Down Expand Up @@ -1189,27 +1189,33 @@ def _send_receive(self, payload, minresponse=28, getresponse=True, decode_respon
self.socket.sendall(enc_payload)
if self.sendWait is not None:
time.sleep(self.sendWait) # give device time to respond
if getresponse:
do_send = False
rmsg = self._receive()
# device may send null ack (28 byte) response before a full response
# consider it an ACK and do not retry the send even if we do not get a full response
if rmsg:
payload = None
partial_success = True
msg = rmsg
if (not msg or len(msg.payload) == 0) and recv_retries <= max_recv_retries:
log.debug("received null payload (%r), fetch new one - retry %s / %s", msg, recv_retries, max_recv_retries)
recv_retries += 1
if recv_retries > max_recv_retries:
while not success:
if getresponse:
do_send = False
rmsg = self._receive()
# device may send null ack (28 byte) response before a full response
# consider it an ACK and do not retry the send even if we do not get a full response
if rmsg:
payload = None
partial_success = True
msg = rmsg
if (not msg or len(msg.payload) == 0) and recv_retries <= max_recv_retries:
log.debug("received null payload (%r), fetch new one - retry %s / %s", msg, recv_retries, max_recv_retries)
recv_retries += 1
if recv_retries > max_recv_retries:
success = True
else:
success = True
log.debug("received message=%r", msg)
if msg.seqno == 0:
log.debug("Received message with seqno=0, ignoring")
success = False
else:
success = True
else:
success = True
log.debug("received message=%r", msg)
else:
# legacy/default mode avoids persisting socket across commands
self._check_socket_close()
return None
# legacy/default mode avoids persisting socket across commands
self._check_socket_close()
return None
except (KeyboardInterrupt, SystemExit) as err:
log.debug("Keyboard Interrupt - Exiting")
raise
Expand Down

0 comments on commit 2c3600b

Please sign in to comment.