Avoid waiting for integration platforms in the parent integration (#112467)
This commit is contained in:
parent
87739bc072
commit
f3a9756f81
29 changed files with 126 additions and 5 deletions
|
@ -157,6 +157,7 @@ async def async_process_integration_platforms(
|
|||
platform_name: str,
|
||||
# Any = platform.
|
||||
process_platform: Callable[[HomeAssistant, str, Any], Awaitable[None] | None],
|
||||
wait_for_platforms: bool = False,
|
||||
) -> None:
|
||||
"""Process a specific platform for all current and future loaded integrations."""
|
||||
if DATA_INTEGRATION_PLATFORMS not in hass.data:
|
||||
|
@ -194,6 +195,36 @@ async def async_process_integration_platforms(
|
|||
if not top_level_components:
|
||||
return
|
||||
|
||||
# We create a task here for two reasons:
|
||||
#
|
||||
# 1. We want the integration that provides the integration platform to
|
||||
# not be delayed by waiting on each individual platform to be processed
|
||||
# since the import or the integration platforms themselves may have to
|
||||
# schedule I/O or executor jobs.
|
||||
#
|
||||
# 2. We want the behavior to be the same as if the integration that has
|
||||
# the integration platform is loaded after the platform is processed.
|
||||
#
|
||||
# We use hass.async_create_task instead of asyncio.create_task because
|
||||
# we want to make sure that startup waits for the task to complete.
|
||||
#
|
||||
future = hass.async_create_task(
|
||||
_async_process_integration_platforms(
|
||||
hass, platform_name, top_level_components.copy(), process_job
|
||||
),
|
||||
eager_start=True,
|
||||
)
|
||||
if wait_for_platforms:
|
||||
await future
|
||||
|
||||
|
||||
async def _async_process_integration_platforms(
|
||||
hass: HomeAssistant,
|
||||
platform_name: str,
|
||||
top_level_components: set[str],
|
||||
process_job: HassJob,
|
||||
) -> None:
|
||||
"""Process integration platforms for a component."""
|
||||
integrations = await async_get_integrations(hass, top_level_components)
|
||||
loaded_integrations: list[Integration] = [
|
||||
integration
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue