mirror of
https://github.com/home-assistant/core.git
synced 2025-07-26 06:37:52 +00:00
Streamline hass.data
storage for AirVisual (#64476)
This commit is contained in:
parent
eabe658211
commit
ee215fb589
@ -44,7 +44,6 @@ from .const import (
|
|||||||
CONF_COUNTRY,
|
CONF_COUNTRY,
|
||||||
CONF_GEOGRAPHIES,
|
CONF_GEOGRAPHIES,
|
||||||
CONF_INTEGRATION_TYPE,
|
CONF_INTEGRATION_TYPE,
|
||||||
DATA_COORDINATOR,
|
|
||||||
DOMAIN,
|
DOMAIN,
|
||||||
INTEGRATION_TYPE_GEOGRAPHY_COORDS,
|
INTEGRATION_TYPE_GEOGRAPHY_COORDS,
|
||||||
INTEGRATION_TYPE_GEOGRAPHY_NAME,
|
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."""
|
"""Get all DataUpdateCoordinator objects related to a particular API key."""
|
||||||
return [
|
return [
|
||||||
coordinator
|
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))
|
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
|
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()
|
await coordinator.async_config_entry_first_refresh()
|
||||||
hass.data.setdefault(DOMAIN, {})
|
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
|
# Reassess the interval between 2 server requests
|
||||||
if CONF_API_KEY in entry.data:
|
if CONF_API_KEY in entry.data:
|
||||||
|
@ -12,5 +12,3 @@ CONF_CITY = "city"
|
|||||||
CONF_COUNTRY = "country"
|
CONF_COUNTRY = "country"
|
||||||
CONF_GEOGRAPHIES = "geographies"
|
CONF_GEOGRAPHIES = "geographies"
|
||||||
CONF_INTEGRATION_TYPE = "integration_type"
|
CONF_INTEGRATION_TYPE = "integration_type"
|
||||||
|
|
||||||
DATA_COORDINATOR = "coordinator"
|
|
||||||
|
@ -32,7 +32,6 @@ from .const import (
|
|||||||
CONF_CITY,
|
CONF_CITY,
|
||||||
CONF_COUNTRY,
|
CONF_COUNTRY,
|
||||||
CONF_INTEGRATION_TYPE,
|
CONF_INTEGRATION_TYPE,
|
||||||
DATA_COORDINATOR,
|
|
||||||
DOMAIN,
|
DOMAIN,
|
||||||
INTEGRATION_TYPE_GEOGRAPHY_COORDS,
|
INTEGRATION_TYPE_GEOGRAPHY_COORDS,
|
||||||
INTEGRATION_TYPE_GEOGRAPHY_NAME,
|
INTEGRATION_TYPE_GEOGRAPHY_NAME,
|
||||||
@ -185,7 +184,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][entry.entry_id][DATA_COORDINATOR]
|
coordinator = hass.data[DOMAIN][entry.entry_id]
|
||||||
|
|
||||||
sensors: list[AirVisualGeographySensor | AirVisualNodeProSensor]
|
sensors: list[AirVisualGeographySensor | AirVisualNodeProSensor]
|
||||||
if entry.data[CONF_INTEGRATION_TYPE] in (
|
if entry.data[CONF_INTEGRATION_TYPE] in (
|
||||||
|
Loading…
x
Reference in New Issue
Block a user