Skip to content

Ensure timer row uses correct state translation keys#9143

Merged
bramkragten merged 5 commits intohome-assistant:devfrom
spacegaier:timer-row-translation
May 24, 2021
Merged

Ensure timer row uses correct state translation keys#9143
bramkragten merged 5 commits intohome-assistant:devfrom
spacegaier:timer-row-translation

Conversation

@spacegaier
Copy link
Copy Markdown
Member

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

  • Dependency upgrade
  • Bugfix (non-breaking change which fixes an issue)
  • New feature (thank you!)
  • Breaking change (fix/feature causing existing functionality to break)
  • Code quality improvements to existing code or addition of tests

Example configuration

Additional information

  • This PR fixes or closes issue: fixes #
  • This PR is related to issue or discussion:
  • Link to documentation pull request:

Checklist

  • The code change is tested and works locally.
  • There is no commented out code in this PR.
  • Tests have been added to verify that the new code works.

If user exposed functionality or configuration variables are added/changed:

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.

@spacegaier spacegaier requested a review from bramkragten May 10, 2021 11:27
Co-authored-by: Bram Kragten <mail@bramkragten.nl>
@bramkragten bramkragten merged commit d425767 into home-assistant:dev May 24, 2021
@github-actions github-actions bot locked and limited conversation to collaborators May 25, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants