Prechádzať zdrojové kódy

fix(device): check socket on hub when checking if subdevice disconnected

The actual socket used is the one on the hub, so subdevice sockets always appear
closed. Only make decisions based on the WiFi device's socket (hub or WiFi standalone device)

Issue #6265
Jason Rumney 1 deň pred
rodič
commit
42aca5255a
1 zmenil súbory, kde vykonal 4 pridanie a 2 odobranie
  1. 4 2
      custom_components/tuya_local/device.py

+ 4 - 2
custom_components/tuya_local/device.py

@@ -340,6 +340,7 @@ class TuyaLocalDevice(object):
             self._api.parent.set_socketPersistent(persist)
 
         last_heartbeat = self._cached_state.get("updated_at", 0)
+        wifi_api = self._api.parent or self._api
         while self._running:
             error_count = self._api_working_protocol_failures
             force_backoff = False
@@ -348,7 +349,7 @@ class TuyaLocalDevice(object):
                 now = time()
                 full_poll = False
                 if (persist == self.should_poll) or (
-                    persist and (self._api.socket is None)
+                    persist and (wifi_api.socket is None)
                 ):
                     # use persistent connections after initial communication
                     # has been established.  Until then, we need to rotate
@@ -460,7 +461,8 @@ class TuyaLocalDevice(object):
                     self._api.parent.set_socketPersistent(False)
                 force_backoff = True
 
-            if not self.has_returned_state or self._api.socket is None:
+            socket = self._api.parent.socket if self._api.parent else self._api.socket
+            if not self.has_returned_state or wifi_api.socket is None:
                 force_backoff = True
             await asyncio.sleep(5 if force_backoff else 0.1)