Fix timer.cancel action fires timer.cancelled event even on canceled timers (#134507)
* Fixes https://github.com/home-assistant/core/issues/116105 * Fixes unit test in accordance to documentation Timer needs to be active before it can be canceled * Allow canceling of paused timers * Add test for canceling/finishing already canceled/finished timers * Add test for finishing a paused timer, this should not be possible * Revert finish related tests * Merge branch 'timer.cancelled_fix' of git@github.com:rrooggiieerr/homeassistant-core.git into timer.cancelled_fix --------- Co-authored-by: Franck Nijhof <git@frenck.dev>pull/137856/head^2
parent
8d5f927b42
commit
0ffbe076be
|
@ -374,6 +374,9 @@ class Timer(collection.CollectionEntity, RestoreEntity):
|
||||||
@callback
|
@callback
|
||||||
def async_cancel(self) -> None:
|
def async_cancel(self) -> None:
|
||||||
"""Cancel a timer."""
|
"""Cancel a timer."""
|
||||||
|
if self._state == STATUS_IDLE:
|
||||||
|
return
|
||||||
|
|
||||||
if self._listener:
|
if self._listener:
|
||||||
self._listener()
|
self._listener()
|
||||||
self._listener = None
|
self._listener = None
|
||||||
|
|
|
@ -196,6 +196,12 @@ async def test_methods_and_events(hass: HomeAssistant) -> None:
|
||||||
"event": EVENT_TIMER_CANCELLED,
|
"event": EVENT_TIMER_CANCELLED,
|
||||||
"data": {},
|
"data": {},
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
"call": SERVICE_CANCEL,
|
||||||
|
"state": STATUS_IDLE,
|
||||||
|
"event": None,
|
||||||
|
"data": {},
|
||||||
|
},
|
||||||
{
|
{
|
||||||
"call": SERVICE_START,
|
"call": SERVICE_START,
|
||||||
"state": STATUS_ACTIVE,
|
"state": STATUS_ACTIVE,
|
||||||
|
|
Loading…
Reference in New Issue