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

device: close connection on any exception when receiving.

This should hopefully help to avoid hung sockets in cases where the device
disappears off the network, and speed up reconnection.
Issue #1804, #1013
Jason Rumney 1 год назад
Родитель
Сommit
c07269e710
1 измененных файлов с 6 добавлено и 0 удалено
  1. 6 0
      custom_components/tuya_local/device.py

+ 6 - 0
custom_components/tuya_local/device.py

@@ -247,6 +247,9 @@ class TuyaLocalDevice(object):
             _LOGGER.exception(
                 "%s receive loop terminated by exception %s", self.name, t
             )
+            self._api.set_socketPersistent(False)
+            if self._api.parent:
+                self._api.parent.set_socketPersistent(False)
 
     @property
     def should_poll(self):
@@ -355,6 +358,9 @@ class TuyaLocalDevice(object):
                     type(t),
                     t,
                 )
+                self._api.set_socketPersistent(False)
+                if self._api.parent:
+                    self._api.parent.set_socketPersistent(False)
                 await asyncio.sleep(5)
 
         # Close the persistent connection when exiting the loop