瀏覽代碼

device matching: run every iteration of generator async

Code was calling the generator as if it were a function, expecting to be able
to loop through the results synchronously. But since it is a generator, every
iteration of the loop needs to be called asynchronously to avoid complaints
about the I/O waits from HA.

Issue #2501
Jason Rumney 1 年之前
父節點
當前提交
5f2113ddf4
共有 1 個文件被更改,包括 3 次插入4 次删除
  1. 3 4
      custom_components/tuya_local/device.py

+ 3 - 4
custom_components/tuya_local/device.py

@@ -380,13 +380,12 @@ class TuyaLocalDevice(object):
             await self.async_refresh()
             await self.async_refresh()
             cached_state = self._get_cached_state()
             cached_state = self._get_cached_state()
 
 
-        possible = await self._hass.async_add_executor_job(
+        for matched in await self._hass.async_add_executor_job(
             possible_matches,
             possible_matches,
             cached_state,
             cached_state,
-        )
-        for match in possible:
+        ):
             await asyncio.sleep(0)
             await asyncio.sleep(0)
-            yield match
+            yield matched
 
 
     async def async_inferred_type(self):
     async def async_inferred_type(self):
         best_match = None
         best_match = None