Streamline `hass.data` storage for AirVisual (#64476)
parent
eabe658211
commit
ee215fb589
|
@ -44,7 +44,6 @@ from .const import (
|
|||
CONF_COUNTRY,
|
||||
CONF_GEOGRAPHIES,
|
||||
CONF_INTEGRATION_TYPE,
|
||||
DATA_COORDINATOR,
|
||||
DOMAIN,
|
||||
INTEGRATION_TYPE_GEOGRAPHY_COORDS,
|
||||
INTEGRATION_TYPE_GEOGRAPHY_NAME,
|
||||
|
@ -106,9 +105,8 @@ def async_get_cloud_coordinators_by_api_key(
|
|||
"""Get all DataUpdateCoordinator objects related to a particular API key."""
|
||||
return [
|
||||
coordinator
|
||||
for entry_id, attrs in hass.data[DOMAIN].items()
|
||||
for entry_id, coordinator in hass.data[DOMAIN].items()
|
||||
if (entry := hass.config_entries.async_get_entry(entry_id))
|
||||
and (coordinator := attrs.get(DATA_COORDINATOR))
|
||||
and entry.data.get(CONF_API_KEY) == api_key
|
||||
]
|
||||
|
||||
|
@ -270,7 +268,7 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
|
|||
|
||||
await coordinator.async_config_entry_first_refresh()
|
||||
hass.data.setdefault(DOMAIN, {})
|
||||
hass.data[DOMAIN][entry.entry_id] = {DATA_COORDINATOR: coordinator}
|
||||
hass.data[DOMAIN][entry.entry_id] = coordinator
|
||||
|
||||
# Reassess the interval between 2 server requests
|
||||
if CONF_API_KEY in entry.data:
|
||||
|
|
|
@ -12,5 +12,3 @@ CONF_CITY = "city"
|
|||
CONF_COUNTRY = "country"
|
||||
CONF_GEOGRAPHIES = "geographies"
|
||||
CONF_INTEGRATION_TYPE = "integration_type"
|
||||
|
||||
DATA_COORDINATOR = "coordinator"
|
||||
|
|
|
@ -32,7 +32,6 @@ from .const import (
|
|||
CONF_CITY,
|
||||
CONF_COUNTRY,
|
||||
CONF_INTEGRATION_TYPE,
|
||||
DATA_COORDINATOR,
|
||||
DOMAIN,
|
||||
INTEGRATION_TYPE_GEOGRAPHY_COORDS,
|
||||
INTEGRATION_TYPE_GEOGRAPHY_NAME,
|
||||
|
@ -185,7 +184,7 @@ async def async_setup_entry(
|
|||
hass: HomeAssistant, entry: ConfigEntry, async_add_entities: AddEntitiesCallback
|
||||
) -> None:
|
||||
"""Set up AirVisual sensors based on a config entry."""
|
||||
coordinator = hass.data[DOMAIN][entry.entry_id][DATA_COORDINATOR]
|
||||
coordinator = hass.data[DOMAIN][entry.entry_id]
|
||||
|
||||
sensors: list[AirVisualGeographySensor | AirVisualNodeProSensor]
|
||||
if entry.data[CONF_INTEGRATION_TYPE] in (
|
||||
|
|
Loading…
Reference in New Issue