Simplify automation startup logic (#113122)
This commit is contained in:
parent
17b202d8cf
commit
1949b9936b
1 changed files with 4 additions and 7 deletions
|
@ -702,7 +702,7 @@ class AutomationEntity(BaseAutomationEntity, RestoreEntity):
|
|||
await super().async_will_remove_from_hass()
|
||||
await self.async_disable()
|
||||
|
||||
async def _async_enable_automation(self) -> None:
|
||||
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:
|
||||
|
@ -710,11 +710,6 @@ class AutomationEntity(BaseAutomationEntity, RestoreEntity):
|
|||
|
||||
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:
|
||||
"""Enable this automation entity.
|
||||
|
||||
|
@ -732,7 +727,9 @@ class AutomationEntity(BaseAutomationEntity, RestoreEntity):
|
|||
return
|
||||
|
||||
self.hass.bus.async_listen_once(
|
||||
EVENT_HOMEASSISTANT_STARTED, self._async_create_enable_automation_task
|
||||
EVENT_HOMEASSISTANT_STARTED,
|
||||
self._async_enable_automation,
|
||||
run_immediately=True,
|
||||
)
|
||||
self.async_write_ha_state()
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue