Make sure AirVisual data storage conforms to standards (#57806)
This commit is contained in:
parent
6fb0609f0c
commit
3da3d26573
2 changed files with 11 additions and 12 deletions
|
@ -104,12 +104,12 @@ def async_get_cloud_coordinators_by_api_key(
|
||||||
hass: HomeAssistant, api_key: str
|
hass: HomeAssistant, api_key: str
|
||||||
) -> list[DataUpdateCoordinator]:
|
) -> list[DataUpdateCoordinator]:
|
||||||
"""Get all DataUpdateCoordinator objects related to a particular API key."""
|
"""Get all DataUpdateCoordinator objects related to a particular API key."""
|
||||||
coordinators = []
|
return [
|
||||||
for entry_id, coordinator in hass.data[DOMAIN][DATA_COORDINATOR].items():
|
attrs[DATA_COORDINATOR]
|
||||||
entry = hass.config_entries.async_get_entry(entry_id)
|
for entry_id, attrs in hass.data[DOMAIN].items()
|
||||||
if entry and entry.data.get(CONF_API_KEY) == api_key:
|
if (entry := hass.config_entries.async_get_entry(entry_id))
|
||||||
coordinators.append(coordinator)
|
and entry.data.get(CONF_API_KEY) == api_key
|
||||||
return coordinators
|
]
|
||||||
|
|
||||||
|
|
||||||
@callback
|
@callback
|
||||||
|
@ -190,7 +190,8 @@ def _standardize_node_pro_config_entry(hass: HomeAssistant, entry: ConfigEntry)
|
||||||
|
|
||||||
async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
|
async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
|
||||||
"""Set up AirVisual as config entry."""
|
"""Set up AirVisual as config entry."""
|
||||||
hass.data.setdefault(DOMAIN, {DATA_COORDINATOR: {}})
|
hass.data.setdefault(DOMAIN, {})
|
||||||
|
hass.data[DOMAIN][entry.entry_id] = {}
|
||||||
|
|
||||||
if CONF_API_KEY in entry.data:
|
if CONF_API_KEY in entry.data:
|
||||||
_standardize_geography_config_entry(hass, entry)
|
_standardize_geography_config_entry(hass, entry)
|
||||||
|
@ -270,8 +271,7 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
|
||||||
)
|
)
|
||||||
|
|
||||||
await coordinator.async_config_entry_first_refresh()
|
await coordinator.async_config_entry_first_refresh()
|
||||||
|
hass.data[DOMAIN][entry.entry_id][DATA_COORDINATOR] = coordinator
|
||||||
hass.data[DOMAIN][DATA_COORDINATOR][entry.entry_id] = coordinator
|
|
||||||
|
|
||||||
# Reassess the interval between 2 server requests
|
# Reassess the interval between 2 server requests
|
||||||
if CONF_API_KEY in entry.data:
|
if CONF_API_KEY in entry.data:
|
||||||
|
@ -329,8 +329,7 @@ async def async_unload_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
|
||||||
unload_ok = await hass.config_entries.async_unload_platforms(entry, PLATFORMS)
|
unload_ok = await hass.config_entries.async_unload_platforms(entry, PLATFORMS)
|
||||||
|
|
||||||
if unload_ok:
|
if unload_ok:
|
||||||
hass.data[DOMAIN][DATA_COORDINATOR].pop(entry.entry_id)
|
hass.data[DOMAIN].pop(entry.entry_id)
|
||||||
|
|
||||||
if CONF_API_KEY in entry.data:
|
if CONF_API_KEY in entry.data:
|
||||||
# Re-calculate the update interval period for any remaining consumers of
|
# Re-calculate the update interval period for any remaining consumers of
|
||||||
# this API key:
|
# this API key:
|
||||||
|
|
|
@ -192,7 +192,7 @@ async def async_setup_entry(
|
||||||
hass: HomeAssistant, entry: ConfigEntry, async_add_entities: AddEntitiesCallback
|
hass: HomeAssistant, entry: ConfigEntry, async_add_entities: AddEntitiesCallback
|
||||||
) -> None:
|
) -> None:
|
||||||
"""Set up AirVisual sensors based on a config entry."""
|
"""Set up AirVisual sensors based on a config entry."""
|
||||||
coordinator = hass.data[DOMAIN][DATA_COORDINATOR][entry.entry_id]
|
coordinator = hass.data[DOMAIN][entry.entry_id][DATA_COORDINATOR]
|
||||||
|
|
||||||
sensors: list[AirVisualGeographySensor | AirVisualNodeProSensor]
|
sensors: list[AirVisualGeographySensor | AirVisualNodeProSensor]
|
||||||
if entry.data[CONF_INTEGRATION_TYPE] in (
|
if entry.data[CONF_INTEGRATION_TYPE] in (
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue