diff --git a/homeassistant/components/adguard/__init__.py b/homeassistant/components/adguard/__init__.py index 2cda6d92556..b848dcefc8c 100644 --- a/homeassistant/components/adguard/__init__.py +++ b/homeassistant/components/adguard/__init__.py @@ -68,10 +68,7 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool: except AdGuardHomeConnectionError as exception: raise ConfigEntryNotReady from exception - for platform in PLATFORMS: - hass.async_create_task( - hass.config_entries.async_forward_entry_setup(entry, platform) - ) + hass.config_entries.async_setup_platforms(entry, PLATFORMS) async def add_url(call) -> None: """Service call to add a new filter subscription to AdGuard Home.""" @@ -126,12 +123,11 @@ async def async_unload_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool: hass.services.async_remove(DOMAIN, SERVICE_DISABLE_URL) hass.services.async_remove(DOMAIN, SERVICE_REFRESH) - for component in PLATFORMS: - await hass.config_entries.async_forward_entry_unload(entry, component) + unload_ok = await hass.config_entries.async_unload_platforms(entry, PLATFORMS) + if unload_ok: + del hass.data[DOMAIN] - del hass.data[DOMAIN] - - return True + return unload_ok class AdGuardHomeEntity(Entity): diff --git a/homeassistant/components/arcam_fmj/__init__.py b/homeassistant/components/arcam_fmj/__init__.py index 8d22cb7723f..e1dfac09d76 100644 --- a/homeassistant/components/arcam_fmj/__init__.py +++ b/homeassistant/components/arcam_fmj/__init__.py @@ -27,6 +27,8 @@ _LOGGER = logging.getLogger(__name__) CONFIG_SCHEMA = cv.deprecated(DOMAIN) +PLATFORMS = ["media_player"] + async def _await_cancel(task): task.cancel() @@ -60,23 +62,21 @@ async def async_setup_entry(hass: HomeAssistant, entry: config_entries.ConfigEnt task = asyncio.create_task(_run_client(hass, client, DEFAULT_SCAN_INTERVAL)) tasks[entry.entry_id] = task - hass.async_create_task( - hass.config_entries.async_forward_entry_setup(entry, "media_player") - ) + hass.config_entries.async_setup_platforms(entry, PLATFORMS) return True async def async_unload_entry(hass, entry): """Cleanup before removing config entry.""" - await hass.config_entries.async_forward_entry_unload(entry, "media_player") + unload_ok = await hass.config_entries.async_unload_platforms(entry, PLATFORMS) task = hass.data[DOMAIN_DATA_TASKS].pop(entry.entry_id) await _await_cancel(task) hass.data[DOMAIN_DATA_ENTRIES].pop(entry.entry_id) - return True + return unload_ok async def _run_client(hass, client, interval): diff --git a/homeassistant/components/azure_devops/__init__.py b/homeassistant/components/azure_devops/__init__.py index 5b0a42bb2a1..017b1246503 100644 --- a/homeassistant/components/azure_devops/__init__.py +++ b/homeassistant/components/azure_devops/__init__.py @@ -18,10 +18,11 @@ from homeassistant.config_entries import ConfigEntry from homeassistant.core import HomeAssistant from homeassistant.exceptions import ConfigEntryAuthFailed, ConfigEntryNotReady from homeassistant.helpers.entity import Entity -from homeassistant.helpers.typing import ConfigType _LOGGER = logging.getLogger(__name__) +PLATFORMS = ["sensor"] + async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool: """Set up Azure DevOps from a config entry.""" @@ -43,18 +44,16 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool: hass.data.setdefault(instance_key, {})[DATA_AZURE_DEVOPS_CLIENT] = client # Setup components - hass.async_create_task( - hass.config_entries.async_forward_entry_setup(entry, "sensor") - ) + hass.config_entries.async_setup_platforms(entry, PLATFORMS) return True -async def async_unload_entry(hass: HomeAssistant, entry: ConfigType) -> bool: +async def async_unload_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool: """Unload Azure DevOps config entry.""" del hass.data[f"{DOMAIN}_{entry.data[CONF_ORG]}_{entry.data[CONF_PROJECT]}"] - return await hass.config_entries.async_forward_entry_unload(entry, "sensor") + return await hass.config_entries.async_unload_platforms(entry, PLATFORMS) class AzureDevOpsEntity(Entity): diff --git a/homeassistant/components/bsblan/__init__.py b/homeassistant/components/bsblan/__init__.py index f452451050b..6c6c8a18336 100644 --- a/homeassistant/components/bsblan/__init__.py +++ b/homeassistant/components/bsblan/__init__.py @@ -14,6 +14,8 @@ from .const import CONF_PASSKEY, DATA_BSBLAN_CLIENT, DOMAIN SCAN_INTERVAL = timedelta(seconds=30) +PLATFORMS = [CLIMATE_DOMAIN] + async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool: """Set up BSB-Lan from a config entry.""" @@ -36,9 +38,7 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool: hass.data.setdefault(DOMAIN, {}) hass.data[DOMAIN][entry.entry_id] = {DATA_BSBLAN_CLIENT: bsblan} - hass.async_create_task( - hass.config_entries.async_forward_entry_setup(entry, CLIMATE_DOMAIN) - ) + hass.config_entries.async_setup_platforms(entry, PLATFORMS) return True @@ -46,11 +46,11 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool: async def async_unload_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool: """Unload BSBLan config entry.""" - await hass.config_entries.async_forward_entry_unload(entry, CLIMATE_DOMAIN) + unload_ok = await hass.config_entries.async_unload_platforms(entry, PLATFORMS) + if unload_ok: + # Cleanup + del hass.data[DOMAIN][entry.entry_id] + if not hass.data[DOMAIN]: + del hass.data[DOMAIN] - # Cleanup - del hass.data[DOMAIN][entry.entry_id] - if not hass.data[DOMAIN]: - del hass.data[DOMAIN] - - return True + return unload_ok diff --git a/homeassistant/components/cert_expiry/__init__.py b/homeassistant/components/cert_expiry/__init__.py index aab996873ca..f91eaab49b6 100644 --- a/homeassistant/components/cert_expiry/__init__.py +++ b/homeassistant/components/cert_expiry/__init__.py @@ -17,6 +17,8 @@ _LOGGER = logging.getLogger(__name__) SCAN_INTERVAL = timedelta(hours=12) +PLATFORMS = ["sensor"] + async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry): """Load the saved entities.""" @@ -32,15 +34,14 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry): if entry.unique_id is None: hass.config_entries.async_update_entry(entry, unique_id=f"{host}:{port}") - hass.async_create_task( - hass.config_entries.async_forward_entry_setup(entry, "sensor") - ) + hass.config_entries.async_setup_platforms(entry, PLATFORMS) + return True async def async_unload_entry(hass, entry): """Unload a config entry.""" - return await hass.config_entries.async_forward_entry_unload(entry, "sensor") + return await hass.config_entries.async_unload_platforms(entry, PLATFORMS) class CertExpiryDataUpdateCoordinator(DataUpdateCoordinator[datetime]): diff --git a/homeassistant/components/coolmaster/__init__.py b/homeassistant/components/coolmaster/__init__.py index 2b092935bb0..e6cf6f36277 100644 --- a/homeassistant/components/coolmaster/__init__.py +++ b/homeassistant/components/coolmaster/__init__.py @@ -12,6 +12,8 @@ from .const import DATA_COORDINATOR, DATA_INFO, DOMAIN _LOGGER = logging.getLogger(__name__) +PLATFORMS = ["climate"] + async def async_setup_entry(hass, entry): """Set up Coolmaster from a config entry.""" @@ -31,20 +33,16 @@ async def async_setup_entry(hass, entry): DATA_INFO: info, DATA_COORDINATOR: coordinator, } - hass.async_create_task( - hass.config_entries.async_forward_entry_setup(entry, "climate") - ) + hass.config_entries.async_setup_platforms(entry, PLATFORMS) return True async def async_unload_entry(hass, entry): """Unload a Coolmaster config entry.""" - unload_ok = await hass.config_entries.async_forward_entry_unload(entry, "climate") - + unload_ok = await hass.config_entries.async_unload_platforms(entry, PLATFORMS) if unload_ok: hass.data[DOMAIN].pop(entry.entry_id) - return unload_ok diff --git a/homeassistant/components/daikin/__init__.py b/homeassistant/components/daikin/__init__.py index eb013e2ba30..fb38c38db0a 100644 --- a/homeassistant/components/daikin/__init__.py +++ b/homeassistant/components/daikin/__init__.py @@ -81,25 +81,18 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry): if not daikin_api: return False hass.data.setdefault(DOMAIN, {}).update({entry.entry_id: daikin_api}) - for platform in PLATFORMS: - hass.async_create_task( - hass.config_entries.async_forward_entry_setup(entry, platform) - ) + hass.config_entries.async_setup_platforms(entry, PLATFORMS) return True -async def async_unload_entry(hass, config_entry): +async def async_unload_entry(hass, entry): """Unload a config entry.""" - await asyncio.wait( - [ - hass.config_entries.async_forward_entry_unload(config_entry, platform) - for platform in PLATFORMS - ] - ) - hass.data[DOMAIN].pop(config_entry.entry_id) - if not hass.data[DOMAIN]: - hass.data.pop(DOMAIN) - return True + unload_ok = await hass.config_entries.async_unload_platforms(entry, PLATFORMS) + if unload_ok: + hass.data[DOMAIN].pop(entry.entry_id) + if not hass.data[DOMAIN]: + hass.data.pop(DOMAIN) + return unload_ok async def daikin_api_setup(hass, host, key, uuid, password): diff --git a/homeassistant/components/deconz/gateway.py b/homeassistant/components/deconz/gateway.py index fa674727a80..8b057ab9e51 100644 --- a/homeassistant/components/deconz/gateway.py +++ b/homeassistant/components/deconz/gateway.py @@ -175,12 +175,7 @@ class DeconzGateway: except AuthenticationRequired as err: raise ConfigEntryAuthFailed from err - for platform in PLATFORMS: - self.hass.async_create_task( - self.hass.config_entries.async_forward_entry_setup( - self.config_entry, platform - ) - ) + self.hass.config_entries.async_setup_platforms(self.config_entry, PLATFORMS) await async_setup_events(self) @@ -250,10 +245,9 @@ class DeconzGateway: self.api.async_connection_status_callback = None self.api.close() - for platform in PLATFORMS: - await self.hass.config_entries.async_forward_entry_unload( - self.config_entry, platform - ) + await self.hass.config_entries.async_unload_platforms( + self.config_entry, PLATFORMS + ) async_unload_events(self) diff --git a/homeassistant/components/denonavr/__init__.py b/homeassistant/components/denonavr/__init__.py index fa4d1612697..76baf73c3e5 100644 --- a/homeassistant/components/denonavr/__init__.py +++ b/homeassistant/components/denonavr/__init__.py @@ -23,6 +23,7 @@ from .receiver import ConnectDenonAVR CONF_RECEIVER = "receiver" UNDO_UPDATE_LISTENER = "undo_update_listener" +PLATFORMS = ["media_player"] _LOGGER = logging.getLogger(__name__) @@ -56,9 +57,7 @@ async def async_setup_entry( UNDO_UPDATE_LISTENER: undo_listener, } - hass.async_create_task( - hass.config_entries.async_forward_entry_setup(entry, "media_player") - ) + hass.config_entries.async_setup_platforms(entry, PLATFORMS) return True @@ -67,8 +66,8 @@ async def async_unload_entry( hass: core.HomeAssistant, config_entry: config_entries.ConfigEntry ): """Unload a config entry.""" - unload_ok = await hass.config_entries.async_forward_entry_unload( - config_entry, "media_player" + unload_ok = await hass.config_entries.async_unload_platforms( + config_entry, PLATFORMS ) hass.data[DOMAIN][config_entry.entry_id][UNDO_UPDATE_LISTENER]() diff --git a/homeassistant/components/devolo_home_control/__init__.py b/homeassistant/components/devolo_home_control/__init__.py index a6918e81998..ded30d75de9 100644 --- a/homeassistant/components/devolo_home_control/__init__.py +++ b/homeassistant/components/devolo_home_control/__init__.py @@ -58,10 +58,7 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool: except GatewayOfflineError as err: raise ConfigEntryNotReady from err - for platform in PLATFORMS: - hass.async_create_task( - hass.config_entries.async_forward_entry_setup(entry, platform) - ) + hass.config_entries.async_setup_platforms(entry, PLATFORMS) def shutdown(event): for gateway in hass.data[DOMAIN][entry.entry_id]["gateways"]: @@ -79,14 +76,7 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool: async def async_unload_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool: """Unload a config entry.""" - unload = all( - await asyncio.gather( - *[ - hass.config_entries.async_forward_entry_unload(entry, platform) - for platform in PLATFORMS - ] - ) - ) + unload = await hass.config_entries.async_unload_platforms(entry, PLATFORMS) await asyncio.gather( *[ hass.async_add_executor_job(gateway.websocket_disconnect) diff --git a/homeassistant/components/dexcom/__init__.py b/homeassistant/components/dexcom/__init__.py index 1630d4b9dfd..1c02a86ca42 100644 --- a/homeassistant/components/dexcom/__init__.py +++ b/homeassistant/components/dexcom/__init__.py @@ -1,5 +1,4 @@ """The Dexcom integration.""" -import asyncio from datetime import timedelta import logging @@ -67,24 +66,14 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry): COORDINATOR ].async_config_entry_first_refresh() - for platform in PLATFORMS: - hass.async_create_task( - hass.config_entries.async_forward_entry_setup(entry, platform) - ) + hass.config_entries.async_setup_platforms(entry, PLATFORMS) return True async def async_unload_entry(hass: HomeAssistant, entry: ConfigEntry): """Unload a config entry.""" - unload_ok = all( - await asyncio.gather( - *[ - hass.config_entries.async_forward_entry_unload(entry, platform) - for platform in PLATFORMS - ] - ) - ) + unload_ok = await hass.config_entries.async_unload_platforms(entry, PLATFORMS) hass.data[DOMAIN][entry.entry_id][UNDO_UPDATE_LISTENER]() if unload_ok: diff --git a/homeassistant/components/directv/__init__.py b/homeassistant/components/directv/__init__.py index f1f05e815a8..45f4eeeda37 100644 --- a/homeassistant/components/directv/__init__.py +++ b/homeassistant/components/directv/__init__.py @@ -1,7 +1,6 @@ """The DirecTV integration.""" from __future__ import annotations -import asyncio from datetime import timedelta from typing import Any @@ -42,25 +41,14 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool: hass.data.setdefault(DOMAIN, {}) hass.data[DOMAIN][entry.entry_id] = dtv - for platform in PLATFORMS: - hass.async_create_task( - hass.config_entries.async_forward_entry_setup(entry, platform) - ) + hass.config_entries.async_setup_platforms(entry, PLATFORMS) return True async def async_unload_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool: """Unload a config entry.""" - unload_ok = all( - await asyncio.gather( - *[ - hass.config_entries.async_forward_entry_unload(entry, platform) - for platform in PLATFORMS - ] - ) - ) - + unload_ok = await hass.config_entries.async_unload_platforms(entry, PLATFORMS) if unload_ok: hass.data[DOMAIN].pop(entry.entry_id) diff --git a/homeassistant/components/doorbird/__init__.py b/homeassistant/components/doorbird/__init__.py index 3e8e59df203..9a21c1b3439 100644 --- a/homeassistant/components/doorbird/__init__.py +++ b/homeassistant/components/doorbird/__init__.py @@ -1,5 +1,4 @@ """Support for DoorBird devices.""" -import asyncio import logging from aiohttp import web @@ -167,10 +166,7 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry): UNDO_UPDATE_LISTENER: undo_listener, } - for platform in PLATFORMS: - hass.async_create_task( - hass.config_entries.async_forward_entry_setup(entry, platform) - ) + hass.config_entries.async_setup_platforms(entry, PLATFORMS) return True @@ -184,14 +180,7 @@ async def async_unload_entry(hass: HomeAssistant, entry: ConfigEntry): hass.data[DOMAIN][entry.entry_id][UNDO_UPDATE_LISTENER]() - unload_ok = all( - await asyncio.gather( - *[ - hass.config_entries.async_forward_entry_unload(entry, platform) - for platform in PLATFORMS - ] - ) - ) + unload_ok = await hass.config_entries.async_unload_platforms(entry, PLATFORMS) if unload_ok: hass.data[DOMAIN].pop(entry.entry_id) diff --git a/homeassistant/components/dsmr/__init__.py b/homeassistant/components/dsmr/__init__.py index f130f500545..3af620df19c 100644 --- a/homeassistant/components/dsmr/__init__.py +++ b/homeassistant/components/dsmr/__init__.py @@ -1,5 +1,4 @@ """The dsmr component.""" -import asyncio from asyncio import CancelledError from contextlib import suppress @@ -14,10 +13,7 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry): hass.data.setdefault(DOMAIN, {}) hass.data[DOMAIN][entry.entry_id] = {} - for platform in PLATFORMS: - hass.async_create_task( - hass.config_entries.async_forward_entry_setup(entry, platform) - ) + hass.config_entries.async_setup_platforms(entry, PLATFORMS) listener = entry.add_update_listener(async_update_options) hass.data[DOMAIN][entry.entry_id][DATA_LISTENER] = listener @@ -35,14 +31,7 @@ async def async_unload_entry(hass: HomeAssistant, entry: ConfigEntry): with suppress(CancelledError): await task - unload_ok = all( - await asyncio.gather( - *[ - hass.config_entries.async_forward_entry_unload(entry, platform) - for platform in PLATFORMS - ] - ) - ) + unload_ok = await hass.config_entries.async_unload_platforms(entry, PLATFORMS) if unload_ok: listener() diff --git a/homeassistant/components/dunehd/__init__.py b/homeassistant/components/dunehd/__init__.py index 10c66c3bfb0..af81b60b38e 100644 --- a/homeassistant/components/dunehd/__init__.py +++ b/homeassistant/components/dunehd/__init__.py @@ -1,6 +1,4 @@ """The Dune HD component.""" -import asyncio - from pdunehd import DuneHDPlayer from homeassistant.const import CONF_HOST @@ -10,35 +8,24 @@ from .const import DOMAIN PLATFORMS = ["media_player"] -async def async_setup_entry(hass, config_entry): +async def async_setup_entry(hass, entry): """Set up a config entry.""" - host = config_entry.data[CONF_HOST] + host = entry.data[CONF_HOST] player = DuneHDPlayer(host) hass.data.setdefault(DOMAIN, {}) - hass.data[DOMAIN][config_entry.entry_id] = player + hass.data[DOMAIN][entry.entry_id] = player - for platform in PLATFORMS: - hass.async_create_task( - hass.config_entries.async_forward_entry_setup(config_entry, platform) - ) + hass.config_entries.async_setup_platforms(entry, PLATFORMS) return True -async def async_unload_entry(hass, config_entry): +async def async_unload_entry(hass, entry): """Unload a config entry.""" - unload_ok = all( - await asyncio.gather( - *[ - hass.config_entries.async_forward_entry_unload(config_entry, platform) - for platform in PLATFORMS - ] - ) - ) - + unload_ok = await hass.config_entries.async_unload_platforms(entry, PLATFORMS) if unload_ok: - hass.data[DOMAIN].pop(config_entry.entry_id) + hass.data[DOMAIN].pop(entry.entry_id) return unload_ok diff --git a/homeassistant/components/dynalite/__init__.py b/homeassistant/components/dynalite/__init__.py index 92392e4b51a..1ee609961cc 100644 --- a/homeassistant/components/dynalite/__init__.py +++ b/homeassistant/components/dynalite/__init__.py @@ -1,7 +1,6 @@ """Support for the Dynalite networks.""" from __future__ import annotations -import asyncio from typing import Any import voluptuous as vol @@ -267,17 +266,14 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool: bridge = DynaliteBridge(hass, entry.data) # need to do it before the listener hass.data[DOMAIN][entry.entry_id] = bridge - entry.add_update_listener(async_entry_changed) + entry.async_on_unload(entry.add_update_listener(async_entry_changed)) if not await bridge.async_setup(): LOGGER.error("Could not set up bridge for entry %s", entry.data) hass.data[DOMAIN][entry.entry_id] = None raise ConfigEntryNotReady - for platform in PLATFORMS: - hass.async_create_task( - hass.config_entries.async_forward_entry_setup(entry, platform) - ) + hass.config_entries.async_setup_platforms(entry, PLATFORMS) return True @@ -285,10 +281,7 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool: async def async_unload_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool: """Unload a config entry.""" LOGGER.debug("Unloading entry %s", entry.data) - hass.data[DOMAIN].pop(entry.entry_id) - tasks = [ - hass.config_entries.async_forward_entry_unload(entry, platform) - for platform in PLATFORMS - ] - results = await asyncio.gather(*tasks) - return False not in results + unload_ok = await hass.config_entries.async_unload_platforms(entry, PLATFORMS) + if unload_ok: + hass.data[DOMAIN].pop(entry.entry_id) + return unload_ok diff --git a/homeassistant/components/eafm/__init__.py b/homeassistant/components/eafm/__init__.py index f0ce5128624..7d2853266ff 100644 --- a/homeassistant/components/eafm/__init__.py +++ b/homeassistant/components/eafm/__init__.py @@ -2,22 +2,16 @@ from .const import DOMAIN - -async def async_setup(hass, config): - """Set up devices.""" - hass.data[DOMAIN] = {} - return True +PLATFORMS = ["sensor"] async def async_setup_entry(hass, entry): """Set up flood monitoring sensors for this config entry.""" - hass.async_create_task( - hass.config_entries.async_forward_entry_setup(entry, "sensor") - ) - + hass.data.setdefault(DOMAIN, {}) + hass.config_entries.async_setup_platforms(entry, PLATFORMS) return True -async def async_unload_entry(hass, config_entry): +async def async_unload_entry(hass, entry): """Unload flood monitoring sensors.""" - return await hass.config_entries.async_forward_entry_unload(config_entry, "sensor") + return await hass.config_entries.async_unload_platforms(entry, PLATFORMS) diff --git a/homeassistant/components/ecobee/__init__.py b/homeassistant/components/ecobee/__init__.py index 015ee1fbf6c..28aec51e81f 100644 --- a/homeassistant/components/ecobee/__init__.py +++ b/homeassistant/components/ecobee/__init__.py @@ -1,5 +1,4 @@ """Support for ecobee.""" -import asyncio from datetime import timedelta from pyecobee import ECOBEE_API_KEY, ECOBEE_REFRESH_TOKEN, Ecobee, ExpiredTokenError @@ -60,10 +59,7 @@ async def async_setup_entry(hass, entry): hass.data[DOMAIN] = data - for platform in PLATFORMS: - hass.async_create_task( - hass.config_entries.async_forward_entry_setup(entry, platform) - ) + hass.config_entries.async_setup_platforms(entry, PLATFORMS) return True @@ -109,14 +105,9 @@ class EcobeeData: return False -async def async_unload_entry(hass, config_entry): +async def async_unload_entry(hass, entry): """Unload the config entry and platforms.""" - hass.data.pop(DOMAIN) - - tasks = [] - for platform in PLATFORMS: - tasks.append( - hass.config_entries.async_forward_entry_unload(config_entry, platform) - ) - - return all(await asyncio.gather(*tasks)) + unload_ok = await hass.config_entries.async_unload_platforms(entry, PLATFORMS) + if unload_ok: + hass.data.pop(DOMAIN) + return unload_ok diff --git a/homeassistant/components/econet/__init__.py b/homeassistant/components/econet/__init__.py index e605b16a237..5a20337e454 100644 --- a/homeassistant/components/econet/__init__.py +++ b/homeassistant/components/econet/__init__.py @@ -1,5 +1,4 @@ """Support for EcoNet products.""" -import asyncio from datetime import timedelta import logging @@ -62,10 +61,7 @@ async def async_setup_entry(hass, config_entry): hass.data[DOMAIN][API_CLIENT][config_entry.entry_id] = api hass.data[DOMAIN][EQUIPMENT][config_entry.entry_id] = equipment - for platform in PLATFORMS: - hass.async_create_task( - hass.config_entries.async_forward_entry_setup(config_entry, platform) - ) + hass.config_entries.async_setup_platforms(config_entry, PLATFORMS) api.subscribe() @@ -88,25 +84,21 @@ async def async_setup_entry(hass, config_entry): """Fetch the latest changes from the API.""" await api.refresh_equipment() - async_track_time_interval(hass, resubscribe, INTERVAL) - async_track_time_interval(hass, fetch_update, INTERVAL + timedelta(minutes=1)) + config_entry.async_on_unload(async_track_time_interval(hass, resubscribe, INTERVAL)) + config_entry.async_on_unload( + async_track_time_interval(hass, fetch_update, INTERVAL + timedelta(minutes=1)) + ) return True async def async_unload_entry(hass, entry): """Unload a EcoNet config entry.""" - tasks = [ - hass.config_entries.async_forward_entry_unload(entry, platform) - for platform in PLATFORMS - ] - - await asyncio.gather(*tasks) - - hass.data[DOMAIN][API_CLIENT].pop(entry.entry_id) - hass.data[DOMAIN][EQUIPMENT].pop(entry.entry_id) - - return True + unload_ok = await hass.config_entries.async_unload_platforms(entry, PLATFORMS) + if unload_ok: + hass.data[DOMAIN][API_CLIENT].pop(entry.entry_id) + hass.data[DOMAIN][EQUIPMENT].pop(entry.entry_id) + return unload_ok class EcoNetEntity(Entity): diff --git a/homeassistant/components/elgato/__init__.py b/homeassistant/components/elgato/__init__.py index 22d60406780..1c83844debc 100644 --- a/homeassistant/components/elgato/__init__.py +++ b/homeassistant/components/elgato/__init__.py @@ -12,6 +12,8 @@ from homeassistant.helpers.aiohttp_client import async_get_clientsession from .const import DATA_ELGATO_CLIENT, DOMAIN +PLATFORMS = [LIGHT_DOMAIN] + async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool: """Set up Elgato Key Light from a config entry.""" @@ -31,10 +33,7 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool: hass.data.setdefault(DOMAIN, {}) hass.data[DOMAIN][entry.entry_id] = {DATA_ELGATO_CLIENT: elgato} - - hass.async_create_task( - hass.config_entries.async_forward_entry_setup(entry, LIGHT_DOMAIN) - ) + hass.config_entries.async_setup_platforms(entry, PLATFORMS) return True @@ -42,11 +41,10 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool: async def async_unload_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool: """Unload Elgato Key Light config entry.""" # Unload entities for this entry/device. - await hass.config_entries.async_forward_entry_unload(entry, LIGHT_DOMAIN) - - # Cleanup - del hass.data[DOMAIN][entry.entry_id] - if not hass.data[DOMAIN]: - del hass.data[DOMAIN] - - return True + unload_ok = await hass.config_entries.async_unload_platforms(entry, PLATFORMS) + if unload_ok: + # Cleanup + del hass.data[DOMAIN][entry.entry_id] + if not hass.data[DOMAIN]: + del hass.data[DOMAIN] + return unload_ok diff --git a/homeassistant/components/elkm1/__init__.py b/homeassistant/components/elkm1/__init__.py index 568b3109227..ff2f2533d24 100644 --- a/homeassistant/components/elkm1/__init__.py +++ b/homeassistant/components/elkm1/__init__.py @@ -262,10 +262,7 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry): "keypads": {}, } - for platform in PLATFORMS: - hass.async_create_task( - hass.config_entries.async_forward_entry_setup(entry, platform) - ) + hass.config_entries.async_setup_platforms(entry, PLATFORMS) return True @@ -286,14 +283,7 @@ def _find_elk_by_prefix(hass, prefix): async def async_unload_entry(hass: HomeAssistant, entry: ConfigEntry): """Unload a config entry.""" - unload_ok = all( - await asyncio.gather( - *[ - hass.config_entries.async_forward_entry_unload(entry, platform) - for platform in PLATFORMS - ] - ) - ) + unload_ok = await hass.config_entries.async_unload_platforms(entry, PLATFORMS) # disconnect cleanly hass.data[DOMAIN][entry.entry_id]["elk"].disconnect() diff --git a/homeassistant/components/emonitor/__init__.py b/homeassistant/components/emonitor/__init__.py index 74630a193a4..516f38d64c2 100644 --- a/homeassistant/components/emonitor/__init__.py +++ b/homeassistant/components/emonitor/__init__.py @@ -1,5 +1,4 @@ """The SiteSage Emonitor integration.""" -import asyncio from datetime import timedelta import logging @@ -38,27 +37,16 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry): hass.data.setdefault(DOMAIN, {})[entry.entry_id] = coordinator - for platform in PLATFORMS: - hass.async_create_task( - hass.config_entries.async_forward_entry_setup(entry, platform) - ) + hass.config_entries.async_setup_platforms(entry, PLATFORMS) return True async def async_unload_entry(hass: HomeAssistant, entry: ConfigEntry): """Unload a config entry.""" - unload_ok = all( - await asyncio.gather( - *[ - hass.config_entries.async_forward_entry_unload(entry, platform) - for platform in PLATFORMS - ] - ) - ) + unload_ok = await hass.config_entries.async_unload_platforms(entry, PLATFORMS) if unload_ok: hass.data[DOMAIN].pop(entry.entry_id) - return unload_ok diff --git a/homeassistant/components/enphase_envoy/__init__.py b/homeassistant/components/enphase_envoy/__init__.py index 26318faa7f9..dfd6b782408 100644 --- a/homeassistant/components/enphase_envoy/__init__.py +++ b/homeassistant/components/enphase_envoy/__init__.py @@ -1,7 +1,6 @@ """The Enphase Envoy integration.""" from __future__ import annotations -import asyncio from datetime import timedelta import logging @@ -79,25 +78,14 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool: NAME: name, } - for platform in PLATFORMS: - hass.async_create_task( - hass.config_entries.async_forward_entry_setup(entry, platform) - ) + hass.config_entries.async_setup_platforms(entry, PLATFORMS) return True async def async_unload_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool: """Unload a config entry.""" - unload_ok = all( - await asyncio.gather( - *[ - hass.config_entries.async_forward_entry_unload(entry, platform) - for platform in PLATFORMS - ] - ) - ) + unload_ok = await hass.config_entries.async_unload_platforms(entry, PLATFORMS) if unload_ok: hass.data[DOMAIN].pop(entry.entry_id) - return unload_ok diff --git a/homeassistant/components/epson/__init__.py b/homeassistant/components/epson/__init__.py index 94254f64f88..b560151e058 100644 --- a/homeassistant/components/epson/__init__.py +++ b/homeassistant/components/epson/__init__.py @@ -1,5 +1,4 @@ """The epson integration.""" -import asyncio import logging from epson_projector import Projector @@ -43,23 +42,14 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry): return False hass.data.setdefault(DOMAIN, {}) hass.data[DOMAIN][entry.entry_id] = projector - for platform in PLATFORMS: - hass.async_create_task( - hass.config_entries.async_forward_entry_setup(entry, platform) - ) + hass.config_entries.async_setup_platforms(entry, PLATFORMS) + return True async def async_unload_entry(hass: HomeAssistant, entry: ConfigEntry): """Unload a config entry.""" - unload_ok = all( - await asyncio.gather( - *[ - hass.config_entries.async_forward_entry_unload(entry, platform) - for platform in PLATFORMS - ] - ) - ) + unload_ok = await hass.config_entries.async_unload_platforms(entry, PLATFORMS) if unload_ok: hass.data[DOMAIN].pop(entry.entry_id) return unload_ok diff --git a/homeassistant/components/esphome/__init__.py b/homeassistant/components/esphome/__init__.py index 8edb6d79bcd..66b16cf3fe3 100644 --- a/homeassistant/components/esphome/__init__.py +++ b/homeassistant/components/esphome/__init__.py @@ -594,12 +594,9 @@ async def _cleanup_instance( async def async_unload_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool: """Unload an esphome config entry.""" entry_data = await _cleanup_instance(hass, entry) - tasks = [] - for platform in entry_data.loaded_platforms: - tasks.append(hass.config_entries.async_forward_entry_unload(entry, platform)) - if tasks: - await asyncio.wait(tasks) - return True + return await hass.config_entries.async_unload_platforms( + entry, entry_data.loaded_platforms + ) async def platform_async_setup_entry( diff --git a/homeassistant/components/ezviz/__init__.py b/homeassistant/components/ezviz/__init__.py index 7619d83e27b..670e07a07dc 100644 --- a/homeassistant/components/ezviz/__init__.py +++ b/homeassistant/components/ezviz/__init__.py @@ -1,5 +1,4 @@ """Support for Ezviz camera.""" -import asyncio from datetime import timedelta import logging @@ -82,10 +81,7 @@ async def async_setup_entry(hass, entry): DATA_COORDINATOR: coordinator, DATA_UNDO_UPDATE_LISTENER: undo_listener, } - for component in PLATFORMS: - hass.async_create_task( - hass.config_entries.async_forward_entry_setup(entry, component) - ) + hass.config_entries.async_setup_platforms(entry, PLATFORMS) return True @@ -96,19 +92,10 @@ async def async_unload_entry(hass, entry): if entry.data.get(CONF_TYPE) == ATTR_TYPE_CAMERA: return True - unload_ok = all( - await asyncio.gather( - *[ - hass.config_entries.async_forward_entry_unload(entry, component) - for component in PLATFORMS - ] - ) - ) - + unload_ok = await hass.config_entries.async_unload_platforms(entry, PLATFORMS) if unload_ok: hass.data[DOMAIN][entry.entry_id][DATA_UNDO_UPDATE_LISTENER]() hass.data[DOMAIN].pop(entry.entry_id) - return unload_ok diff --git a/homeassistant/components/faa_delays/__init__.py b/homeassistant/components/faa_delays/__init__.py index 6db9b667526..56cf9ad13bc 100644 --- a/homeassistant/components/faa_delays/__init__.py +++ b/homeassistant/components/faa_delays/__init__.py @@ -1,5 +1,4 @@ """The FAA Delays integration.""" -import asyncio from datetime import timedelta import logging @@ -30,27 +29,16 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry): hass.data.setdefault(DOMAIN, {}) hass.data[DOMAIN][entry.entry_id] = coordinator - for platform in PLATFORMS: - hass.async_create_task( - hass.config_entries.async_forward_entry_setup(entry, platform) - ) + hass.config_entries.async_setup_platforms(entry, PLATFORMS) return True async def async_unload_entry(hass: HomeAssistant, entry: ConfigEntry): """Unload a config entry.""" - unload_ok = all( - await asyncio.gather( - *[ - hass.config_entries.async_forward_entry_unload(entry, platform) - for platform in PLATFORMS - ] - ) - ) + unload_ok = await hass.config_entries.async_unload_platforms(entry, PLATFORMS) if unload_ok: hass.data[DOMAIN].pop(entry.entry_id) - return unload_ok diff --git a/homeassistant/components/fireservicerota/__init__.py b/homeassistant/components/fireservicerota/__init__.py index 0a4936b6ed6..aa10a16f088 100644 --- a/homeassistant/components/fireservicerota/__init__.py +++ b/homeassistant/components/fireservicerota/__init__.py @@ -1,5 +1,4 @@ """The FireServiceRota integration.""" -import asyncio from datetime import timedelta import logging @@ -59,10 +58,7 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool: DATA_COORDINATOR: coordinator, } - for platform in PLATFORMS: - hass.async_create_task( - hass.config_entries.async_forward_entry_setup(entry, platform) - ) + hass.config_entries.async_setup_platforms(entry, PLATFORMS) return True @@ -73,19 +69,9 @@ async def async_unload_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool: await hass.async_add_executor_job( hass.data[DOMAIN][entry.entry_id].websocket.stop_listener ) - - unload_ok = all( - await asyncio.gather( - *[ - hass.config_entries.async_forward_entry_unload(entry, platform) - for platform in PLATFORMS - ] - ) - ) - + unload_ok = await hass.config_entries.async_unload_platforms(entry, PLATFORMS) if unload_ok: del hass.data[DOMAIN][entry.entry_id] - return unload_ok diff --git a/homeassistant/components/flick_electric/__init__.py b/homeassistant/components/flick_electric/__init__.py index 04d7b88f52b..54167b6a55f 100644 --- a/homeassistant/components/flick_electric/__init__.py +++ b/homeassistant/components/flick_electric/__init__.py @@ -21,6 +21,8 @@ from .const import CONF_TOKEN_EXPIRES_IN, CONF_TOKEN_EXPIRY, DOMAIN CONF_ID_TOKEN = "id_token" +PLATFORMS = ["sensor"] + async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry): """Set up Flick Electric from a config entry.""" @@ -29,20 +31,17 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry): hass.data.setdefault(DOMAIN, {}) hass.data[DOMAIN][entry.entry_id] = FlickAPI(auth) - hass.async_create_task( - hass.config_entries.async_forward_entry_setup(entry, "sensor") - ) + hass.config_entries.async_setup_platforms(entry, PLATFORMS) return True async def async_unload_entry(hass: HomeAssistant, entry: ConfigEntry): """Unload a config entry.""" - if await hass.config_entries.async_forward_entry_unload(entry, "sensor"): + unload_ok = await hass.config_entries.async_unload_platforms(entry, PLATFORMS) + if unload_ok: hass.data[DOMAIN].pop(entry.entry_id) - return True - - return False + return unload_ok class HassFlickAuth(AbstractFlickAuth): diff --git a/homeassistant/components/flo/__init__.py b/homeassistant/components/flo/__init__.py index 4ea6d1dec93..890f18ee3b7 100644 --- a/homeassistant/components/flo/__init__.py +++ b/homeassistant/components/flo/__init__.py @@ -44,25 +44,14 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry): tasks = [device.async_refresh() for device in devices] await asyncio.gather(*tasks) - for platform in PLATFORMS: - hass.async_create_task( - hass.config_entries.async_forward_entry_setup(entry, platform) - ) + hass.config_entries.async_setup_platforms(entry, PLATFORMS) return True async def async_unload_entry(hass: HomeAssistant, entry: ConfigEntry): """Unload a config entry.""" - unload_ok = all( - await asyncio.gather( - *[ - hass.config_entries.async_forward_entry_unload(entry, platform) - for platform in PLATFORMS - ] - ) - ) + unload_ok = await hass.config_entries.async_unload_platforms(entry, PLATFORMS) if unload_ok: hass.data[DOMAIN].pop(entry.entry_id) - return unload_ok diff --git a/homeassistant/components/flume/__init__.py b/homeassistant/components/flume/__init__.py index 9acc5756023..c8e652fefd6 100644 --- a/homeassistant/components/flume/__init__.py +++ b/homeassistant/components/flume/__init__.py @@ -1,5 +1,4 @@ """The flume integration.""" -import asyncio from functools import partial import logging @@ -74,24 +73,14 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry): FLUME_HTTP_SESSION: http_session, } - for platform in PLATFORMS: - hass.async_create_task( - hass.config_entries.async_forward_entry_setup(entry, platform) - ) + hass.config_entries.async_setup_platforms(entry, PLATFORMS) return True async def async_unload_entry(hass: HomeAssistant, entry: ConfigEntry): """Unload a config entry.""" - unload_ok = all( - await asyncio.gather( - *[ - hass.config_entries.async_forward_entry_unload(entry, platform) - for platform in PLATFORMS - ] - ) - ) + unload_ok = await hass.config_entries.async_unload_platforms(entry, PLATFORMS) hass.data[DOMAIN][entry.entry_id][FLUME_HTTP_SESSION].close() diff --git a/homeassistant/components/flunearyou/__init__.py b/homeassistant/components/flunearyou/__init__.py index 8e5e3762f32..6eb4d54fe4f 100644 --- a/homeassistant/components/flunearyou/__init__.py +++ b/homeassistant/components/flunearyou/__init__.py @@ -31,15 +31,15 @@ async def async_setup(hass, config): return True -async def async_setup_entry(hass, config_entry): +async def async_setup_entry(hass, entry): """Set up Flu Near You as config entry.""" - hass.data[DOMAIN][DATA_COORDINATOR][config_entry.entry_id] = {} + hass.data[DOMAIN][DATA_COORDINATOR][entry.entry_id] = {} websession = aiohttp_client.async_get_clientsession(hass) client = Client(websession) - latitude = config_entry.data.get(CONF_LATITUDE, hass.config.latitude) - longitude = config_entry.data.get(CONF_LONGITUDE, hass.config.longitude) + latitude = entry.data.get(CONF_LATITUDE, hass.config.latitude) + longitude = entry.data.get(CONF_LONGITUDE, hass.config.longitude) async def async_update(api_category): """Get updated date from the API based on category.""" @@ -54,7 +54,7 @@ async def async_setup_entry(hass, config_entry): data_init_tasks = [] for api_category in [CATEGORY_CDC_REPORT, CATEGORY_USER_REPORT]: - coordinator = hass.data[DOMAIN][DATA_COORDINATOR][config_entry.entry_id][ + coordinator = hass.data[DOMAIN][DATA_COORDINATOR][entry.entry_id][ api_category ] = DataUpdateCoordinator( hass, @@ -67,25 +67,15 @@ async def async_setup_entry(hass, config_entry): await asyncio.gather(*data_init_tasks) - for platform in PLATFORMS: - hass.async_create_task( - hass.config_entries.async_forward_entry_setup(config_entry, platform) - ) + hass.config_entries.async_setup_platforms(entry, PLATFORMS) return True -async def async_unload_entry(hass, config_entry): +async def async_unload_entry(hass, entry): """Unload an Flu Near You config entry.""" - unload_ok = all( - await asyncio.gather( - *[ - hass.config_entries.async_forward_entry_unload(config_entry, platform) - for platform in PLATFORMS - ] - ) - ) + unload_ok = await hass.config_entries.async_unload_platforms(entry, PLATFORMS) if unload_ok: - hass.data[DOMAIN][DATA_COORDINATOR].pop(config_entry.entry_id) + hass.data[DOMAIN][DATA_COORDINATOR].pop(entry.entry_id) return unload_ok diff --git a/homeassistant/components/forked_daapd/__init__.py b/homeassistant/components/forked_daapd/__init__.py index 0186b18ee74..fc67d78d5ed 100644 --- a/homeassistant/components/forked_daapd/__init__.py +++ b/homeassistant/components/forked_daapd/__init__.py @@ -3,18 +3,18 @@ from homeassistant.components.media_player import DOMAIN as MP_DOMAIN from .const import DOMAIN, HASS_DATA_REMOVE_LISTENERS_KEY, HASS_DATA_UPDATER_KEY +PLATFORMS = [MP_DOMAIN] + async def async_setup_entry(hass, entry): """Set up forked-daapd from a config entry by forwarding to platform.""" - hass.async_create_task( - hass.config_entries.async_forward_entry_setup(entry, MP_DOMAIN) - ) + hass.config_entries.async_setup_platforms(entry, PLATFORMS) return True async def async_unload_entry(hass, entry): """Remove forked-daapd component.""" - status = await hass.config_entries.async_forward_entry_unload(entry, MP_DOMAIN) + status = await hass.config_entries.async_unload_platforms(entry, PLATFORMS) if status and hass.data.get(DOMAIN) and hass.data[DOMAIN].get(entry.entry_id): hass.data[DOMAIN][entry.entry_id][ HASS_DATA_UPDATER_KEY diff --git a/homeassistant/components/foscam/__init__.py b/homeassistant/components/foscam/__init__.py index 1b3ae5e7216..308b1a3cc9f 100644 --- a/homeassistant/components/foscam/__init__.py +++ b/homeassistant/components/foscam/__init__.py @@ -1,5 +1,4 @@ """The foscam component.""" -import asyncio from libpyfoscam import FoscamCamera @@ -14,19 +13,11 @@ from .const import CONF_RTSP_PORT, DOMAIN, LOGGER, SERVICE_PTZ, SERVICE_PTZ_PRES PLATFORMS = ["camera"] -async def async_setup(hass: HomeAssistant, config: dict): - """Set up the foscam component.""" - hass.data.setdefault(DOMAIN, {}) - return True - - async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry): """Set up foscam from a config entry.""" - for platform in PLATFORMS: - hass.async_create_task( - hass.config_entries.async_forward_entry_setup(entry, platform) - ) + hass.config_entries.async_setup_platforms(entry, PLATFORMS) + hass.data.setdefault(DOMAIN, {}) hass.data[DOMAIN][entry.entry_id] = entry.data return True @@ -34,15 +25,7 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry): async def async_unload_entry(hass: HomeAssistant, entry: ConfigEntry): """Unload a config entry.""" - unload_ok = all( - await asyncio.gather( - *[ - hass.config_entries.async_forward_entry_unload(entry, platform) - for platform in PLATFORMS - ] - ) - ) - + unload_ok = await hass.config_entries.async_unload_platforms(entry, PLATFORMS) if unload_ok: hass.data[DOMAIN].pop(entry.entry_id) diff --git a/homeassistant/components/freebox/__init__.py b/homeassistant/components/freebox/__init__.py index 976041721c3..40e01db39d1 100644 --- a/homeassistant/components/freebox/__init__.py +++ b/homeassistant/components/freebox/__init__.py @@ -1,5 +1,4 @@ """Support for Freebox devices (Freebox v6 and Freebox mini 4K).""" -import asyncio import logging import voluptuous as vol @@ -45,10 +44,7 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry): hass.data.setdefault(DOMAIN, {}) hass.data[DOMAIN][entry.unique_id] = router - for platform in PLATFORMS: - hass.async_create_task( - hass.config_entries.async_forward_entry_setup(entry, platform) - ) + hass.config_entries.async_setup_platforms(entry, PLATFORMS) # Services async def async_reboot(call): @@ -70,14 +66,7 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry): async def async_unload_entry(hass: HomeAssistant, entry: ConfigEntry): """Unload a config entry.""" - unload_ok = all( - await asyncio.gather( - *[ - hass.config_entries.async_forward_entry_unload(entry, platform) - for platform in PLATFORMS - ] - ) - ) + unload_ok = await hass.config_entries.async_unload_platforms(entry, PLATFORMS) if unload_ok: router = hass.data[DOMAIN].pop(entry.unique_id) await router.close() diff --git a/homeassistant/components/fritz/__init__.py b/homeassistant/components/fritz/__init__.py index 6c8f54ea928..507804bb857 100644 --- a/homeassistant/components/fritz/__init__.py +++ b/homeassistant/components/fritz/__init__.py @@ -1,5 +1,4 @@ """Support for AVM Fritz!Box functions.""" -import asyncio import logging from fritzconnection.core.exceptions import FritzConnectionException, FritzSecurityError @@ -52,10 +51,7 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool: hass.bus.async_listen_once(EVENT_HOMEASSISTANT_STOP, _async_unload) ) # Load the other platforms like switch - for domain in PLATFORMS: - hass.async_create_task( - hass.config_entries.async_forward_entry_setup(entry, domain) - ) + hass.config_entries.async_setup_platforms(entry, PLATFORMS) return True @@ -65,14 +61,7 @@ async def async_unload_entry(hass: HomeAssistant, entry: ConfigType) -> bool: fritzbox: FritzBoxTools = hass.data[DOMAIN][entry.entry_id] fritzbox.async_unload() - unload_ok = all( - await asyncio.gather( - *[ - hass.config_entries.async_forward_entry_unload(entry, platform) - for platform in PLATFORMS - ] - ) - ) + unload_ok = await hass.config_entries.async_unload_platforms(entry, PLATFORMS) if unload_ok: hass.data[DOMAIN].pop(entry.entry_id) diff --git a/homeassistant/components/fritzbox/__init__.py b/homeassistant/components/fritzbox/__init__.py index b398a1ee775..16b005359e1 100644 --- a/homeassistant/components/fritzbox/__init__.py +++ b/homeassistant/components/fritzbox/__init__.py @@ -1,7 +1,6 @@ """Support for AVM Fritz!Box smarthome devices.""" from __future__ import annotations -import asyncio from datetime import timedelta from pyfritzhome import Fritzhome, FritzhomeDevice, LoginError @@ -80,10 +79,7 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool: await coordinator.async_config_entry_first_refresh() - for platform in PLATFORMS: - hass.async_create_task( - hass.config_entries.async_forward_entry_setup(entry, platform) - ) + hass.config_entries.async_setup_platforms(entry, PLATFORMS) def logout_fritzbox(event): """Close connections to this fritzbox.""" @@ -101,14 +97,7 @@ async def async_unload_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool: fritz = hass.data[DOMAIN][entry.entry_id][CONF_CONNECTIONS] await hass.async_add_executor_job(fritz.logout) - unload_ok = all( - await asyncio.gather( - *[ - hass.config_entries.async_forward_entry_unload(entry, platform) - for platform in PLATFORMS - ] - ) - ) + unload_ok = await hass.config_entries.async_unload_platforms(entry, PLATFORMS) if unload_ok: hass.data[DOMAIN].pop(entry.entry_id) diff --git a/homeassistant/components/fritzbox_callmonitor/__init__.py b/homeassistant/components/fritzbox_callmonitor/__init__.py index 0ba0de59849..4c36ee3ddfb 100644 --- a/homeassistant/components/fritzbox_callmonitor/__init__.py +++ b/homeassistant/components/fritzbox_callmonitor/__init__.py @@ -1,5 +1,4 @@ """The fritzbox_callmonitor integration.""" -from asyncio import gather import logging from fritzconnection.core.exceptions import FritzConnectionException, FritzSecurityError @@ -54,10 +53,7 @@ async def async_setup_entry(hass, config_entry): UNDO_UPDATE_LISTENER: undo_listener, } - for platform in PLATFORMS: - hass.async_create_task( - hass.config_entries.async_forward_entry_setup(config_entry, platform) - ) + hass.config_entries.async_setup_platforms(config_entry, PLATFORMS) return True @@ -65,13 +61,8 @@ async def async_setup_entry(hass, config_entry): async def async_unload_entry(hass, config_entry): """Unloading the fritzbox_callmonitor platforms.""" - unload_ok = all( - await gather( - *[ - hass.config_entries.async_forward_entry_unload(config_entry, platform) - for platform in PLATFORMS - ] - ) + unload_ok = await hass.config_entries.async_unload_platforms( + config_entry, PLATFORMS ) hass.data[DOMAIN][config_entry.entry_id][UNDO_UPDATE_LISTENER]() diff --git a/tests/components/foscam/test_config_flow.py b/tests/components/foscam/test_config_flow.py index 3b8910c4dbc..2f72000aaed 100644 --- a/tests/components/foscam/test_config_flow.py +++ b/tests/components/foscam/test_config_flow.py @@ -87,8 +87,6 @@ async def test_user_valid(hass): with patch( "homeassistant.components.foscam.config_flow.FoscamCamera", ) as mock_foscam_camera, patch( - "homeassistant.components.foscam.async_setup", return_value=True - ) as mock_setup, patch( "homeassistant.components.foscam.async_setup_entry", return_value=True, ) as mock_setup_entry: @@ -105,7 +103,6 @@ async def test_user_valid(hass): assert result["title"] == CAMERA_NAME assert result["data"] == VALID_CONFIG - assert len(mock_setup.mock_calls) == 1 assert len(mock_setup_entry.mock_calls) == 1 @@ -263,8 +260,6 @@ async def test_import_user_valid(hass): with patch( "homeassistant.components.foscam.config_flow.FoscamCamera", ) as mock_foscam_camera, patch( - "homeassistant.components.foscam.async_setup", return_value=True - ) as mock_setup, patch( "homeassistant.components.foscam.async_setup_entry", return_value=True, ) as mock_setup_entry: @@ -282,7 +277,6 @@ async def test_import_user_valid(hass): assert result["title"] == CAMERA_NAME assert result["data"] == VALID_CONFIG - assert len(mock_setup.mock_calls) == 1 assert len(mock_setup_entry.mock_calls) == 1 @@ -293,8 +287,6 @@ async def test_import_user_valid_with_name(hass): with patch( "homeassistant.components.foscam.config_flow.FoscamCamera", ) as mock_foscam_camera, patch( - "homeassistant.components.foscam.async_setup", return_value=True - ) as mock_setup, patch( "homeassistant.components.foscam.async_setup_entry", return_value=True, ) as mock_setup_entry: @@ -316,7 +308,6 @@ async def test_import_user_valid_with_name(hass): assert result["title"] == name assert result["data"] == VALID_CONFIG - assert len(mock_setup.mock_calls) == 1 assert len(mock_setup_entry.mock_calls) == 1