Set automation last_triggered earlier (#35671)

Co-authored-by: Paulus Schoutsen <paulus@home-assistant.io>
This commit is contained in:
Bas Nijholt 2020-06-03 20:08:37 +02:00 committed by GitHub
parent eba5b50e58
commit dcb04acc65
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -389,6 +389,8 @@ class AutomationEntity(ToggleEntity, RestoreEntity):
trigger_context = Context(parent_id=parent_id)
self.async_set_context(trigger_context)
self._last_triggered = utcnow()
self.async_write_ha_state()
self.hass.bus.async_fire(
EVENT_AUTOMATION_TRIGGERED,
{ATTR_NAME: self._name, ATTR_ENTITY_ID: self.entity_id},
@ -402,9 +404,6 @@ class AutomationEntity(ToggleEntity, RestoreEntity):
except Exception: # pylint: disable=broad-except
pass
self._last_triggered = utcnow()
self.async_write_ha_state()
async def async_will_remove_from_hass(self):
"""Remove listeners when removing automation from Home Assistant."""
await super().async_will_remove_from_hass()