Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions homeassistant/components/timer/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,11 @@ def should_poll(self):
"""If entity should be polled."""
return False

@property
def force_update(self) -> bool:
"""Return True to fix restart issues."""
return True

@property
def name(self):
"""Return name of the timer."""
Expand Down
42 changes: 42 additions & 0 deletions tests/components/timer/test_init.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
ATTR_ID,
ATTR_NAME,
CONF_ENTITY_ID,
EVENT_STATE_CHANGED,
SERVICE_RELOAD,
)
from homeassistant.core import Context, CoreState
Expand Down Expand Up @@ -406,6 +407,47 @@ def fake_event_listener(event):
assert len(results) == 4


async def test_state_changed_when_timer_restarted(hass):
"""Ensure timer's state changes when it restarted."""
hass.state = CoreState.starting

await async_setup_component(hass, DOMAIN, {DOMAIN: {"test1": {CONF_DURATION: 10}}})

state = hass.states.get("timer.test1")
assert state
assert state.state == STATUS_IDLE

results = []

def fake_event_listener(event):
"""Fake event listener for trigger."""
results.append(event)

hass.bus.async_listen(EVENT_STATE_CHANGED, fake_event_listener)

await hass.services.async_call(
DOMAIN, SERVICE_START, {CONF_ENTITY_ID: "timer.test1"}
)
await hass.async_block_till_done()
state = hass.states.get("timer.test1")
assert state
assert state.state == STATUS_ACTIVE

assert results[-1].event_type == EVENT_STATE_CHANGED
assert len(results) == 1

await hass.services.async_call(
DOMAIN, SERVICE_START, {CONF_ENTITY_ID: "timer.test1"}
)
await hass.async_block_till_done()
state = hass.states.get("timer.test1")
assert state
assert state.state == STATUS_ACTIVE

assert results[-1].event_type == EVENT_STATE_CHANGED
assert len(results) == 2


async def test_load_from_storage(hass, storage_setup):
"""Test set up from storage."""
assert await storage_setup()
Expand Down