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
This commit is contained in:
J. Nick Koston 2024-02-28 01:46:32 -10:00 committed by GitHub
parent 69a1da0a1a
commit 913ee90e1a
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -43,6 +43,7 @@ from homeassistant.exceptions import (
UnknownUser, UnknownUser,
) )
from homeassistant.loader import Integration, async_get_integrations, bind_hass 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 import load_yaml_dict
from homeassistant.util.yaml.loader import JSON_TYPE 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. # Context expires if the turn on commands took a long time.
# Set context again so it's there when we update # Set context again so it's there when we update
entity.async_set_context(call.context) 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: if tasks:
done, pending = await asyncio.wait(tasks) done, pending = await asyncio.wait(tasks)