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
12 changes: 6 additions & 6 deletions homeassistant/components/timer/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
ATTR_FINISHES_AT = "finishes_at"
ATTR_RESTORE = "restore"
ATTR_FINISHED_AT = "finished_at"
ATTR_LAST_ACTION = "last_action"
ATTR_LAST_TRANSITION = "last_transition"

Comment thread
MartinHjelmare marked this conversation as resolved.
CONF_DURATION = "duration"
CONF_RESTORE = "restore"
Expand Down Expand Up @@ -203,7 +203,7 @@ class Timer(collection.CollectionEntity, RestoreEntity):
def __init__(self, config: ConfigType) -> None:
"""Initialize a timer."""
self._config: dict = config
self._last_action: str | None = None
self._last_transition: str | None = None
self._state: str = STATUS_IDLE
self._configured_duration = cv.time_period_str(config[CONF_DURATION])
self._running_duration: timedelta = self._configured_duration
Expand Down Expand Up @@ -251,7 +251,7 @@ def extra_state_attributes(self) -> dict[str, Any]:
attrs: dict[str, Any] = {
ATTR_DURATION: _format_timedelta(self._running_duration),
ATTR_EDITABLE: self.editable,
ATTR_LAST_ACTION: self._last_action,
ATTR_LAST_TRANSITION: self._last_transition,
}
Comment thread
MartinHjelmare marked this conversation as resolved.
if self._end is not None:
attrs[ATTR_FINISHES_AT] = self._end.isoformat()
Expand All @@ -277,7 +277,7 @@ async def async_added_to_hass(self) -> None:

# Begin restoring state
self._state = state.state
self._last_action = state.attributes.get(ATTR_LAST_ACTION)
self._last_transition = state.attributes.get(ATTR_LAST_TRANSITION)

Comment thread
MartinHjelmare marked this conversation as resolved.
# Nothing more to do if the timer is idle
if self._state == STATUS_IDLE:
Expand Down Expand Up @@ -353,7 +353,7 @@ def async_change(self, duration: timedelta) -> None:
self._end += duration
self._remaining = new_remaining
# We don't use _fire_event_and_write_state here because we don't want to
# update last_action
# update last_transition
self.async_write_ha_state()
self.hass.bus.async_fire(EVENT_TIMER_CHANGED, {ATTR_ENTITY_ID: self.entity_id})
self._listener = async_track_point_in_utc_time(
Expand Down Expand Up @@ -437,7 +437,7 @@ def _fire_event_and_write_state(
self, event: str, *, extra_attrs: dict[str, Any] | None = None
) -> None:
"""Fire the event and write state."""
self._last_action = event.partition(".")[2]
self._last_transition = event.partition(".")[2]
self.async_write_ha_state()
event_data = {ATTR_ENTITY_ID: self.entity_id}
if extra_attrs:
Expand Down
10 changes: 10 additions & 0 deletions homeassistant/components/timer/strings.json
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,16 @@
"finishes_at": {
"name": "Finishes at"
},
"last_transition": {
"name": "Last transition",
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure this is understandable?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it's good. It's better than last action as we didn't include all actions in last action.

"state": {
"cancelled": "Cancelled",
"finished": "Finished",
"paused": "Paused",
"restarted": "Restarted",
"started": "Started"
}
},
"remaining": {
"name": "Remaining"
},
Expand Down
Loading