Skip to content

feat: Use native localized units & order "value - delimiter - unit"#1350

Open
ildar170975 wants to merge 17 commits into
kalkih:devfrom
ildar170975:uom-delimiter-order
Open

feat: Use native localized units & order "value - delimiter - unit"#1350
ildar170975 wants to merge 17 commits into
kalkih:devfrom
ildar170975:uom-delimiter-order

Conversation

@ildar170975
Copy link
Copy Markdown
Collaborator

@ildar170975 ildar170975 commented Mar 10, 2026

Adds more features to #1233.
So, suggest to test along with #1233 merged.

Additionally - implements #1287.


Features:

Support of native units for attributes; example - temperatures in climate.ecobee of Demo integration:

image

Support of native presentation of "percentage" values: some locales like “German” demand a presence of a whitespace between a value & "%", some like “English” do not place a whitespace:

image

Support of native localized units dependently on a locale.
Support of native reversed order for a state/attribute value presentation dependently on a locale.
Example - monetary values:

Language: "English (GB)"
Number format: "Use system locale"

image

Language: "English"
Number format: "Use language settings"

image

Support of translated units; example - Github integration:
Language: “German”

image

Allow to hide a unit for extrema & average info for a compactness (#1287):

image

@ildar170975 ildar170975 changed the base branch from master to dev March 10, 2026 23:42
@ildar170975 ildar170975 marked this pull request as ready for review March 11, 2026 00:26
@ildar170975
Copy link
Copy Markdown
Collaborator Author

A possible improvement which can/should be done in future:
perhaps we need to define an order "value - delimiter - unit" not on every render - but once we get a meaningful state (i.e. not unknown or unavailable), may slightly increase a performance.

@ildar170975 ildar170975 marked this pull request as draft March 11, 2026 05:16
@ildar170975 ildar170975 linked an issue Mar 11, 2026 that may be closed by this pull request
@ildar170975 ildar170975 marked this pull request as ready for review March 11, 2026 05:52
Copy link
Copy Markdown
Collaborator

@jlsjonas jlsjonas left a comment

Choose a reason for hiding this comment

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

Not a thorough review yet, thanks for your continued contributions & glad to see your progress!

Comment thread src/locale.js
case 'fi':
case 'fr':
case 'sk':
case 'sv':
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Could we potentially extract this from home assistant's api instead?
If not, are you sure this list is exhaustive? Would be good to refer to the (preferably HA) source to maintain over time.

Copy link
Copy Markdown
Collaborator Author

@ildar170975 ildar170975 Mar 26, 2026

Choose a reason for hiding this comment

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

Could we potentially extract this from home assistant's api instead?

I do not think there is such a "HA api" (((. We can use methods of hass object (specially exposed for external use) - but there are no exposed methods for formatting.
Recently I added methods to hass to represent parts of a state & attribute - earlier only WHOLE strings for a state & attribute were available (i.e. "value with unit", not separately). Now I am thinking to expose formatNumber() (internal frontend function) to the outer world. But meanwhile we have to manually "copy" functions from Frontend to get a similar result.

If not, are you sure this list is exhaustive? Would be good to refer to the (preferably HA) source to maintain over time.

No guarantee that this list is full. The best scenario would be using an exposed HA function - which is not available now, see above.

Comment thread src/main.js
*/
computeStateOrder(index) {
const entityId = this.config.entities[index].entity;
const { attribute } = this.config.entities[index];
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Suggested change
const { attribute } = this.config.entities[index];
const { entityId, attribute } = this.config.entities[index];

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

The problem is that entities[index] does not have the entityId option.
Perhaps we can do smth like

const { entity: entityId, attribute } = this.config.entities[index];

just a speculation, since I know a little about JS.

My approach was simple: when I get a warning about a "deconstruction", I use that "const { xxx } = yyy" syntax, otherwise - use "old classic" way.

Comment thread src/main.js
: ''
)
)
);
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Note that this format was originally used for performance reasons (we also run on lower-spec devices), please check the performance impact of the change(s)

Copy link
Copy Markdown
Collaborator Author

@ildar170975 ildar170975 Mar 26, 2026

Choose a reason for hiding this comment

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

Yeah, using functions like formatEntityAttributeValueToParts needs more time.
Same as for "use states['sensor.xxx'].state" vs "use formatEntityStateToParts()".
But we need to follow HA frontend number formatting settings, individual entity precision settings, translations...
My only hope is that computeState() (same for computeUom()) is only used for presentation, i.e. not being called very often.

@ildar170975
Copy link
Copy Markdown
Collaborator Author

@jlsjonas
Hi Jonas, nice to see you again). Thanks for the review, please go on)))

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[FR] Hide unit for Min/Avg/Max value

2 participants