Home Assistant Unofficial Reference 2024.12.1
__init__.py
Go to the documentation of this file.
1 """The Airthings BLE integration."""
2 
3 from __future__ import annotations
4 
5 from homeassistant.const import Platform
6 from homeassistant.core import HomeAssistant
7 
8 from .const import MAX_RETRIES_AFTER_STARTUP
9 from .coordinator import AirthingsBLEConfigEntry, AirthingsBLEDataUpdateCoordinator
10 
11 PLATFORMS: list[Platform] = [Platform.SENSOR]
12 
13 
15  hass: HomeAssistant, entry: AirthingsBLEConfigEntry
16 ) -> bool:
17  """Set up Airthings BLE device from a config entry."""
18  coordinator = AirthingsBLEDataUpdateCoordinator(hass, entry)
19  await coordinator.async_config_entry_first_refresh()
20 
21  # Once its setup and we know we are not going to delay
22  # the startup of Home Assistant, we can set the max attempts
23  # to a higher value. If the first connection attempt fails,
24  # Home Assistant's built-in retry logic will take over.
25  coordinator.airthings.set_max_attempts(MAX_RETRIES_AFTER_STARTUP)
26 
27  entry.runtime_data = coordinator
28 
29  await hass.config_entries.async_forward_entry_setups(entry, PLATFORMS)
30 
31  return True
32 
33 
35  hass: HomeAssistant, entry: AirthingsBLEConfigEntry
36 ) -> bool:
37  """Unload a config entry."""
38  return await hass.config_entries.async_unload_platforms(entry, PLATFORMS)
bool async_unload_entry(HomeAssistant hass, AirthingsBLEConfigEntry entry)
Definition: __init__.py:36
bool async_setup_entry(HomeAssistant hass, AirthingsBLEConfigEntry entry)
Definition: __init__.py:16