home-assistant-vacuum-styj02ym icon indicating copy to clipboard operation
home-assistant-vacuum-styj02ym copied to clipboard

"Passing coroutines is forbidden, use tasks explicitly" - Python incompatibility?

Open maks23rus opened this issue 1 year ago • 0 comments

The services still work, but every time one is executed the error appears.

I've noticied some problems related with "async", in other custom components, and the new changes with Python...

Logger: homeassistant.components.websocket_api.http.connection
Source: components/websocket_api/commands.py:230
Integration: Home Assistant WebSocket API ([documentation](https://www.home-assistant.io/integrations/websocket_api), [issues](https://github.com/home-assistant/core/issues?q=is%3Aissue+is%3Aopen+label%3A%22integration%3A+websocket_api%22))
First occurred: 11:21:16 (1 occurrences)
Last logged: 11:21:16

[140322262907200] Passing coroutines is forbidden, use tasks explicitly.
Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/components/websocket_api/commands.py", line 230, in handle_call_service
    await hass.services.async_call(
  File "/usr/src/homeassistant/homeassistant/core.py", line 2035, in async_call
    response_data = await coro
                    ^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/core.py", line 2072, in _execute_service
    return await target(service_call)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/config/custom_components/miio2/vacuum.py", line 231, in async_service_handler
    await asyncio.wait(update_tasks)
  File "/usr/local/lib/python3.11/asyncio/tasks.py", line 425, in wait
    raise TypeError("Passing coroutines is forbidden, use tasks explicitly.")
TypeError: Passing coroutines is forbidden, use tasks explicitly.

Please change the code to:

for vacuum in target_vacuums:
    update_coro = vacuum.async_update_ha_state(True)
    update_tasks.append(asyncio.create_task(update_coro))

maks23rus avatar Nov 17 '23 08:11 maks23rus