Explorar el Código

fix(device): ensure device appears offline if receive loop terminates

There appear to be unknown error conditions that are ending the receive loop on some
(3.4) devices. While this does not help track these down, we can at least ensure that
the connection to the device is properly closed to prevent issues trying to reconnect
it later, and that the device appears as unavailable rather than remaining as a zombie
showing stale state.

Issue #5848
Jason Rumney hace 1 día
padre
commit
0d4416069c
Se han modificado 1 ficheros con 4 adiciones y 0 borrados
  1. 4 0
      custom_components/tuya_local/device.py

+ 4 - 0
custom_components/tuya_local/device.py

@@ -306,9 +306,13 @@ class TuyaLocalDevice(object):
             _LOGGER.exception(
             _LOGGER.exception(
                 "%s receive loop terminated by exception %s", self.name, t
                 "%s receive loop terminated by exception %s", self.name, t
             )
             )
+        finally:
+            # Ensure the persistent connection is closed when the loop exits
+            # and device appears as unavailable
             self._api.set_socketPersistent(False)
             self._api.set_socketPersistent(False)
             if self._api.parent:
             if self._api.parent:
                 self._api.parent.set_socketPersistent(False)
                 self._api.parent.set_socketPersistent(False)
+            self._reset_cached_state()
 
 
     @property
     @property
     def should_poll(self):
     def should_poll(self):