|
|
@@ -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,
|