Initialize triggers eagerly (#112294)

Most of these will never suspend and do not need
to be scheduled as tasks on the event loop
This commit is contained in:
J. Nick Koston 2024-03-05 04:58:43 -10:00 committed by GitHub
parent dca7083026
commit 390f5822fe
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -28,6 +28,7 @@ from homeassistant.core import (
)
from homeassistant.exceptions import HomeAssistantError
from homeassistant.loader import IntegrationNotFound, async_get_integration
from homeassistant.util.async_ import create_eager_task
from .typing import ConfigType, TemplateVarsType
@ -305,7 +306,7 @@ async def async_initialize_triggers(
variables: TemplateVarsType = None,
) -> CALLBACK_TYPE | None:
"""Initialize triggers."""
triggers: list[Coroutine[Any, Any, CALLBACK_TYPE]] = []
triggers: list[asyncio.Task[CALLBACK_TYPE]] = []
for idx, conf in enumerate(trigger_config):
# Skip triggers that are not enabled
if not conf.get(CONF_ENABLED, True):
@ -325,8 +326,10 @@ async def async_initialize_triggers(
)
triggers.append(
platform.async_attach_trigger(
hass, conf, _trigger_action_wrapper(hass, action, conf), info
create_eager_task(
platform.async_attach_trigger(
hass, conf, _trigger_action_wrapper(hass, action, conf), info
)
)
)