Avoid calling async_get_component twice for each component being setup (#112096)
We already have the component so we can pass it to async_process_component_config to avoid having to look it up again
This commit is contained in:
parent
72efb3dab5
commit
9af12a0639
3 changed files with 17 additions and 15 deletions
|
@ -1430,6 +1430,7 @@ async def async_process_component_config( # noqa: C901
|
||||||
hass: HomeAssistant,
|
hass: HomeAssistant,
|
||||||
config: ConfigType,
|
config: ConfigType,
|
||||||
integration: Integration,
|
integration: Integration,
|
||||||
|
component: ComponentProtocol | None = None,
|
||||||
) -> IntegrationConfigInfo:
|
) -> IntegrationConfigInfo:
|
||||||
"""Check component configuration.
|
"""Check component configuration.
|
||||||
|
|
||||||
|
@ -1441,18 +1442,19 @@ async def async_process_component_config( # noqa: C901
|
||||||
integration_docs = integration.documentation
|
integration_docs = integration.documentation
|
||||||
config_exceptions: list[ConfigExceptionInfo] = []
|
config_exceptions: list[ConfigExceptionInfo] = []
|
||||||
|
|
||||||
try:
|
if not component:
|
||||||
component = await integration.async_get_component()
|
try:
|
||||||
except LOAD_EXCEPTIONS as exc:
|
component = await integration.async_get_component()
|
||||||
exc_info = ConfigExceptionInfo(
|
except LOAD_EXCEPTIONS as exc:
|
||||||
exc,
|
exc_info = ConfigExceptionInfo(
|
||||||
ConfigErrorTranslationKey.COMPONENT_IMPORT_ERR,
|
exc,
|
||||||
domain,
|
ConfigErrorTranslationKey.COMPONENT_IMPORT_ERR,
|
||||||
config,
|
domain,
|
||||||
integration_docs,
|
config,
|
||||||
)
|
integration_docs,
|
||||||
config_exceptions.append(exc_info)
|
)
|
||||||
return IntegrationConfigInfo(None, config_exceptions)
|
config_exceptions.append(exc_info)
|
||||||
|
return IntegrationConfigInfo(None, config_exceptions)
|
||||||
|
|
||||||
# Check if the integration has a custom config validator
|
# Check if the integration has a custom config validator
|
||||||
config_validator = None
|
config_validator = None
|
||||||
|
|
|
@ -299,7 +299,7 @@ async def _async_setup_component( # noqa: C901
|
||||||
return False
|
return False
|
||||||
|
|
||||||
integration_config_info = await conf_util.async_process_component_config(
|
integration_config_info = await conf_util.async_process_component_config(
|
||||||
hass, config, integration
|
hass, config, integration, component
|
||||||
)
|
)
|
||||||
conf_util.async_handle_component_errors(hass, integration_config_info, integration)
|
conf_util.async_handle_component_errors(hass, integration_config_info, integration)
|
||||||
processed_config = conf_util.async_drop_config_annotations(
|
processed_config = conf_util.async_drop_config_annotations(
|
||||||
|
|
|
@ -1075,11 +1075,11 @@ def assert_setup_component(count, domain=None):
|
||||||
"""
|
"""
|
||||||
config = {}
|
config = {}
|
||||||
|
|
||||||
async def mock_psc(hass, config_input, integration):
|
async def mock_psc(hass, config_input, integration, component=None):
|
||||||
"""Mock the prepare_setup_component to capture config."""
|
"""Mock the prepare_setup_component to capture config."""
|
||||||
domain_input = integration.domain
|
domain_input = integration.domain
|
||||||
integration_config_info = await async_process_component_config(
|
integration_config_info = await async_process_component_config(
|
||||||
hass, config_input, integration
|
hass, config_input, integration, component
|
||||||
)
|
)
|
||||||
res = integration_config_info.config
|
res = integration_config_info.config
|
||||||
config[domain_input] = None if res is None else res.get(domain_input)
|
config[domain_input] = None if res is None else res.get(domain_input)
|
||||||
|
|
Loading…
Add table
Reference in a new issue