mirror of
https://github.com/home-assistant/core.git
synced 2025-07-21 20:27:08 +00:00
Start automations with eager tasks (#111568)
This commit is contained in:
parent
fb4e8a4f3b
commit
6a62a39456
@ -701,7 +701,7 @@ class AutomationEntity(BaseAutomationEntity, 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:
|
async def _async_enable_automation(self) -> None:
|
||||||
"""Start automation on startup."""
|
"""Start automation on startup."""
|
||||||
# Don't do anything if no longer enabled or already attached
|
# Don't do anything if no longer enabled or already attached
|
||||||
if not self._is_enabled or self._async_detach_triggers is not None:
|
if not self._is_enabled or self._async_detach_triggers is not None:
|
||||||
@ -709,6 +709,11 @@ class AutomationEntity(BaseAutomationEntity, RestoreEntity):
|
|||||||
|
|
||||||
self._async_detach_triggers = await self._async_attach_triggers(True)
|
self._async_detach_triggers = await self._async_attach_triggers(True)
|
||||||
|
|
||||||
|
@callback
|
||||||
|
def _async_create_enable_automation_task(self, event: Event) -> None:
|
||||||
|
"""Create a task to enable the automation."""
|
||||||
|
self.hass.async_create_task(self._async_enable_automation(), eager_start=True)
|
||||||
|
|
||||||
async def async_enable(self) -> None:
|
async def async_enable(self) -> None:
|
||||||
"""Enable this automation entity.
|
"""Enable this automation entity.
|
||||||
|
|
||||||
@ -726,7 +731,7 @@ class AutomationEntity(BaseAutomationEntity, RestoreEntity):
|
|||||||
return
|
return
|
||||||
|
|
||||||
self.hass.bus.async_listen_once(
|
self.hass.bus.async_listen_once(
|
||||||
EVENT_HOMEASSISTANT_STARTED, self._async_enable_automation
|
EVENT_HOMEASSISTANT_STARTED, self._async_create_enable_automation_task
|
||||||
)
|
)
|
||||||
self.async_write_ha_state()
|
self.async_write_ha_state()
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user