Просмотр исходного кода

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 1 день назад
Родитель
Сommit
0d4416069c
1 измененных файлов с 4 добавлено и 0 удалено
  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(
                 "%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)
             if self._api.parent:
                 self._api.parent.set_socketPersistent(False)
+            self._reset_cached_state()
 
     @property
     def should_poll(self):