Use an async dependency
Platinum rule async-dependency: the library of the integration uses asyncio.
This is a Platinum rule. In quality_scale.yaml, it is called async-dependency.
The library that the integration uses to talk to the device or service must be written for asyncio. Its I/O, like network requests, runs as coroutines on the event loop of Home Assistant, instead of blocking calls that need a thread.
Home Assistant runs on asyncio. A blocking library cannot run on the event loop, so every call has to go to a thread in the executor, and the result has to come back to the loop. Each of those switches costs time and memory, and with many integrations polling many devices, it adds up. An async library avoids all of that, and the integration code gets simpler as well.
With a blocking library, every call goes through the executor:
data = await hass.async_add_executor_job(client.get_data)With an async library, you await the call directly:
data = await client.get_data()If you maintain the library yourself, this usually means building it on aiohttp or httpx for HTTP, or on the asyncio streams for raw sockets. That also makes inject-websession possible.
This rule is checked in review. A good hint in the code is the use of async_add_executor_job for calls to the library.
If the integration has no external dependencies, or its dependencies do no I/O, this rule does not apply.
- inject-websession: pass in the web session.
- dependency-transparency: use transparent dependencies.