mirror of
https://github.com/home-assistant/core.git
synced 2025-07-15 01:07:10 +00:00
Properly unload listener for AirVisual config entry updates (#42583)
This commit is contained in:
parent
b9d04b9304
commit
f78e75e16f
@ -45,6 +45,8 @@ from .const import (
|
|||||||
|
|
||||||
PLATFORMS = ["air_quality", "sensor"]
|
PLATFORMS = ["air_quality", "sensor"]
|
||||||
|
|
||||||
|
DATA_LISTENER = "listener"
|
||||||
|
|
||||||
DEFAULT_ATTRIBUTION = "Data provided by AirVisual"
|
DEFAULT_ATTRIBUTION = "Data provided by AirVisual"
|
||||||
DEFAULT_NODE_PRO_UPDATE_INTERVAL = timedelta(minutes=1)
|
DEFAULT_NODE_PRO_UPDATE_INTERVAL = timedelta(minutes=1)
|
||||||
DEFAULT_OPTIONS = {CONF_SHOW_ON_MAP: True}
|
DEFAULT_OPTIONS = {CONF_SHOW_ON_MAP: True}
|
||||||
@ -151,7 +153,7 @@ def async_sync_geo_coordinator_update_intervals(hass, api_key):
|
|||||||
|
|
||||||
async def async_setup(hass, config):
|
async def async_setup(hass, config):
|
||||||
"""Set up the AirVisual component."""
|
"""Set up the AirVisual component."""
|
||||||
hass.data[DOMAIN] = {DATA_COORDINATOR: {}}
|
hass.data[DOMAIN] = {DATA_COORDINATOR: {}, DATA_LISTENER: {}}
|
||||||
|
|
||||||
if DOMAIN not in config:
|
if DOMAIN not in config:
|
||||||
return True
|
return True
|
||||||
@ -281,7 +283,9 @@ async def async_setup_entry(hass, config_entry):
|
|||||||
)
|
)
|
||||||
|
|
||||||
# Only geography-based entries have options:
|
# Only geography-based entries have options:
|
||||||
config_entry.add_update_listener(async_reload_entry)
|
hass.data[DOMAIN][DATA_LISTENER][
|
||||||
|
config_entry.entry_id
|
||||||
|
] = config_entry.add_update_listener(async_reload_entry)
|
||||||
else:
|
else:
|
||||||
_standardize_node_pro_config_entry(hass, config_entry)
|
_standardize_node_pro_config_entry(hass, config_entry)
|
||||||
|
|
||||||
@ -365,9 +369,12 @@ async def async_unload_entry(hass, config_entry):
|
|||||||
)
|
)
|
||||||
if unload_ok:
|
if unload_ok:
|
||||||
hass.data[DOMAIN][DATA_COORDINATOR].pop(config_entry.entry_id)
|
hass.data[DOMAIN][DATA_COORDINATOR].pop(config_entry.entry_id)
|
||||||
|
remove_listener = hass.data[DOMAIN][DATA_LISTENER].pop(config_entry.entry_id)
|
||||||
|
remove_listener()
|
||||||
|
|
||||||
if config_entry.data[CONF_INTEGRATION_TYPE] == INTEGRATION_TYPE_GEOGRAPHY:
|
if config_entry.data[CONF_INTEGRATION_TYPE] == INTEGRATION_TYPE_GEOGRAPHY:
|
||||||
# Re-calculate the update interval period for any remaining consumes of this
|
# Re-calculate the update interval period for any remaining consumers of
|
||||||
# API key:
|
# this API key:
|
||||||
async_sync_geo_coordinator_update_intervals(
|
async_sync_geo_coordinator_update_intervals(
|
||||||
hass, config_entry.data[CONF_API_KEY]
|
hass, config_entry.data[CONF_API_KEY]
|
||||||
)
|
)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user