1 """The Airly integration."""
3 from __future__
import annotations
5 from datetime
import timedelta
15 from .const
import CONF_USE_NEAREST, DOMAIN, MIN_UPDATE_INTERVAL
16 from .coordinator
import AirlyDataUpdateCoordinator
18 PLATFORMS = [Platform.SENSOR]
20 _LOGGER = logging.getLogger(__name__)
22 type AirlyConfigEntry = ConfigEntry[AirlyDataUpdateCoordinator]
26 """Set up Airly as config entry."""
27 api_key = entry.data[CONF_API_KEY]
28 latitude = entry.data[CONF_LATITUDE]
29 longitude = entry.data[CONF_LONGITUDE]
30 use_nearest = entry.data.get(CONF_USE_NEAREST,
False)
33 if entry.unique_id
is None:
34 hass.config_entries.async_update_entry(
35 entry, unique_id=f
"{latitude}-{longitude}"
41 device_registry = dr.async_get(hass)
42 old_ids = (DOMAIN, latitude, longitude)
44 (DOMAIN, latitude, longitude),
51 device_entry = device_registry.async_get_device(identifiers={old_ids})
52 if device_entry
and entry.entry_id
in device_entry.config_entries:
53 new_ids = (DOMAIN, f
"{latitude}-{longitude}")
54 device_registry.async_update_device(
55 device_entry.id, new_identifiers={new_ids}
60 update_interval =
timedelta(minutes=MIN_UPDATE_INTERVAL)
63 hass, websession, api_key, latitude, longitude, update_interval, use_nearest
65 await coordinator.async_config_entry_first_refresh()
67 entry.runtime_data = coordinator
69 await hass.config_entries.async_forward_entry_setups(entry, PLATFORMS)
72 ent_reg = er.async_get(hass)
73 unique_id = f
"{coordinator.latitude}-{coordinator.longitude}"
74 if entity_id := ent_reg.async_get_entity_id(
75 AIR_QUALITY_PLATFORM, DOMAIN, unique_id
77 _LOGGER.debug(
"Removing deprecated air_quality entity %s", entity_id)
78 ent_reg.async_remove(entity_id)
84 """Unload a config entry."""
85 return await hass.config_entries.async_unload_platforms(entry, PLATFORMS)
bool async_unload_entry(HomeAssistant hass, AirlyConfigEntry entry)
bool async_setup_entry(HomeAssistant hass, AirlyConfigEntry 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)