Explorar el Código

Protect against missing "updated_at" in cached_state.

I think this only happens in tests, and it is not clear to me why it has
suddenly become a problem now, but checking is better in case the cache is
completely cleared in actual use.
Jason Rumney hace 5 años
padre
commit
3afe9cc081
Se han modificado 1 ficheros con 6 adiciones y 1 borrados
  1. 6 1
      custom_components/tuya_local/device.py

+ 6 - 1
custom_components/tuya_local/device.py

@@ -108,7 +108,12 @@ class TuyaLocalDevice(object):
         return best_match.legacy_type
 
     async def async_refresh(self):
-        last_updated = self._get_cached_state()["updated_at"]
+        cache = self._get_cached_state()
+        if "updated_at" in cache:
+            last_updated = self._get_cached_state()["updated_at"]
+        else:
+            last_updated = 0
+
         if self._refresh_task is None or time() - last_updated >= self._CACHE_TIMEOUT:
             self._cached_state["updated_at"] = time()
             self._refresh_task = self._hass.async_add_executor_job(self.refresh)