1
0
mirror of https://github.com/home-assistant/core.git synced 2025-12-24 12:59:34 +00:00

Add config_entries.async_wait_component (#76980)

Co-authored-by: thecode <levyshay1@gmail.com>
This commit is contained in:
Erik Montnemery
2022-11-17 21:52:57 +01:00
committed by GitHub
parent e3749e0f76
commit 1a274adc28
11 changed files with 157 additions and 91 deletions

View File

@@ -29,11 +29,27 @@ ATTR_COMPONENT = "component"
BASE_PLATFORMS = {platform.value for platform in Platform}
# DATA_SETUP is a dict[str, asyncio.Task[bool]], indicating domains which are currently
# being setup or which failed to setup
# - Tasks are added to DATA_SETUP by `async_setup_component`, the key is the domain being setup
# and the Task is the `_async_setup_component` helper.
# - Tasks are removed from DATA_SETUP if setup was successful, that is, the task returned True
DATA_SETUP = "setup_tasks"
# DATA_SETUP_DONE is a dict [str, asyncio.Event], indicating components which will be setup
# - Events are added to DATA_SETUP_DONE during bootstrap by async_set_domains_to_be_loaded,
# the key is the domain which will be loaded
# - Events are set and removed from DATA_SETUP_DONE when async_setup_component is finished,
# regardless of if the setup was successful or not.
DATA_SETUP_DONE = "setup_done"
# DATA_SETUP_DONE is a dict [str, datetime], indicating when an attempt to setup a component
# started
DATA_SETUP_STARTED = "setup_started"
# DATA_SETUP_TIME is a dict [str, timedelta], indicating how time was spent setting up a component
DATA_SETUP_TIME = "setup_time"
DATA_SETUP = "setup_tasks"
DATA_DEPS_REQS = "deps_reqs_processed"
SLOW_SETUP_WARNING = 10
@@ -44,7 +60,9 @@ SLOW_SETUP_MAX_WAIT = 300
def async_set_domains_to_be_loaded(hass: core.HomeAssistant, domains: set[str]) -> None:
"""Set domains that are going to be loaded from the config.
This will allow us to properly handle after_dependencies.
This allow us to:
- Properly handle after_dependencies.
- Keep track of domains which will load but have not yet finished loading
"""
hass.data[DATA_SETUP_DONE] = {domain: asyncio.Event() for domain in domains}
@@ -265,7 +283,7 @@ async def _async_setup_component(
await asyncio.sleep(0)
await hass.config_entries.flow.async_wait_init_flow_finish(domain)
# Add to components before the async_setup
# Add to components before the entry.async_setup
# call to avoid a deadlock when forwarding platforms
hass.config.components.add(domain)