From ecf66f76e624aa5888b34862b385f15688748ac5 Mon Sep 17 00:00:00 2001 From: rospogrigio Date: Mon, 9 Jan 2023 01:49:51 +0100 Subject: [PATCH] Fixed sequence numbering on status update --- custom_components/localtuya/pytuya/__init__.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/custom_components/localtuya/pytuya/__init__.py b/custom_components/localtuya/pytuya/__init__.py index 3f24d50..259ed57 100644 --- a/custom_components/localtuya/pytuya/__init__.py +++ b/custom_components/localtuya/pytuya/__init__.py @@ -562,7 +562,7 @@ class TuyaProtocol(asyncio.Protocol, ContextualLogger): def _setup_dispatcher(self): def _status_update(msg): - if self.seqno > 0: + if msg.seqno > 0: self.seqno = msg.seqno + 1 decoded_message = self._decode_payload(msg.payload) if "dps" in decoded_message: @@ -707,9 +707,9 @@ class TuyaProtocol(asyncio.Protocol, ContextualLogger): return None # TODO: Verify stuff, e.g. CRC sequence number? - if real_cmd in [HEART_BEAT, CONTROL_NEW] and len(msg.payload) == 0: - # device may send one or two messages with empty payload in response - # to a CONTROL_NEW command, consider it an ACK + if real_cmd in [HEART_BEAT, CONTROL, CONTROL_NEW] and len(msg.payload) == 0: + # device may send messages with empty payload in response + # to a HEART_BEAT or CONTROL or CONTROL_NEW command: consider them an ACK self.debug("ACK received for command %d: ignoring it", real_cmd) return None payload = self._decode_payload(msg.payload)