mirror of https://github.com/home-assistant/core
50 lines
1.3 KiB
Python
50 lines
1.3 KiB
Python
"""The Airgradient integration."""
|
|
|
|
from __future__ import annotations
|
|
|
|
from airgradient import AirGradientClient
|
|
|
|
from homeassistant.config_entries import ConfigEntry
|
|
from homeassistant.const import CONF_HOST, Platform
|
|
from homeassistant.core import HomeAssistant
|
|
from homeassistant.helpers.aiohttp_client import async_get_clientsession
|
|
|
|
from .coordinator import AirGradientCoordinator
|
|
|
|
PLATFORMS: list[Platform] = [
|
|
Platform.BUTTON,
|
|
Platform.NUMBER,
|
|
Platform.SELECT,
|
|
Platform.SENSOR,
|
|
Platform.SWITCH,
|
|
Platform.UPDATE,
|
|
]
|
|
|
|
|
|
type AirGradientConfigEntry = ConfigEntry[AirGradientCoordinator]
|
|
|
|
|
|
async def async_setup_entry(hass: HomeAssistant, entry: AirGradientConfigEntry) -> bool:
|
|
"""Set up Airgradient from a config entry."""
|
|
|
|
client = AirGradientClient(
|
|
entry.data[CONF_HOST], session=async_get_clientsession(hass)
|
|
)
|
|
|
|
coordinator = AirGradientCoordinator(hass, client)
|
|
|
|
await coordinator.async_config_entry_first_refresh()
|
|
|
|
entry.runtime_data = coordinator
|
|
|
|
await hass.config_entries.async_forward_entry_setups(entry, PLATFORMS)
|
|
|
|
return True
|
|
|
|
|
|
async def async_unload_entry(
|
|
hass: HomeAssistant, entry: AirGradientConfigEntry
|
|
) -> bool:
|
|
"""Unload a config entry."""
|
|
return await hass.config_entries.async_unload_platforms(entry, PLATFORMS)
|