You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Use HA's official entity formatting functions when available
HA 2023.9+ exposes hass.formatEntityState/formatEntityAttributeValue,
which apply the user's own locale/number-format/precision preferences
the same way HA's own UI does. Delegate to them when present instead
of this project's own formatNumber/computeStateDisplay
reimplementation, falling back to the existing logic otherwise. A
custom `format:` config still takes precedence over both.
Based on the approach in benct#336 (originally by @mill1000), which should
closebenct#333, benct#308, benct#286, and benct#220 - a cluster of long-standing
decimal/precision formatting complaints.
That PR alone would have introduced a regression, though: HA installs
stub formatEntityState/formatEntityAttributeValue functions on initial
connection that return completely raw, unformatted values (confirmed
by extracting the actual implementations from a running instance's
frontend bundle - the stub is literally `(e,t) => (t ?? e.state) ?? ""`),
and swaps in the real implementations asynchronously. This is the same
race benct#373/benct#379 fixed for formatEntityName, but benct#336 didn't extend that
re-render check to the new functions it depends on - so cards would
have been stuck showing raw values whenever the swap happened after
initial render, same bug class as benct#370/benct#371 but for values instead of
names.
Generalized hasConfigOrEntitiesChanged's formatEntityName check into a
list covering all three formatter keys, and added tests simulating the
swap for each. Also added tests covering the new delegation paths in
entityStateDisplay, which the original PR's diff had zero coverage for.
Fixesbenct#333, benct#308, benct#286, benct#220
Co-Authored-By: Tucker Kern <mill1000@users.noreply.github.com>
Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
0 commit comments