Reduce bootstrap code (#111450)
* Reduce bootstrap code Adds a SETUP_ORDER const dict which will be used for future refactoring * tweak * fix bad mergepull/111574/head^2
parent
587854fd59
commit
f08122084b
|
@ -157,6 +157,17 @@ CRITICAL_INTEGRATIONS = {
|
|||
"frontend",
|
||||
}
|
||||
|
||||
SETUP_ORDER = {
|
||||
# Load logging as soon as possible
|
||||
"logging": LOGGING_INTEGRATIONS,
|
||||
# Setup frontend
|
||||
"frontend": FRONTEND_INTEGRATIONS,
|
||||
# Setup recorder
|
||||
"recorder": RECORDER_INTEGRATIONS,
|
||||
# Start up debuggers. Start these first in case they want to wait.
|
||||
"debugger": DEBUGGER_INTEGRATIONS,
|
||||
}
|
||||
|
||||
|
||||
async def async_setup_hass(
|
||||
runtime_config: RuntimeConfig,
|
||||
|
@ -758,25 +769,10 @@ async def _async_set_up_integrations(
|
|||
if "recorder" in domains_to_setup:
|
||||
recorder.async_initialize_recorder(hass)
|
||||
|
||||
# Load logging as soon as possible
|
||||
if logging_domains := domains_to_setup & LOGGING_INTEGRATIONS:
|
||||
_LOGGER.info("Setting up logging: %s", logging_domains)
|
||||
await async_setup_multi_components(hass, logging_domains, config)
|
||||
|
||||
# Setup frontend
|
||||
if frontend_domains := domains_to_setup & FRONTEND_INTEGRATIONS:
|
||||
_LOGGER.info("Setting up frontend: %s", frontend_domains)
|
||||
await async_setup_multi_components(hass, frontend_domains, config)
|
||||
|
||||
# Setup recorder
|
||||
if recorder_domains := domains_to_setup & RECORDER_INTEGRATIONS:
|
||||
_LOGGER.info("Setting up recorder: %s", recorder_domains)
|
||||
await async_setup_multi_components(hass, recorder_domains, config)
|
||||
|
||||
# Start up debuggers. Start these first in case they want to wait.
|
||||
if debuggers := domains_to_setup & DEBUGGER_INTEGRATIONS:
|
||||
_LOGGER.debug("Setting up debuggers: %s", debuggers)
|
||||
await async_setup_multi_components(hass, debuggers, config)
|
||||
pre_stage_domains: dict[str, set[str]] = {
|
||||
name: domains_to_setup & domain_group
|
||||
for name, domain_group in SETUP_ORDER.items()
|
||||
}
|
||||
|
||||
# calculate what components to setup in what stage
|
||||
stage_1_domains: set[str] = set()
|
||||
|
@ -800,14 +796,13 @@ async def _async_set_up_integrations(
|
|||
|
||||
deps_promotion.update(dep_itg.all_dependencies)
|
||||
|
||||
stage_2_domains = (
|
||||
domains_to_setup
|
||||
- logging_domains
|
||||
- frontend_domains
|
||||
- recorder_domains
|
||||
- debuggers
|
||||
- stage_1_domains
|
||||
)
|
||||
stage_2_domains = domains_to_setup - stage_1_domains
|
||||
|
||||
for name, domain_group in pre_stage_domains.items():
|
||||
if domain_group:
|
||||
stage_2_domains -= domain_group
|
||||
_LOGGER.info("Setting up %s: %s", name, domain_group)
|
||||
await async_setup_multi_components(hass, domain_group, config)
|
||||
|
||||
# Enables after dependencies when setting up stage 1 domains
|
||||
async_set_domains_to_be_loaded(hass, stage_1_domains)
|
||||
|
|
Loading…
Reference in New Issue