Ensure timer row uses correct state translation keys#9143
Ensure timer row uses correct state translation keys#9143bramkragten merged 5 commits intohome-assistant:devfrom
Conversation
| 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}`) || |
There was a problem hiding this comment.
Use computeStateDisplay so we don't have this again if we change logic there :-)
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
Isn't it the same as stateObj.attributes.duration?
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
Yeah I meant stateObj.attributes.remaining
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
OK, let's move it to data/timer then
There was a problem hiding this comment.
timerTimeRemaining should move there too btw
There was a problem hiding this comment.
Code is moved. Have a look if that is what you had in mind.
Co-authored-by: Bram Kragten <mail@bramkragten.nl>
Breaking change
Proposed change
Glance and Entity card were correct since they use
computeStateDisplay()but the timer entity row has its own compute logic, that however tried to use wrong and non-existing keys => translations cannot work and UI shows the technical state string.With this PR it now uses the state translations that the backend provides.
Type of change
Example configuration
Additional information
Checklist
If user exposed functionality or configuration variables are added/changed: