mirror of
https://github.com/home-assistant/core.git
synced 2025-07-09 22:37:11 +00:00
Speed up creating automations (#93776)
Creating the inner coroutine for each automation to be run at started was expensive when the user had 1000s of automations
This commit is contained in:
parent
c129b4d0c2
commit
c25ccb90a4
@ -578,6 +578,14 @@ class AutomationEntity(ToggleEntity, RestoreEntity):
|
|||||||
await super().async_will_remove_from_hass()
|
await super().async_will_remove_from_hass()
|
||||||
await self.async_disable()
|
await self.async_disable()
|
||||||
|
|
||||||
|
async def _async_enable_automation(self, event: Event) -> None:
|
||||||
|
"""Start automation on startup."""
|
||||||
|
# Don't do anything if no longer enabled or already attached
|
||||||
|
if not self._is_enabled or self._async_detach_triggers is not None:
|
||||||
|
return
|
||||||
|
|
||||||
|
self._async_detach_triggers = await self._async_attach_triggers(True)
|
||||||
|
|
||||||
async def async_enable(self) -> None:
|
async def async_enable(self) -> None:
|
||||||
"""Enable this automation entity.
|
"""Enable this automation entity.
|
||||||
|
|
||||||
@ -594,16 +602,8 @@ class AutomationEntity(ToggleEntity, RestoreEntity):
|
|||||||
self.async_write_ha_state()
|
self.async_write_ha_state()
|
||||||
return
|
return
|
||||||
|
|
||||||
async def async_enable_automation(event: Event) -> None:
|
|
||||||
"""Start automation on startup."""
|
|
||||||
# Don't do anything if no longer enabled or already attached
|
|
||||||
if not self._is_enabled or self._async_detach_triggers is not None:
|
|
||||||
return
|
|
||||||
|
|
||||||
self._async_detach_triggers = await self._async_attach_triggers(True)
|
|
||||||
|
|
||||||
self.hass.bus.async_listen_once(
|
self.hass.bus.async_listen_once(
|
||||||
EVENT_HOMEASSISTANT_STARTED, async_enable_automation
|
EVENT_HOMEASSISTANT_STARTED, self._async_enable_automation
|
||||||
)
|
)
|
||||||
self.async_write_ha_state()
|
self.async_write_ha_state()
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user