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

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 год назад
Родитель
Сommit
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()
             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,
             cached_state,
-        )
-        for match in possible:
+        ):
             await asyncio.sleep(0)
-            yield match
+            yield matched
 
     async def async_inferred_type(self):
         best_match = None