mirror of
https://github.com/home-assistant/core
synced 2024-08-28 03:36:46 +02:00
![Joost Lekkerkerker](/assets/img/avatar_default.png)
* Migrate WAQI to aiowaqi library * Migrate WAQI to aiowaqi library * Migrate WAQI to aiowaqi library * Add config flow to WAQI * Finish config flow * Add tests * Add tests * Fix ruff * Add issues on failing to import * Add issues on failing to import * Add issues on failing to import * Add importing issue * Finish coverage * Remove url from translation string * Fix feedback * Fix feedback
37 lines
1.1 KiB
Python
37 lines
1.1 KiB
Python
"""Coordinator for the World Air Quality Index (WAQI) integration."""
|
|
from __future__ import annotations
|
|
|
|
from datetime import timedelta
|
|
|
|
from aiowaqi import WAQIAirQuality, WAQIClient, WAQIError
|
|
|
|
from homeassistant.config_entries import ConfigEntry
|
|
from homeassistant.core import HomeAssistant
|
|
from homeassistant.helpers.update_coordinator import DataUpdateCoordinator, UpdateFailed
|
|
|
|
from .const import CONF_STATION_NUMBER, DOMAIN, LOGGER
|
|
|
|
|
|
class WAQIDataUpdateCoordinator(DataUpdateCoordinator[WAQIAirQuality]):
|
|
"""The WAQI Data Update Coordinator."""
|
|
|
|
config_entry: ConfigEntry
|
|
|
|
def __init__(self, hass: HomeAssistant, client: WAQIClient) -> None:
|
|
"""Initialize the WAQI data coordinator."""
|
|
super().__init__(
|
|
hass,
|
|
LOGGER,
|
|
name=DOMAIN,
|
|
update_interval=timedelta(minutes=5),
|
|
)
|
|
self._client = client
|
|
|
|
async def _async_update_data(self) -> WAQIAirQuality:
|
|
try:
|
|
return await self._client.get_by_station_number(
|
|
self.config_entry.data[CONF_STATION_NUMBER]
|
|
)
|
|
except WAQIError as exc:
|
|
raise UpdateFailed from exc
|