فهرست منبع

Alternate calling of status and updatedps.

When dps are set to force, alternate calls to status and updatedps to ensure
that all dps get fresh data, especially after they have been offline and missed
state changes.

Reduce CACHE_TIMEOUT from 2 minutes to 30s to ensure each dps is updated at
least once a minute.

Issue #420
Jason Rumney 3 سال پیش
والد
کامیت
9f2fcdc3cc
1فایلهای تغییر یافته به همراه8 افزوده شده و 2 حذف شده
  1. 8 2
      custom_components/tuya_local/device.py

+ 8 - 2
custom_components/tuya_local/device.py

@@ -86,7 +86,7 @@ class TuyaLocalDevice(object):
         # we can overlay onto the state while we wait for the board to update
         # its switches.
         self._FAKE_IT_TIMEOUT = 5
-        self._CACHE_TIMEOUT = 120
+        self._CACHE_TIMEOUT = 30
         # More attempts are needed in auto mode so we can cycle through all
         # the possibilities a couple of times
         self._AUTO_CONNECTION_ATTEMPTS = len(API_PROTOCOL_VERSIONS) * 2 + 1
@@ -206,6 +206,10 @@ class TuyaLocalDevice(object):
         # If we didn't yet get any state from the device, we may need to
         # negotiate the protocol before making the connection persistent
         persist = not self.should_poll
+        # flag to alternate updatedps and status calls to ensure we get
+        # all dps updated
+        dps_updated = False
+
         self._api.set_socketPersistent(persist)
         while self._running:
             try:
@@ -220,16 +224,18 @@ class TuyaLocalDevice(object):
                     self._api.set_socketPersistent(persist)
 
                 if now - last_cache > self._CACHE_TIMEOUT:
-                    if self._force_dps:
+                    if self._force_dps and not dps_updated:
                         poll = await self._retry_on_failed_connection(
                             lambda: self._api.updatedps(self._force_dps),
                             f"Failed to refresh device state for {self.name}",
                         )
+                        dps_updated = True
                     else:
                         poll = await self._retry_on_failed_connection(
                             lambda: self._api.status(),
                             f"Failed to refresh device state for {self.name}",
                         )
+                        dps_updated = False
                 else:
                     await self._hass.async_add_executor_job(
                         self._api.heartbeat,