diff --git a/homeassistant/components/timer/__init__.py b/homeassistant/components/timer/__init__.py index b0ade17b9c9..b472e94a5c3 100644 --- a/homeassistant/components/timer/__init__.py +++ b/homeassistant/components/timer/__init__.py @@ -389,13 +389,15 @@ class Timer(collection.CollectionEntity, RestoreEntity): @callback def async_finish(self) -> None: """Reset and updates the states, fire finished event.""" - if self._state != STATUS_ACTIVE or self._end is None: + if self._state == STATUS_IDLE: return if self._listener: self._listener() self._listener = None end = self._end + if end is None: + end = dt_util.utcnow().replace(microsecond=0) self._state = STATUS_IDLE self._end = None self._remaining = None diff --git a/tests/components/timer/test_init.py b/tests/components/timer/test_init.py index 95baa07eaa9..3e5ecc58b5a 100644 --- a/tests/components/timer/test_init.py +++ b/tests/components/timer/test_init.py @@ -208,6 +208,12 @@ async def test_methods_and_events(hass: HomeAssistant) -> None: "event": EVENT_TIMER_FINISHED, "data": {}, }, + { + "call": SERVICE_FINISH, + "state": STATUS_IDLE, + "event": None, + "data": {}, + }, { "call": SERVICE_START, "state": STATUS_ACTIVE, @@ -244,6 +250,18 @@ async def test_methods_and_events(hass: HomeAssistant) -> None: "event": EVENT_TIMER_RESTARTED, "data": {}, }, + { + "call": SERVICE_PAUSE, + "state": STATUS_PAUSED, + "event": EVENT_TIMER_PAUSED, + "data": {}, + }, + { + "call": SERVICE_FINISH, + "state": STATUS_IDLE, + "event": EVENT_TIMER_FINISHED, + "data": {}, + }, ] expected_events = 0