diff --git a/homeassistant/components/airvisual/__init__.py b/homeassistant/components/airvisual/__init__.py index 473cf3a32dd..f02020d25b4 100644 --- a/homeassistant/components/airvisual/__init__.py +++ b/homeassistant/components/airvisual/__init__.py @@ -242,10 +242,6 @@ async def async_setup_entry(hass, config_entry): update_method=async_update_data, ) - async_sync_geo_coordinator_update_intervals( - hass, config_entry.data[CONF_API_KEY] - ) - # Only geography-based entries have options: hass.data[DOMAIN][DATA_LISTENER][ config_entry.entry_id @@ -275,6 +271,12 @@ async def async_setup_entry(hass, config_entry): hass.data[DOMAIN][DATA_COORDINATOR][config_entry.entry_id] = coordinator + # Reassess the interval between 2 server requests + if CONF_API_KEY in config_entry.data: + async_sync_geo_coordinator_update_intervals( + hass, config_entry.data[CONF_API_KEY] + ) + for platform in PLATFORMS: hass.async_create_task( hass.config_entries.async_forward_entry_setup(config_entry, platform) @@ -340,10 +342,7 @@ async def async_unload_entry(hass, config_entry): remove_listener = hass.data[DOMAIN][DATA_LISTENER].pop(config_entry.entry_id) remove_listener() - if ( - config_entry.data[CONF_INTEGRATION_TYPE] - == INTEGRATION_TYPE_GEOGRAPHY_COORDS - ): + if CONF_API_KEY in config_entry.data: # Re-calculate the update interval period for any remaining consumers of # this API key: async_sync_geo_coordinator_update_intervals(