fix(web): use configured currency minor unit in Rates chart legend#4307
Merged
springfall2008 merged 4 commits intoJul 26, 2026
Merged
Conversation
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>
This was referenced Jul 25, 2026
Contributor
There was a problem hiding this comment.
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 onself.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. |
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>
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.
Summary
Fixes #4153. The Rates chart's "Hourly"/"Today" series legend names were hardcoded to
p/kWh(pence) regardless of the user's configuredcurrency_symbols, so non-GBP users (e.g. the reporter's NZD setup, configured as$c) sawp/kWhin the chart legend even though the surrounding chart title/axis already correctly usedself.currency_symbols[1].Per the maintainer's own scoping comment on the issue: fix limited to
web.py's chart rendering. Leftconfig.py's CONFIG_ITEMS units andoutput.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 realWebInterface.get_chart("Rates")(via a minimal instance bypassingComponentBase.__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 hardcodedp/kWhstrings 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.