From 4f113f256fbadd3ce2c4e584e4b2644e5972c639 Mon Sep 17 00:00:00 2001 From: "J. Nick Koston" Date: Wed, 13 Mar 2024 18:23:25 -1000 Subject: [PATCH] Migrate script integration to create eager tasks (#113189) Along with #113183 the script execution may be able to synchronously without having to be scheduled on the event loop --- homeassistant/components/script/__init__.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/homeassistant/components/script/__init__.py b/homeassistant/components/script/__init__.py index 12abf51a925..2be2ce7b062 100644 --- a/homeassistant/components/script/__init__.py +++ b/homeassistant/components/script/__init__.py @@ -56,6 +56,7 @@ from homeassistant.helpers.service import async_set_service_schema from homeassistant.helpers.trace import trace_get, trace_path from homeassistant.helpers.typing import ConfigType from homeassistant.loader import bind_hass +from homeassistant.util.async_ import create_eager_task from homeassistant.util.dt import parse_datetime from .config import ScriptConfig @@ -227,7 +228,7 @@ async def async_setup(hass: HomeAssistant, config: ConfigType) -> bool: await asyncio.wait( [ - asyncio.create_task(script_entity.async_turn_off()) + create_eager_task(script_entity.async_turn_off()) for script_entity in script_entities ] ) @@ -576,7 +577,7 @@ class ScriptEntity(BaseScriptEntity, RestoreEntity): script_stack_cv.set([]) self._changed.clear() - self.hass.async_create_task(coro) + self.hass.async_create_task(coro, eager_start=True) # Wait for first state change so we can guarantee that # it is written to the State Machine before we return. await self._changed.wait()