Repository navigation
Conversation
|
Thanks for the PR, Can you share screenshots of the various features of the proposed dashboards? |
springfall2008
left a comment
There was a problem hiding this comment.
Thanks for this. The new UI looks great and I'd like to get it in. Before it can merge I need changes to how it's packaged, and I'd like both interfaces to run side by side. I've reviewed head 5309cecb.
1. Size: every user downloads this, even on the legacy UI
The updater (download.py) and the add-on's first install (startup.py in predbat_addon) both download the whole repository archive and then copy apps/predbat/* out of it. Anything committed anywhere in the repo is therefore downloaded by every user on every update:
| Size | |
|---|---|
Repo .tar.gz on main |
10.7 MB |
Repo .tar.gz on this PR |
48.4 MB |
frontend/src/assets/house/*.png (16 × ~2 MB) |
~31 MB |
apps/predbat/frontend.zip |
4.7 MB |
docs/images/web-interface-overview-view.png |
1.7 MB |
The source PNGs are never used at runtime; the build turns them into WebP files totalling about 2.8 MB. Please:
- Commit the WebP files, not the PNGs, and drop the
sharp/images:housepre-build step. If you want to go further, a base house image with car, heat-pump and snow overlays would replace the 16 combinations. - Shrink the docs screenshot. A WebP or a resized PNG should be well under 300 KB.
2. Replace Monaco
Most of the bundle is Monaco, which is used only on the apps.yaml editor page. It is shipped with about 80 language definitions (ABAP, Solidity, Verilog, …) when only YAML is used: editor.api is 2.5 MB, yaml.worker 1 MB and AppsEditorPage 1.1 MB.
Please switch to CodeMirror 6 (@codemirror/lang-yaml, linting and autocomplete), which is the successor to the CodeMirror 5 the legacy editor uses. It needs no web workers and comes to a few hundred KB. JSON-schema packages for CodeMirror cover the schema checking, hover and completion you get from monaco-yaml today, and the entity completion is your own code either way.
If you'd rather keep Monaco, at least limit it to YAML: import monaco-editor/esm/vs/editor/editor.api and only the YAML language contribution, rather than monaco-editor, which pulls in every language. The CDN route is awkward because Monaco's workers can't be started from another origin, and monaco-yaml's worker has to be bundled anyway.
3. Ship the built files directly instead of a zip
I'd like to avoid the zip. The committed zip can't be reviewed or diffed, nothing checks that it matches frontend/, and python3 -m zipfile stores file timestamps, so every rebuild is a new 4.7 MB file in history. This branch already holds 66 versions of it (~528 MB).
I've checked what the installers support:
- Flat files directly in
apps/predbat/work. The updater lists the directory via the GitHub API, verifies each file against its Git blob SHA and writes it in binary, so.js,.css,.webpand.svgare all fine. The add-on'scp apps/predbat/* …picks them up too. - Subdirectories do not work.
get_github_directory_listingdrops directories,match_archive_memberonly accepts<repo>/apps/predbat/<file>, andpredbat_update_moveis a flat chain ofmvcommands. Afrontend/dist/folder would never reach users. Changing that would also need two updates for existing installs, because an update runs the olddownload.py. - The updater never deletes files. Vite's default content-hashed names (
index-wqkwcjKB.js) would leave the old copies behind on users' disks after every frontend change. check_installfails on a zero-byte file, so the build must not emit empty chunks.
So please:
- Configure Vite to write fixed, prefixed names into
apps/predbat/. For example:entryFileNames: 'predbat_ui.js',chunkFileNames: 'predbat_ui_[name].js',assetFileNames: 'predbat_ui_[name][extname]', pluspredbat_ui.html. Updates then overwrite files rather than adding new ones. - Keep the file count small. Without Monaco this should be a few dozen files. Merge small page chunks with
manualChunkswhere it helps. - Serve only those files. The asset route will be reading from the install directory, which also holds
apps.yaml,secrets.yamland the Python source. Serve only names matchingpredbat_ui*with an allow-listed extension, and nothing else from that directory. - Handle caching without hashed names. Use
web.FileResponse(it sets ETag and Last-Modified and answers 304s) withCache-Control: no-cache, or add?v=<predbat version>to the asset URLs inpredbat_ui.html. Please also enable compression; the JS is served uncompressed at the moment. - Add a CI job that runs
npm ci && npm run buildand fails ongit diff --exit-code apps/predbat/predbat_ui*. It proves the committed files match the reviewed source. With fixed names and the lockfile, Vite's output should be deterministic. - Update
coverage/deployto copypredbat_ui*instead offrontend.zip.
4. Run both UIs at the same time
Rather than choosing one interface in apps.yaml at startup, I'd like both available all the time:
- Mount the modern UI under a prefix, for example
./ui/,./ui/plan,./ui/charts. The legacy pages stay at their current paths. - Fix up the relative URLs. The frontend already uses relative URLs and takes the page from the last path segment, so this mostly works under ingress. From
/ui/plan,./api/...resolves to/ui/api/..., so build API and POST URLs as../api/...(one level up), or register the API under the prefix as well. Assets resolve to./ui/predbat_ui_*, which the prefixed asset route serves. - Add a link each way: "Try the new interface" in the legacy menu and "Classic interface" in the modern one. If a user wants the new UI as their landing page, remember it per browser (cookie or localStorage) and redirect
/to./ui/. Noapps.yamloption or restart needed. - Remove what that makes unnecessary: the
web_uioption,get_web_ui(), everyself.html_modern_ui if modern_ui else …route, the duplicate/legacy_*routes (legacy_annual,legacy_chat,legacy_apps,legacy_charts,legacy_dash,legacy_plan) and thechart_pathswitch. Updatedocs/web-interface.mdanddocs/apps-yaml.mdto match.
This also lets anyone try the new UI without editing their config. That's the best way to get feedback while the legacy UI remains the default.
Happy to talk any of this through.
|
Those changes all make sense to me, I’ve implemented them all:
I’ve tested this in Home Assistant. All 100 frontend tests and the focused backend tests pass, and a clean build reproduces the committed assets exactly. |
bb18f2c to
2bfcb90
Compare
|
@calvind80 thanks for working through the packaging review. I've checked the current head ( Before I review the UI itself, there's a problem with scope. Besides the UI, the branch now carries several engine changes that have nothing to do with it:
Some of these may well be good fixes. But each one changes how Predbat controls an inverter or plans, so each needs its own review and its own place in the release notes. They can't be merged as part of a UI PR. The rebuilt There are two ways forward, and I'm happy with either:
Let me know which you'd prefer. |
I will do the splitting up, I will keep this PR as the UI additions & required backend changes for that only. |
8b6c913 to
52b56fd
Compare
|
@springfall2008 Non-UI changes have been split out from this PR. |








Summary
Adds an optional modern web interface for Predbat, with responsive layouts, light and dark themes, and navigation between Overview, Dashboard, Plan, Charts, Compare, configuration and system pages.
Both interfaces run together: the classic pages keep their existing paths, and the modern interface is available under
./ui/. Select Try the new interface in the classic menu or Classic interface in the modern menu. The browser remembers the choice for this installation; no configuration change or restart is needed.The new interface includes:
Compatibility
apps/predbat/predbat_ui*files.apps.yamlconfigurations remain supported.frontend/.Configuration
Add the relevant settings to your existing pred_bat: section in apps.yaml. Replace the example entity IDs with your own.
No
web_uisetting is needed. All additional Overview settings below are optional. Existing grid, solar, battery and household entities are reused automatically.Existing integrations and defaults
Packaging and delivery
sharpdependency are removed.predbat_ui*files with fixed names and rejects empty chunks/assets. No zip is shipped.FileResponsesupplies ETag/Last-Modified and conditional responses, withCache-Control: no-cacheand compression for text assets.npm ci, tests and a build, then checks for changed or untracked generated files.coverage/deploycopiespredbat_ui*./legacy_*aliases and chart-path switch are removed. Modern UI guidance is in final sections of the web-interface and apps.yaml documentation.Validation
Frontend CI passed on both fork repositories at
a1c64357. The upstream pull request workflows are awaiting maintainer approval.