Fix web UI showing raw 'p' unit instead of configured currency (#4071)#4104
Merged
Conversation
The Predbat web UI config pages (/config and /entity) displayed the raw
config item unit ("p") without applying the currency_symbols conversion,
so entities like car_charging_plan_max_price always showed "p" even when
currency_symbols was set to e.g. ['€', 'c']. The HA entity itself was
already converted correctly via expose_config.
Factor the conversion into a shared convert_currency_unit() helper on
UserInterface, reuse it in expose_config, and apply it at the three web.py
config display sites. Add unit tests covering the helper and the rendered
config item HTML.
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Contributor
There was a problem hiding this comment.
Pull request overview
This PR fixes a web UI inconsistency where config item units were displayed using raw default currency units (£/p) instead of the user-configured currency_symbols, aligning the /config and /entity pages with Home Assistant’s already-correct unit display.
Changes:
- Introduces a shared
UserInterface.convert_currency_unit()helper and reuses it inexpose_config. - Applies currency unit conversion to config unit display in key
web.pyconfig rendering paths. - Adds unit tests to validate unit conversion behavior and HTML rendering for the affected config item.
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
| apps/predbat/web.py | Uses currency-unit conversion when rendering config item units in entity list and config pages. |
| apps/predbat/userinterface.py | Factors out currency unit conversion into a helper and reuses it for HA entity exposure. |
| apps/predbat/tests/test_web_functions.py | Adds tests covering currency unit conversion and expected rendered HTML output. |
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #4071
Problem
The Car Charging Plan max price field (and other price config items) displayed its unit as
pin the Predbat web UI even whencurrency_symbolswas configured to something else (e.g.['€', 'c']).The Home Assistant entity itself was already converted correctly via
expose_config(it showscin HA). The bug was that the web UI config pages (/configand/entity) read the raw config itemunit("p") without applying thecurrency_symbolsconversion.Fix
£→symbol /p→symbol conversion into a sharedconvert_currency_unit()helper onUserInterface.expose_config(replacing the duplicated inline logic).web.pyconfig display sites: the entity-list builder,html_config_item_text(/entitypage), andhtml_config(/configpage).test_web_functions.pycovering the helper (p→c,p/kWh→c/kWh,£→€, unchanged/empty units) and asserting the rendered config item HTML shows14 crather than14 p.Note on the reporter's "can't enter 0,14"
That part of the report is a misunderstanding rather than a bug: the field has always been in the minor unit (pence/cents) with step 1 —
0.14 €is entered as14, the same way10pis entered as10. Only the displayed label was wrong; the stored/used value was already in cents.🤖 Generated with Claude Code