Skip to content

feat: add glance mode (mode: glance) for the givenergy dashboard strategy (#131)#137

Merged
dewet22 merged 6 commits into
mainfrom
feat/dashboard-glance-mode
Jun 6, 2026
Merged

feat: add glance mode (mode: glance) for the givenergy dashboard strategy (#131)#137
dewet22 merged 6 commits into
mainfrom
feat/dashboard-glance-mode

Conversation

@dewet22

@dewet22 dewet22 commented Jun 6, 2026

Copy link
Copy Markdown
Owner

Summary

Closes part of #131 — introduces mode: glance as a third selectable mode for the custom:givenergy dashboard strategy.

What's new

  • mode: glance prepends a full-viewport Glance panel (panel: true) to the existing classic view set.
  • custom:givenergy-glance — a new vanilla custom element (no build step) that renders:
    • A natural-language status sentence with a pulsing amber/green indicator dot. Eight states are derived from live sign-combinations of grid/battery/solar (e.g. "Solar covering the house and charging the battery, exporting the surplus." / "Battery powering the house." / "Drawing from the grid."). The dot turns amber when importing from the grid or when battery SOC drops below 20%.
    • Three large Fraunces numerals: Solar today (kWh), Battery SOC (%), House today (kWh). Each has a contextual sub-line: string breakdown or current kW for solar, per-pack SOC or charge/discharge direction for battery, import/export direction for house.
    • Health pills: battery count, per-pack SOC when multiple packs are present (amber at < 20%), imported/exported kWh today, active per-string generation.
  • EMS plants fall back to the classic view set (no glance panel), matching the flow mode behaviour.
  • Kiosk-mode hints (hide_header, hide_sidebar) are feature-detected and omitted when the integration is absent.
  • Container-query responsive layout; signature guard skips DOM rebuilds when no referenced state has changed.
  • _STRATEGY_VERSION bumped to 6 for cache-busting.

Tests

Four new JS tests (29 total): view set shape, EMS fallback, registry resolution under the loft_ area prefix, and missing-entity omission.

Test plan

  • Add strategy: { type: custom:givenergy, mode: glance } to a dashboard.
  • Confirm Glance panel is the first view; classic tabs follow.
  • Status sentence matches the current system state (solar generating, battery charging/discharging, grid import/export).
  • Dot is green when self-sufficient/exporting, amber when importing or SOC < 20%.
  • Three big numbers populated (Solar today / Battery % / House today).
  • Health pills show battery count, import/export today, and per-string when active.
  • On a narrow viewport, the three numbers stack to a single column.
  • EMS plant: mode: glance falls back to the classic EMS view set.

🤖 Generated with Claude Code

Summary by CodeRabbit

  • New Features

    • Added a new "glance" dashboard mode with an at-a-glance view displaying solar generation, battery state-of-charge, and household usage.
    • Includes visual indicators for battery availability, import/export totals, and per-string solar generation.
  • Chores

    • Updated dashboard version to ensure clients fetch the latest configuration.

…tegy

Adds a Glance panel to the custom:givenergy dashboard strategy, selectable
via `strategy: { type: custom:givenergy, mode: glance }`.

The panel is a new `custom:givenergy-glance` card (no additional install)
that renders:

- A natural-language status sentence with a pulsing amber/green dot:
  "Solar covering the house and charging the battery, exporting the
  surplus." and eight other states derived from live grid/battery/solar
  sign combinations.
- Three large Fraunces numerals: Solar today (kWh), Battery SOC (%),
  House today (kWh), each with a contextual sub-line (string breakdown,
  per-pack SOC, import/export direction).
- Health pills: battery count, per-pack SOC when multiple packs present,
  imported/exported kWh today, active per-string generation.

EMS plants fall back to the classic view set (no glance panel), matching
the flow mode behaviour. Kiosk-mode hints are emitted when the
integration is detected.

Four new JS tests (29 total); _STRATEGY_VERSION bumped to 6.

Part of #131.
@coderabbitai

coderabbitai Bot commented Jun 6, 2026

Copy link
Copy Markdown

Review Change Stack

Warning

Review limit reached

@dewet22, we couldn't start this review because you've reached your PR review rate limit.

More reviews will be available in 44 minutes and 49 seconds. Learn how PR review limits work.

Your organization has run out of usage credits. Purchase more in the billing tab.

⌛ How to resolve this issue?

After more reviews become available, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans include higher PR review limits than trial, open-source, and free plans. In all cases, reviews become available again over time. During sustained high-volume PR review activity, CodeRabbit may temporarily slow when the next review becomes available.

Please see our Fair Usage Limits Policy for further information.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: e1a47988-c36c-41ab-9b33-118f33a63fb3

📥 Commits

Reviewing files that changed from the base of the PR and between 89b2c01 and cb8779d.

📒 Files selected for processing (4)
  • README.md
  • custom_components/givenergy_local/__init__.py
  • custom_components/givenergy_local/www/ge-strategy.js
  • tests/js/ge-strategy.test.js
📝 Walkthrough

Walkthrough

This PR introduces a new "glance" dashboard mode for the GivEnergy Home Assistant integration. The changes add glance view generation, mode dispatcher routing, a custom card component for metrics display, comprehensive tests, and a cache-busting version bump to ensure clients fetch the updated JavaScript bundle.

Changes

Glance Dashboard Mode

Layer / File(s) Summary
Glance view generator
custom_components/givenergy_local/www/ge-strategy.js
New glanceViews and glanceView functions generate an inverter-centric glance panel (prepended to classic views for non-EMS plants), with dynamic resolution of solar/grid/load/battery entity IDs and optional battery pack and kiosk-mode support.
Dashboard mode dispatch integration
custom_components/givenergy_local/www/ge-strategy.js
The generateDashboard function now routes mode: "glance" to the glance view generator alongside existing classic and flow mode handling.
Custom glance card rendering and metadata
custom_components/givenergy_local/www/ge-strategy.js
New custom:givenergy-glance web component renders status sentences, solar/battery/house big-number metrics, and pill indicators (battery status/import/export/per-string generation) with signature-based DOM optimization and optional kiosk-mode styling. Strategy metadata is updated to advertise glance mode support.
Glance mode validation tests
tests/js/ge-strategy.test.js
Comprehensive test suite validates view structure/ordering, entity resolution via registry with area-prefix handling, omission of missing entities, and exemption of EMS plants from glance panel generation.
Frontend cache-busting version update
custom_components/givenergy_local/__init__.py
_STRATEGY_VERSION incremented from "5" to "6" to force clients to refetch the updated strategy bundle.

Sequence Diagram

sequenceDiagram
  participant Lovelace as Lovelace
  participant dispatcher as generateDashboard
  participant generator as glanceViews
  participant card as custom:givenergy-glance
  Lovelace->>dispatcher: generateDashboard({mode:"glance"})
  dispatcher->>generator: route to glanceViews
  generator->>dispatcher: return glance panel with card refs
  dispatcher->>Lovelace: dashboard with glance panel
  Lovelace->>card: load and render component
  card->>card: compute status from entity states
  card->>Lovelace: display big 3 metrics + pills
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Possibly related PRs

  • dewet22/givenergy-hass#136: Both PRs extend generateDashboard's mode dispatch by adding new dashboard modes within the same code path (glance mode in this PR, flow mode in the related PR), with overlapping conventions for view generation and routing.
  • dewet22/givenergy-hass#132: This PR builds directly on the strategy module and _STRATEGY_VERSION wiring by introducing new glance mode generation and test logic to the existing ge-strategy.js infrastructure.

Poem

🐰 A glance that sparkles, metrics gleam bright,
Solar and battery dance in the light,
New cards take flight, with status to tell,
Big numbers bold, and pills that compel.
From dashboard cascade to cache-busting verse,
A givenergy view for better or worse! ✨

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 20.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The PR title 'feat: add glance mode (mode: glance) for the givenergy dashboard strategy' clearly and specifically describes the main feature addition—a new glance mode for the dashboard strategy, which aligns with the primary changes across all three modified files.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch feat/dashboard-glance-mode

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@dewet22-codex

Copy link
Copy Markdown
Collaborator

I’ve started reviewing this PR.

Comment thread custom_components/givenergy_local/www/ge-strategy.js Outdated
Comment thread custom_components/givenergy_local/www/ge-strategy.js Outdated

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Code Review

This pull request introduces a new 'glance' mode to the GivEnergy dashboard. It adds a custom element givenergy-glance that displays a natural-language status sentence, key metrics (solar today, battery SOC, and house today), and health pills. The strategy version is bumped to 6, and corresponding unit tests are added to verify the glance mode functionality. There are no review comments to address.

Important

The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.

dewet22 and others added 4 commits June 6, 2026 19:48
… README

Restructure the status sentence logic to check the net grid direction
(exporting / importing / idle) within the solarOn group before deciding
what to say. Previously `solarOn` took priority over `importing`, so
e.g. solar=200 W with grid=-1500 W produced "Solar covering the house"
despite heavy grid import. The new structure:

  solarOn + exporting -> "ahead of demand" / "exporting the surplus" / etc.
  solarOn + importing -> "Solar and grid supplying..." (admits the import)
  solarOn + idle grid -> "Solar covering..." / "...and charging..."
  no solar            -> battery/grid/idle branches (unchanged)

Also adds the `#### mode: glance` section to the README and updates the
mode comment and "still to come" line to reflect the shipped state.
Replace the single 100 W threshold with a Schmitt-trigger pair:
THRESH_ON=200 W to enter a state, THRESH_OFF=80 W to leave it.
Persisted via this._flowState between renders.

Prevents the sentence from flipping between states when readings are
near a threshold -- e.g. solar=170 W / grid=+150 W briefly claiming
"Solar ahead of demand" at dusk when sensor timing skew tips the grid
reading just above the old 100 W entry threshold.
Temporary dev convenience: a single dashboard with all mode panels
(Glance, Flow, then the six classic tabs). Intended to be removed when
modes are split into separate dashboards at release time.

_STRATEGY_VERSION bumped to 7.
Adds a dense terminal-aesthetic Analyst view that combines live power
metrics, an energy sources/sinks ledger with percentages, inverter
diagnostics, a 24h apexcharts power overlay (placeholder if absent),
and per-pack cell heatmaps in a multi-card non-panel layout.

Also folds Analyst into mode: all (Glance -> Flow -> Analyst -> classic
tabs) and bumps _STRATEGY_VERSION to 8.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@dewet22-codex

Copy link
Copy Markdown
Collaborator

I’ve started re-reviewing this PR.

Comment thread custom_components/givenergy_local/www/ge-strategy.js Outdated
Adds README sections for mode:analyst and mode:all (same pattern as
mode:flow and mode:glance). Updates the mode hint comment in the
strategy yaml example to list all five modes. Removes the "dev
convenience" label from the mode:all comment in ge-strategy.js now
that all four UX modes are implemented.

Addresses coderabbitai feedback on PR #137.

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

dewet22 commented Jun 6, 2026

Copy link
Copy Markdown
Owner Author

Thanks for the three-point review. Quick status on each:

Status sentence logic — the concern was already addressed by the fix commits (33e4da2, a26f0b7) that landed after the first review pass. The dispatch now checks exporting/importing before reaching any solar-only clause, so solarOn=true, importing=true always produces "Solar and grid supplying the house" rather than the earlier incorrect variant.

README missing glance docs — also covered by a26f0b7; mode: glance has had its own section and mode-hint entry since that commit.

mode: all in production — fair point. I've just pushed cb8779d which adds mode: analyst and mode: all sections to the README (same pattern as flow/glance), updates the mode-hint comment to list all five options, and removes the "dev convenience" wording from the inline comment. mode: all now ships as a documented, intentional mode — it stacks Glance, Flow, and Analyst in front of the classic tab set, which is genuinely useful for users who want all display styles in one dashboard.

@dewet22 dewet22 merged commit a263a52 into main Jun 6, 2026
12 checks passed
@dewet22 dewet22 deleted the feat/dashboard-glance-mode branch June 6, 2026 21:30
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.

2 participants