Skip to content
Merged
Changes from 1 commit
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
7 changes: 5 additions & 2 deletions src/panels/lovelace/entity-rows/hui-timer-entity-row.ts
Original file line number Diff line number Diff line change
Expand Up @@ -126,14 +126,17 @@ class HuiTimerEntityRow extends LitElement {

if (stateObj.state === "idle" || this._timeRemaining === 0) {
return (
this.hass!.localize(`state.timer.${stateObj.state}`) || stateObj.state
this.hass!.localize(`component.timer.state._.${stateObj.state}`) ||

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.

Use computeStateDisplay so we don't have this again if we change logic there :-)

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Made the change, but that lead me to something else: The more-info dialog also was not aligned, which I fixed now, but that meant duplicating code. But since the computeStateDisplay() function does only accept a stateObj we cannot pass the remaining seconds to make it completely capsuled in computeStateDisplay().

We could add an optional parameter to computeStateDisplay() for a generic value to be provided by the caller and to be used in the domain specific handling for timer then.

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.

Isn't it the same as stateObj.attributes.duration?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

I don't think so. stateObj.attributes.duration is the defined runtime that this timer runs to reach 0. timeRemaining is the remaining seconds from the start of the timer until the duration is reached.

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.

Yeah I meant stateObj.attributes.remaining

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Does not work, because the backend attribute does only get updated when the timers pauses (and perhaps periodically?), but not each second as the frontend needs it to. The "live" timeRemaining is only known in the frontend.

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.

OK, let's move it to data/timer then

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.

timerTimeRemaining should move there too btw

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Code is moved. Have a look if that is what you had in mind.

stateObj.state
);
}

let display = secondsToDuration(this._timeRemaining || 0);

if (stateObj.state === "paused") {
display += ` (${this.hass!.localize("state.timer.paused")})`;
display += ` (${this.hass!.localize(
`component.timer.state._.${stateObj.state}`
)})`;
}

return display;
Expand Down