Streamline `hass.data` storage for AirVisual (#64476)

pull/64481/head
Aaron Bach 2022-01-19 14:32:23 -07:00 committed by GitHub
parent eabe658211
commit ee215fb589
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 3 additions and 8 deletions

View File

@ -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:

View File

@ -12,5 +12,3 @@ CONF_CITY = "city"
CONF_COUNTRY = "country"
CONF_GEOGRAPHIES = "geographies"
CONF_INTEGRATION_TYPE = "integration_type"
DATA_COORDINATOR = "coordinator"

View File

@ -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 (