Avoid task creation when calling schedule_update_ha_state without force update (#91352)

This commit is contained in:
Franck Nijhof 2023-04-13 18:39:03 +02:00 committed by GitHub
parent 9e1a670e6e
commit 445b823232
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -698,10 +698,13 @@ class Entity(ABC):
If state is changed more than once before the ha state change task has If state is changed more than once before the ha state change task has
been executed, the intermediate state transitions will be missed. been executed, the intermediate state transitions will be missed.
""" """
self.hass.create_task( if force_refresh:
self.async_update_ha_state(force_refresh), self.hass.create_task(
f"Entity {self.entity_id} schedule update ha state", self.async_update_ha_state(force_refresh),
) f"Entity {self.entity_id} schedule update ha state",
)
else:
self.hass.loop.call_soon_threadsafe(self.async_write_ha_state)
@callback @callback
def async_schedule_update_ha_state(self, force_refresh: bool = False) -> None: def async_schedule_update_ha_state(self, force_refresh: bool = False) -> None: