Skip to content

timer: timer.start doesn't restart the timer if already running #12013

Description

@jackwilsdon

Make sure you are running the latest version of Home Assistant before reporting an issue.

You should only file an issue if you found a bug. Feature and enhancement requests should go in the Feature Requests section of our community forum:

Home Assistant release (hass --version): 0.62.0

Python release (python3 --version): Python 3.6.3

Component/platform: timer

Description of problem: The timer does not restart if timer.start is called on a running timer.

Expected: The timer restarts.

Problem-relevant configuration.yaml entries and steps to reproduce:

frontend:

homeassistant:
  name: Home

http:

script:
  start_timer:
    alias: Start Timer
    sequence:
      - service: timer.start
        entity_id: timer.timer
  pause_timer:
    alias: Pause Timer
    sequence:
      - service: timer.pause
        entity_id: timer.timer
  cancel_timer:
    alias: Cancel Timer
    sequence:
      - service: timer.cancel
        entity_id: timer.timer
  finish_timer:
    alias: Finish Timer
    sequence:
      - service: timer.finish
        entity_id: timer.timer

timer:
  timer:
    duration: '00:01:00'
  1. Start the timer
  2. Wait a few seconds
  3. Press the start button again
  4. Observe that the timer hasn't restarted

Additional info:

I've done some investigation into this, and it seems to be due to the fact that the timer's state isn't changing, so HASS is discarding any changes made to the timer(?).

The logic to adjust the end time also isn't quite right.

This patch fixes the logic and also fixes the restart, however updating the state twice doesn't seem like the right way to do it.

index 84d2d3f34..b441e2380 100644
--- a/homeassistant/components/timer/__init__.py
+++ b/homeassistant/components/timer/__init__.py
@@ -249,17 +249,20 @@ class Timer(Entity):
         # pylint: disable=redefined-outer-name
         start = dt_util.utcnow()
         if self._remaining and newduration is None:
-            self._end = start + self._remaining
+            self._remaining = self._duration
         else:
             if newduration:
                 self._duration = newduration
                 self._remaining = newduration
             else:
                 self._remaining = self._duration
-            self._end = start + self._duration
+        self._end = start + self._duration
         self._listener = async_track_point_in_utc_time(self._hass,
                                                        self.async_finished,
                                                        self._end)
+        self._state = STATUS_PAUSED
+        yield from self.async_update_ha_state()
+        self._state = STATUS_ACTIVE
         yield from self.async_update_ha_state()

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Fields

    Priority

    None yet

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions