1 """The Airthings integration."""
3 from __future__
import annotations
5 from datetime
import timedelta
8 from airthings
import Airthings, AirthingsDevice, AirthingsError
16 from .const
import CONF_SECRET, DOMAIN
18 _LOGGER = logging.getLogger(__name__)
20 PLATFORMS: list[Platform] = [Platform.SENSOR]
23 type AirthingsDataCoordinatorType = DataUpdateCoordinator[dict[str, AirthingsDevice]]
24 type AirthingsConfigEntry = ConfigEntry[AirthingsDataCoordinatorType]
28 """Set up Airthings from a config entry."""
29 airthings = Airthings(
31 entry.data[CONF_SECRET],
35 async
def _update_method() -> dict[str, AirthingsDevice]:
36 """Get the latest data from Airthings."""
38 return await airthings.update_devices()
39 except AirthingsError
as err:
40 raise UpdateFailed(f
"Unable to fetch data: {err}")
from err
47 update_method=_update_method,
48 update_interval=SCAN_INTERVAL,
50 await coordinator.async_config_entry_first_refresh()
52 entry.runtime_data = coordinator
54 await hass.config_entries.async_forward_entry_setups(entry, PLATFORMS)
60 """Unload a config entry."""
61 return await hass.config_entries.async_unload_platforms(entry, PLATFORMS)
bool async_setup_entry(HomeAssistant hass, AirthingsConfigEntry entry)
bool async_unload_entry(HomeAssistant hass, AirthingsConfigEntry entry)
aiohttp.ClientSession async_get_clientsession(HomeAssistant hass, bool verify_ssl=True, socket.AddressFamily family=socket.AF_UNSPEC, ssl_util.SSLCipherList ssl_cipher=ssl_util.SSLCipherList.PYTHON_DEFAULT)