Creating persistent async tasks

I’m developing an integration where the api uses asyncio and requires an event loop in the form of a Coroutine to be called. I had attempted to use hass.async_create_task to generate a task and run the event loop however because the task doesn’t complete until the api is shutdown the startup of home assistant gets stalled in async_block_til_done. The work-around is to create the task outside of home assistant’s APIs (e.g. using asyncio.create_task) however this doesn’t seem like a good solution.

Is there an intended approach to this such as running these types of Coroutines after the start phase?

1 Like