2024-05-09 08:54:29 +00:00
|
|
|
"""The Airgradient integration."""
|
|
|
|
|
|
|
|
from __future__ import annotations
|
|
|
|
|
2024-08-31 14:40:12 +00:00
|
|
|
from airgradient import AirGradientClient
|
2024-05-29 18:12:51 +00:00
|
|
|
|
2024-05-09 08:54:29 +00:00
|
|
|
from homeassistant.config_entries import ConfigEntry
|
|
|
|
from homeassistant.const import CONF_HOST, Platform
|
|
|
|
from homeassistant.core import HomeAssistant
|
2024-05-29 18:12:51 +00:00
|
|
|
from homeassistant.helpers.aiohttp_client import async_get_clientsession
|
2024-05-09 08:54:29 +00:00
|
|
|
|
2024-08-31 14:40:12 +00:00
|
|
|
from .coordinator import AirGradientCoordinator
|
2024-05-09 08:54:29 +00:00
|
|
|
|
2024-06-24 09:55:48 +00:00
|
|
|
PLATFORMS: list[Platform] = [
|
|
|
|
Platform.BUTTON,
|
|
|
|
Platform.NUMBER,
|
|
|
|
Platform.SELECT,
|
|
|
|
Platform.SENSOR,
|
2024-06-26 12:21:30 +00:00
|
|
|
Platform.SWITCH,
|
2024-08-13 16:44:12 +00:00
|
|
|
Platform.UPDATE,
|
2024-06-24 09:55:48 +00:00
|
|
|
]
|
2024-05-09 08:54:29 +00:00
|
|
|
|
|
|
|
|
2024-08-31 14:40:12 +00:00
|
|
|
type AirGradientConfigEntry = ConfigEntry[AirGradientCoordinator]
|
2024-06-12 12:49:03 +00:00
|
|
|
|
|
|
|
|
2024-07-21 06:41:42 +00:00
|
|
|
async def async_setup_entry(hass: HomeAssistant, entry: AirGradientConfigEntry) -> bool:
|
2024-05-09 08:54:29 +00:00
|
|
|
"""Set up Airgradient from a config entry."""
|
|
|
|
|
2024-05-29 18:12:51 +00:00
|
|
|
client = AirGradientClient(
|
|
|
|
entry.data[CONF_HOST], session=async_get_clientsession(hass)
|
|
|
|
)
|
|
|
|
|
2024-08-31 14:40:12 +00:00
|
|
|
coordinator = AirGradientCoordinator(hass, client)
|
2024-05-29 18:12:51 +00:00
|
|
|
|
2024-08-31 14:40:12 +00:00
|
|
|
await coordinator.async_config_entry_first_refresh()
|
|
|
|
|
|
|
|
entry.runtime_data = coordinator
|
2024-05-09 08:54:29 +00:00
|
|
|
|
|
|
|
await hass.config_entries.async_forward_entry_setups(entry, PLATFORMS)
|
|
|
|
|
|
|
|
return True
|
|
|
|
|
|
|
|
|
2024-07-21 06:41:42 +00:00
|
|
|
async def async_unload_entry(
|
|
|
|
hass: HomeAssistant, entry: AirGradientConfigEntry
|
|
|
|
) -> bool:
|
2024-05-09 08:54:29 +00:00
|
|
|
"""Unload a config entry."""
|
2024-06-12 12:49:03 +00:00
|
|
|
return await hass.config_entries.async_unload_platforms(entry, PLATFORMS)
|