Browse Source

Refresh cache when it is less than one in length.

The change from checking for specific dps to checking length was assuming
that the "updated_at" timestamp was always present.  When we set up mocks for
tests, that is not always the case, so allow for the case where it is missing.
Jason Rumney 4 years ago
parent
commit
1720962a11
1 changed files with 3 additions and 1 deletions
  1. 3 1
      custom_components/tuya_local/device.py

+ 3 - 1
custom_components/tuya_local/device.py

@@ -83,7 +83,9 @@ class TuyaLocalDevice(object):
     async def async_inferred_type(self):
 
         cached_state = self._get_cached_state()
-        if len(cached_state) == 1:
+        # cached state should have "updated_at" timestamp if it has anything,
+        # so use 1 as the threshold for judging if dps have been fetched.
+        if len(cached_state) <= 1:
             await self.async_refresh()
             cached_state = self._get_cached_state()