Skip to content

fix(web): use configured currency minor unit in Rates chart legend#4307

Merged
springfall2008 merged 4 commits into
springfall2008:mainfrom
chalfontchubby:fix/rates-chart-currency-symbol
Jul 26, 2026
Merged

fix(web): use configured currency minor unit in Rates chart legend#4307
springfall2008 merged 4 commits into
springfall2008:mainfrom
chalfontchubby:fix/rates-chart-currency-symbol

Conversation

@chalfontchubby

Copy link
Copy Markdown
Collaborator

Summary

Fixes #4153. The Rates chart's "Hourly"/"Today" series legend names were hardcoded to p/kWh (pence) regardless of the user's configured currency_symbols, so non-GBP users (e.g. the reporter's NZD setup, configured as $c) saw p/kWh in the chart legend even though the surrounding chart title/axis already correctly used self.currency_symbols[1].

Per the maintainer's own scoping comment on the issue: fix limited to web.py's chart rendering. Left config.py's CONFIG_ITEMS units and output.py's HA entity attribute names untouched, since changing those affects existing HA entity definitions/history for all users.

Split out from #4288, which originally bundled this with two unrelated fixes.

Changes

  • apps/predbat/web.py: series names now use "{}/kWh".format(self.currency_symbols[1]), matching the pattern already used elsewhere in the same file.
  • apps/predbat/tests/test_web_chart_currency.py: calls the real WebInterface.get_chart("Rates") (via a minimal instance bypassing ComponentBase.__init__) and checks the rendered series names, rather than re-testing the formatting logic in isolation. Verified this actually catches a regression: temporarily reintroducing the hardcoded p/kWh strings makes the test fail as expected.

Test plan

  • ./run_all --test web_chart_currency - new test passes
  • ./run_all --quick - full quick suite passes (611 tests, 0 failures)
  • ./run_pre_commit - clean (ruff, black, cspell, markdownlint)

🤖 Implemented with Claude Code, disclosed per repo convention.

chalfontchubby and others added 2 commits July 25, 2026 22:34
The Rates chart's "Hourly"/"Today" series legends were hardcoded to
"p/kWh" (pence) regardless of the configured currency_symbols, so
non-GBP users (e.g. NZD, configured as "$c") saw "p/kWh" in the chart
legend even though the surrounding chart title/axis already correctly
used self.currency_symbols[1]. Fixes springfall2008#4153.

Added a test verifying the series-name formatting follows
currency_symbols for £p/$c/€c - get_chart() itself requires a fully
computed plan before reaching this branch, so the test mirrors the
formatting logic directly rather than standing up that heavier
machinery (matching this file's existing "Loading..." early-return
gate and the lack of any content assertions in test_web_if.py's
integration tests).

🤖 Implemented with Claude Code, disclosed per repo convention.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
…y test

Two issues flagged on PR springfall2008#4288:

- The test mutated my_predbat.currency_symbols without restoring it,
  leaking state into later tests in the same suite process (the shared
  my_predbat fixture is reused across all tests).
- The test never actually called WebInterface.get_chart()/web.py - it only
  re-tested the same inline string-formatting logic, so it would still
  pass even if web.py regressed back to a hardcoded "p/kWh".

Now builds a minimal WebInterface (bypassing ComponentBase.__init__, which
would stand up the real aiohttp app) and calls the real get_chart("Rates"),
stubbing get_history_wrapper() directly to avoid reproducing realistic HA
history formatting for data not under test. Verified this actually catches
a regression: temporarily reintroducing the hardcoded "p/kWh" strings in
web.py makes the test fail as expected. currency_symbols/dashboard_values
are now saved and restored via try/finally.

🤖 Implemented with Claude Code, disclosed per repo convention.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>

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 the Rates chart legend text in the web UI so the “Hourly” and “Today” series names use the configured currency minor unit (from currency_symbols[1]) instead of being hardcoded to p/kWh, addressing issue #4153 for non-GBP users.

Changes:

  • Updated WebInterface.get_chart("Rates") to render “Hourly {minor}/kWh” and “Today {minor}/kWh” based on self.currency_symbols[1].
  • Added a targeted unit test that exercises the real get_chart("Rates") output and validates the rendered series names.
  • Registered the new test in the main unit test runner.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.

File Description
apps/predbat/web.py Uses the configured currency minor unit in the Rates chart legend series names instead of hardcoded p/kWh.
apps/predbat/unit_test.py Adds the new web chart currency test to the unit test registry.
apps/predbat/tests/test_web_chart_currency.py New test verifying Rates chart series names follow currency_symbols[1] in real get_chart() output.

Comment thread apps/predbat/tests/test_web_chart_currency.py
chalfontchubby and others added 2 commits July 26, 2026 09:53
Copilot review on springfall2008#4307: the test stubbed dashboard_values using
hardcoded "predbat.*" entity IDs, so it would silently pass if the
test harness prefix ever differed from get_chart()'s own self.prefix
lookup. Build the keys from my_predbat.prefix instead, matching how
get_chart() actually resolves them.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
@springfall2008
springfall2008 merged commit 7b5fcdb into springfall2008:main Jul 26, 2026
2 checks passed
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.

Graph legends show as p/kWh, when should be c/kWh

3 participants