From 390f5822fea1e4b99aaf8328e40db682fcbb55bd Mon Sep 17 00:00:00 2001 From: "J. Nick Koston" Date: Tue, 5 Mar 2024 04:58:43 -1000 Subject: [PATCH] Initialize triggers eagerly (#112294) Most of these will never suspend and do not need to be scheduled as tasks on the event loop --- homeassistant/helpers/trigger.py | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/homeassistant/helpers/trigger.py b/homeassistant/helpers/trigger.py index 2483806abc1..d98b24f9afd 100644 --- a/homeassistant/helpers/trigger.py +++ b/homeassistant/helpers/trigger.py @@ -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 + ) ) )