Browse Source

fix(device): ensure we restart with a full poll after errors

When we get an error, we need to ensure we restart communication with a full poll.

Starting a new connection and just listening passively until the heartbeat timeout
causes some devices to build up errors internally until they stop responding.

Possible fix for the following issues:

Issue #4965, #4961, #4949, #4594, #3896
Jason Rumney 1 month ago
parent
commit
c0eba8a2a0
1 changed files with 3 additions and 0 deletions
  1. 3 0
      custom_components/tuya_local/device.py

+ 3 - 0
custom_components/tuya_local/device.py

@@ -334,6 +334,7 @@ class TuyaLocalDevice(object):
                     self._api.set_socketPersistent(persist)
                     if self._api.parent:
                         self._api.parent.set_socketPersistent(persist)
+                    self._last_full_poll = 0  # ensure we start with a full poll
 
                 needs_full_poll = now - self._last_full_poll > self._CACHE_TIMEOUT
                 if now - last_cache > self._CACHE_TIMEOUT or (
@@ -404,6 +405,7 @@ class TuyaLocalDevice(object):
             except CancelledError:
                 self._running = False
                 # Close the persistent connection when exiting the loop
+                persist = False
                 self._api.set_socketPersistent(False)
                 if self._api.parent:
                     self._api.parent.set_socketPersistent(False)
@@ -415,6 +417,7 @@ class TuyaLocalDevice(object):
                     type(t).__name__,
                     t,
                 )
+                persist = False
                 self._api.set_socketPersistent(False)
                 if self._api.parent:
                     self._api.parent.set_socketPersistent(False)