Răsfoiți Sursa

fix(device): ensure receive loop knows when the socket has been closed

Due to close() not being part of the tinytuya official API, and prior to 1.17.0
it's behaviour was not what we want, we instead use set_socketPersist(False) for
its side effect of closing the socket. But when we do that outside of the main
receive loop, it gets out of sync with the local persist variable, leading to
incorrect behaviour.

Use self._temporary_poll to resync the receive loop with the actual persistence
state when closing the socket outside of the main receive loop (making sure non-working
connections were closed was one of the early attempts to fix issue #4949 in 2026.4.0
but ended up prolonging the issue after other causes were fixed).

Issue #6054, #5736, #5347.
Jason Rumney 13 ore în urmă
părinte
comite
b121da2331
1 a modificat fișierele cu 4 adăugiri și 0 ștergeri
  1. 4 0
      custom_components/tuya_local/device.py

+ 4 - 0
custom_components/tuya_local/device.py

@@ -227,6 +227,7 @@ class TuyaLocalDevice(object):
         self._children.clear()
         self._force_dps.clear()
         if self._refresh_task:
+            self._temporary_poll = True
             self._api.set_socketPersistent(False)
             if self._api.parent:
                 self._api.parent.set_socketPersistent(False)
@@ -309,6 +310,7 @@ class TuyaLocalDevice(object):
         finally:
             # Ensure the persistent connection is closed when the loop exits
             # and device appears as unavailable
+            self._temporary_poll = True
             self._api.set_socketPersistent(False)
             if self._api.parent:
                 self._api.parent.set_socketPersistent(False)
@@ -468,6 +470,7 @@ class TuyaLocalDevice(object):
             await asyncio.sleep(5 if force_backoff else 0.1)
 
         # Close the persistent connection when exiting the loop
+        self._temporary_poll = True
         self._api.set_socketPersistent(False)
         if self._api.parent:
             self._api.parent.set_socketPersistent(False)
@@ -719,6 +722,7 @@ class TuyaLocalDevice(object):
                     connections,
                 )
                 # Ensure we have a fresh connection for the next attempt
+                self._temporary_poll = True
                 self._api.set_socketPersistent(False)
                 if self._api.parent:
                     self._api.parent.set_socketPersistent(False)