Przeglądaj źródła

fix(device): add fake protocols 3.42 and 3.52 to deal with device22

Some protocol 3.4 and 3.5 devices appear to require "device22" command set
to be used or they won't return any data. But enabling detection of "device22"
also causes devices to stop working if it misdetects that it needs to use that,
which is the reason why we have the fake 3.22 protocol version. In 2026.7.2,
we enabled device22 detection for 3.4 and 3.5 devices to cater to such devices,
on the assumption that the newer protocols would be robust enough to not have
issues with the "device22" commands being used even when not needed.

But that turns out not to be the case, so to avoid issues with normal devices
that momentarily lose connection, follow the same path as 3.3 and require
explicit enabling of "device22" through the fake protocol versions 3.42 and 3.52.

Issue #5697
Jason Rumney 11 godzin temu
rodzic
commit
7f4d77b5be
1 zmienionych plików z 19 dodań i 5 usunięć
  1. 19 5
      custom_components/tuya_local/device.py

+ 19 - 5
custom_components/tuya_local/device.py

@@ -658,13 +658,18 @@ class TuyaLocalDevice(object):
     async def _retry_on_failed_connection(self, func, error_message):
     async def _retry_on_failed_connection(self, func, error_message):
         if self._api_protocol_version_index is None:
         if self._api_protocol_version_index is None:
             await self._rotate_api_protocol_version()
             await self._rotate_api_protocol_version()
-        auto = (self._protocol_configured in ["auto", 3.22]) and (
+        auto = (self._protocol_configured == "auto") and (
             not self._api_protocol_working
             not self._api_protocol_working
         )
         )
+        dev22 = self._protocol_configured in (3.22, 3.42, 3.52)
         connections = (
         connections = (
             self._AUTO_CONNECTION_ATTEMPTS
             self._AUTO_CONNECTION_ATTEMPTS
             if auto
             if auto
-            else self._SINGLE_PROTO_CONNECTION_ATTEMPTS
+            else (
+                self._SINGLE_PROTO_CONNECTION_ATTEMPTS * 2
+                if dev22
+                else self._SINGLE_PROTO_CONNECTION_ATTEMPTS
+            )
         )
         )
 
 
         last_err_code = None
         last_err_code = None
@@ -783,18 +788,27 @@ class TuyaLocalDevice(object):
             self.name,
             self.name,
             new_version,
             new_version,
         )
         )
-        # Only enable tinytuya's "device22" auto-detect when using 3.22, 3.4, or 3.5
-        # Enabling this on 3.1 or 3.3 devices can cause them to stop responding to commands.
+        # Only enable tinytuya's "device22" auto-detect when exlpicitly requested
+        # as 3.22, 3.42, or 3.52
+        # Enabling this on other devices can cause them to stop responding to commands,
+        # as once tinytuya decides to switch to it, it never switches back.
         # 3.2 always uses the "device22" protocol variant.
         # 3.2 always uses the "device22" protocol variant.
         # 3.22 is a fake version that actually means 3.3 with auto-detect enabled
         # 3.22 is a fake version that actually means 3.3 with auto-detect enabled
+        # likewise 3.42 and 3.52 actually mean 3.4 and 3.5 with auto-detect enabled.
         #
         #
         # Note: "device22" is a misnomer for historical reasons. Not all devices with
         # Note: "device22" is a misnomer for historical reasons. Not all devices with
         # 22 character device ids use this protocol variant.
         # 22 character device ids use this protocol variant.
         if new_version == 3.22:
         if new_version == 3.22:
             new_version = 3.3
             new_version = 3.3
             self._api.disabledetect = False
             self._api.disabledetect = False
+        elif new_version == 3.42:
+            new_version = 3.4
+            self._api.disabledetect = False
+        elif new_version == 3.52:
+            new_version = 3.5
+            self._api.disabledetect = False
         else:
         else:
-            self._api.disabledetect = new_version < 3.4
+            self._api.disabledetect = True
 
 
         await self._hass.async_add_executor_job(
         await self._hass.async_add_executor_job(
             self._api.set_version,
             self._api.set_version,