Skip to content

Formats number state with selected language in compute_state_display#7516

Merged
bramkragten merged 5 commits intohome-assistant:devfrom
joshmcrty:localize-number-state-display
Oct 30, 2020
Merged

Formats number state with selected language in compute_state_display#7516
bramkragten merged 5 commits intohome-assistant:devfrom
joshmcrty:localize-number-state-display

Conversation

@joshmcrty
Copy link
Contributor

Proposed change

This updates the computeStateDisplay function to format numbers using the browser's Intl.NumberFormat feature based on the selected language in Home Assistant. This results in language-specific thousands separator and decimal characters when displaying a state that is valid number.

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

Add an integration that creates entities that use a number state value with a unit of measurement. The Coronavirus integration is a quick and easy way to test this. When rendered in lovelace, more info dialogs, or anywhere the computeStateDisplay is used, the value should use language-specific comma separators and decimal characters.

Additional information

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:

@joshmcrty joshmcrty requested a review from bramkragten October 30, 2020 19:16
@bramkragten bramkragten merged commit 14db374 into home-assistant:dev Oct 30, 2020
@bramkragten bramkragten mentioned this pull request Nov 11, 2020
@joshmcrty joshmcrty deleted the localize-number-state-display branch November 19, 2020 20:55
@hulkhaugen
Copy link

This was a nice fix. I'm not going to pretend that i understand the code that does the magic. I just wanted to point out that this doesn't apply to the climate entities showing setpoint and current temperatures in the Lovelace UI, those values are still using the "." separator, while everything else in my setup seems to be using the "," separator which is correct for my language.

@bramkragten
Copy link
Member

Please don't comment on merged PR's, please create a new issue for this.

@home-assistant home-assistant locked as resolved and limited conversation to collaborators Nov 21, 2020
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