From 913ee90e1ad9c33f0ab25e5bd8a308769dcd160c Mon Sep 17 00:00:00 2001 From: "J. Nick Koston" Date: Wed, 28 Feb 2024 01:46:32 -1000 Subject: [PATCH] Use eager tasks when updating entity state after service calls (#111702) In a multi-entity update case the state update may not need to suspend and can get executed without scheduling a task on the event loop --- homeassistant/helpers/service.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/homeassistant/helpers/service.py b/homeassistant/helpers/service.py index b170026f375..9feabbb45e2 100644 --- a/homeassistant/helpers/service.py +++ b/homeassistant/helpers/service.py @@ -43,6 +43,7 @@ from homeassistant.exceptions import ( UnknownUser, ) from homeassistant.loader import Integration, async_get_integrations, bind_hass +from homeassistant.util.async_ import create_eager_task from homeassistant.util.yaml import load_yaml_dict from homeassistant.util.yaml.loader import JSON_TYPE @@ -938,7 +939,7 @@ async def entity_service_call( # Context expires if the turn on commands took a long time. # Set context again so it's there when we update entity.async_set_context(call.context) - tasks.append(asyncio.create_task(entity.async_update_ha_state(True))) + tasks.append(create_eager_task(entity.async_update_ha_state(True))) if tasks: done, pending = await asyncio.wait(tasks)