From 4d637e5f3032e77bf6402ceccd11308aa3ab035f Mon Sep 17 00:00:00 2001 From: "J. Nick Koston" Date: Mon, 31 Aug 2020 06:54:15 -0500 Subject: [PATCH] Skip setup of dependencies if they are already setup (#39482) after_dependencies were checking hass.config.components to see if something was already setup. We did not do the same for dependencies which resulted in trying to set them up more then once. Noticed when `homeassistant.setup` was set to debug logging and many integrations were announcing waiting on http when it was already setup. --- homeassistant/setup.py | 38 +++++++++++++++++++++++++++++--------- 1 file changed, 29 insertions(+), 9 deletions(-) diff --git a/homeassistant/setup.py b/homeassistant/setup.py index 870b476d605..818e28479fb 100644 --- a/homeassistant/setup.py +++ b/homeassistant/setup.py @@ -71,27 +71,47 @@ async def _async_process_dependencies( hass: core.HomeAssistant, config: ConfigType, integration: loader.Integration ) -> bool: """Ensure all dependencies are set up.""" - tasks = { + dependencies_tasks = { dep: hass.loop.create_task(async_setup_component(hass, dep, config)) for dep in integration.dependencies + if dep not in hass.config.components } + after_dependencies_tasks = dict() to_be_loaded = hass.data.get(DATA_SETUP_DONE, {}) for dep in integration.after_dependencies: - if dep in to_be_loaded and dep not in hass.config.components: - tasks[dep] = hass.loop.create_task(to_be_loaded[dep].wait()) + if ( + dep not in dependencies_tasks + and dep in to_be_loaded + and dep not in hass.config.components + ): + after_dependencies_tasks[dep] = hass.loop.create_task( + to_be_loaded[dep].wait() + ) - if not tasks: + if not dependencies_tasks and not after_dependencies_tasks: return True - _LOGGER.debug("Dependency %s will wait for %s", integration.domain, list(tasks)) + if dependencies_tasks: + _LOGGER.debug( + "Dependency %s will wait for dependencies %s", + integration.domain, + list(dependencies_tasks), + ) + if after_dependencies_tasks: + _LOGGER.debug( + "Dependency %s will wait for after dependencies %s", + integration.domain, + list(after_dependencies_tasks), + ) + async with hass.timeout.async_freeze(integration.domain): - results = await asyncio.gather(*tasks.values()) + results = await asyncio.gather( + *dependencies_tasks.values(), *after_dependencies_tasks.values() + ) failed = [ - domain - for idx, domain in enumerate(integration.dependencies) - if not results[idx] + domain for idx, domain in enumerate(dependencies_tasks) if not results[idx] ] if failed: