Просмотр исходного кода

Revert "Use lock when getting status from device." and subsequent commits

This reverts commits: c103d036e, 0797eae5e, cc6fba50d, a298c59dd
which were ineffective at fixing the communication errors, and may impact performance.
Jason Rumney 5 лет назад
Родитель
Сommit
d27a73a2e9
1 измененных файлов с 10 добавлено и 21 удалено
  1. 10 21
      custom_components/tuya_local/device.py

+ 10 - 21
custom_components/tuya_local/device.py

@@ -122,16 +122,9 @@ class TuyaLocalDevice(object):
 
     async def async_refresh(self):
         last_updated = self._get_cached_state()["updated_at"]
-        try:
-            self._lock.acquire()
-            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)
-        finally:
-            self._lock.release()
+        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)
 
         await self._refresh_task
 
@@ -169,17 +162,13 @@ class TuyaLocalDevice(object):
         self._pending_updates = {}
 
     def _refresh_cached_state(self):
-        try:
-            self._lock.acquire()
-            new_state = self._api.status()
-            self._cached_state = new_state["dps"]
-            self._cached_state["updated_at"] = time()
-            _LOGGER.debug(f"refreshed device state: {json.dumps(new_state)}")
-            _LOGGER.debug(
-                f"new cache state (including pending properties): {json.dumps(self._get_cached_state())}"
-            )
-        finally:
-            self._lock.release()
+        new_state = self._api.status()
+        self._cached_state = new_state["dps"]
+        self._cached_state["updated_at"] = time()
+        _LOGGER.debug(f"refreshed device state: {json.dumps(new_state)}")
+        _LOGGER.debug(
+            f"new cache state (including pending properties): {json.dumps(self._get_cached_state())}"
+        )
 
     def _set_properties(self, properties):
         if len(properties) == 0: