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:
parent
dca7083026
commit
390f5822fe
1 changed files with 6 additions and 3 deletions
|
@ -28,6 +28,7 @@ from homeassistant.core import (
|
||||||
)
|
)
|
||||||
from homeassistant.exceptions import HomeAssistantError
|
from homeassistant.exceptions import HomeAssistantError
|
||||||
from homeassistant.loader import IntegrationNotFound, async_get_integration
|
from homeassistant.loader import IntegrationNotFound, async_get_integration
|
||||||
|
from homeassistant.util.async_ import create_eager_task
|
||||||
|
|
||||||
from .typing import ConfigType, TemplateVarsType
|
from .typing import ConfigType, TemplateVarsType
|
||||||
|
|
||||||
|
@ -305,7 +306,7 @@ async def async_initialize_triggers(
|
||||||
variables: TemplateVarsType = None,
|
variables: TemplateVarsType = None,
|
||||||
) -> CALLBACK_TYPE | None:
|
) -> CALLBACK_TYPE | None:
|
||||||
"""Initialize triggers."""
|
"""Initialize triggers."""
|
||||||
triggers: list[Coroutine[Any, Any, CALLBACK_TYPE]] = []
|
triggers: list[asyncio.Task[CALLBACK_TYPE]] = []
|
||||||
for idx, conf in enumerate(trigger_config):
|
for idx, conf in enumerate(trigger_config):
|
||||||
# Skip triggers that are not enabled
|
# Skip triggers that are not enabled
|
||||||
if not conf.get(CONF_ENABLED, True):
|
if not conf.get(CONF_ENABLED, True):
|
||||||
|
@ -325,8 +326,10 @@ async def async_initialize_triggers(
|
||||||
)
|
)
|
||||||
|
|
||||||
triggers.append(
|
triggers.append(
|
||||||
platform.async_attach_trigger(
|
create_eager_task(
|
||||||
hass, conf, _trigger_action_wrapper(hass, action, conf), info
|
platform.async_attach_trigger(
|
||||||
|
hass, conf, _trigger_action_wrapper(hass, action, conf), info
|
||||||
|
)
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue