1 """The AirNow integration."""
18 from .coordinator
import AirNowDataUpdateCoordinator
20 _LOGGER = logging.getLogger(__name__)
21 PLATFORMS = [Platform.SENSOR]
23 type AirNowConfigEntry = ConfigEntry[AirNowDataUpdateCoordinator]
27 """Set up AirNow from a config entry."""
28 api_key = entry.data[CONF_API_KEY]
29 latitude = entry.data[CONF_LATITUDE]
30 longitude = entry.data[CONF_LONGITUDE]
33 distance = entry.options[CONF_RADIUS]
36 update_interval = datetime.timedelta(minutes=30)
41 hass, session, api_key, latitude, longitude, distance, update_interval
45 await coordinator.async_config_entry_first_refresh()
48 entry.runtime_data = coordinator
51 entry.async_on_unload(entry.add_update_listener(update_listener))
53 await hass.config_entries.async_forward_entry_setups(entry, PLATFORMS)
56 device_registry = dr.async_get(hass)
57 entity_registry = er.async_get(hass)
59 device_entries = dr.async_entries_for_config_entry(
60 device_registry, config_entry_id=entry.entry_id
62 for dev
in device_entries:
63 dev_entities = er.async_entries_for_device(
64 entity_registry, dev.id, include_disabled_entities=
True
67 device_registry.async_remove_device(dev.id)
73 """Migrate old entry."""
74 _LOGGER.debug(
"Migrating from version %s", entry.version)
76 if entry.version == 1:
77 new_options = {CONF_RADIUS: entry.data[CONF_RADIUS]}
78 new_data = entry.data.copy()
79 del new_data[CONF_RADIUS]
81 hass.config_entries.async_update_entry(
82 entry, data=new_data, options=new_options, version=2
85 _LOGGER.info(
"Migration to version %s successful", entry.version)
91 """Unload a config entry."""
92 return await hass.config_entries.async_unload_platforms(entry, PLATFORMS)
96 """Handle options update."""
97 await hass.config_entries.async_reload(entry.entry_id)
bool async_unload_entry(HomeAssistant hass, AirNowConfigEntry entry)
bool async_setup_entry(HomeAssistant hass, AirNowConfigEntry entry)
None update_listener(HomeAssistant hass, ConfigEntry entry)
bool async_migrate_entry(HomeAssistant hass, ConfigEntry 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)