ha-async-patterns
Installation
SKILL.md
Async Python Patterns in Home Assistant
Home Assistant runs on a single-threaded asyncio event loop. All I/O must be non-blocking. Blocking the loop freezes automations, the UI, and entity updates.
Pattern 1: Async Libraries (Preferred)
import aiohttp
async def async_get_data(self) -> dict:
async with aiohttp.ClientSession() as session:
async with session.get(f"http://{self._host}/api") as response:
response.raise_for_status()
return await response.json()
Pattern 2: Wrapping Sync Libraries
When no async library exists:
Related skills