Explorar o código

Device: improve error detection in refresh_cached_state.

Since the code now considers empty polls to be valid, we need to
detect errors by other means.

1) Don't update updated_at timestamp when there is an error.
   - this allows the first data when connecting a new device to be
     detected as an error when it doesn't work.
2) Return the status result from refresh_cached_state.
   - this allows the retry mechanism work, and anything else that
     checks for error attributes in the response.

Issue #2922
Jason Rumney hai 1 ano
pai
achega
d6b5ac0633
Modificáronse 1 ficheiros con 2 adicións e 1 borrados
  1. 2 1
      custom_components/tuya_local/device.py

+ 2 - 1
custom_components/tuya_local/device.py

@@ -472,7 +472,7 @@ class TuyaLocalDevice(object):
 
     def _refresh_cached_state(self):
         new_state = self._api.status()
-        if new_state:
+        if new_state and "Err" not in new_state:
             self._cached_state = self._cached_state | new_state.get("dps", {})
             self._cached_state["updated_at"] = time()
             for entity in self._children:
@@ -505,6 +505,7 @@ class TuyaLocalDevice(object):
             "new state (incl pending): %s",
             log_json(self._get_cached_state()),
         )
+        return new_state
 
     async def async_set_properties(self, properties):
         if len(properties) == 0: