Skip to content

Fix web UI showing raw 'p' unit instead of configured currency (#4071)#4104

Merged
springfall2008 merged 4 commits into
mainfrom
fix/web-currency-unit-4071
Jun 21, 2026
Merged

Fix web UI showing raw 'p' unit instead of configured currency (#4071)#4104
springfall2008 merged 4 commits into
mainfrom
fix/web-currency-unit-4071

Conversation

@springfall2008

Copy link
Copy Markdown
Owner

Fixes #4071

Problem

The Car Charging Plan max price field (and other price config items) displayed its unit as p in the Predbat web UI even when currency_symbols was configured to something else (e.g. ['€', 'c']).

The Home Assistant entity itself was already converted correctly via expose_config (it shows c in HA). The bug was that the web UI config pages (/config and /entity) read the raw config item unit ("p") without applying the currency_symbols conversion.

Fix

  • Factored the existing £→symbol / p→symbol conversion into a shared convert_currency_unit() helper on UserInterface.
  • Reused it in expose_config (replacing the duplicated inline logic).
  • Applied it at the three web.py config display sites: the entity-list builder, html_config_item_text (/entity page), and html_config (/config page).
  • Added unit tests in test_web_functions.py covering the helper (pc, p/kWhc/kWh, £, unchanged/empty units) and asserting the rendered config item HTML shows 14 c rather than 14 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 as 14, the same way 10p is entered as 10. Only the displayed label was wrong; the stored/used value was already in cents.

🤖 Generated with Claude Code

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>
Copilot AI review requested due to automatic review settings June 21, 2026 15:45

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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 in expose_config.
  • Applies currency unit conversion to config unit display in key web.py config 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.

Comment thread apps/predbat/userinterface.py
Comment thread apps/predbat/tests/test_web_functions.py
springfall2008 and others added 2 commits June 21, 2026 18:39
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>
@springfall2008 springfall2008 merged commit 80c1f9b into main Jun 21, 2026
1 check passed
@springfall2008 springfall2008 deleted the fix/web-currency-unit-4071 branch June 21, 2026 19:47
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.

Car Charging Plan max price still in pence

2 participants