Skip to content

feat: dashboard PR A — Smart Load, AC-Coupled, mode controls, battery totals#121

Merged
dewet22 merged 2 commits into
mainfrom
feat/dashboard-gaps-pr-a
Jun 4, 2026
Merged

feat: dashboard PR A — Smart Load, AC-Coupled, mode controls, battery totals#121
dewet22 merged 2 commits into
mainfrom
feat/dashboard-gaps-pr-a

Conversation

@dewet22

@dewet22 dewet22 commented Jun 4, 2026

Copy link
Copy Markdown
Owner

Summary

Closes the highest-priority gaps between entities the integration exposes and what the generated dashboard surfaces:

  • Smart Load slots 1–10 on Controls. Wired through generate_dashboard(has_smart_load=…); defaults to True for inverter installs until givenergy-modbus exposes a capability we can gate on (modbus #181, targeted at 2.1.3). The Repairs prompt has shown for some users that the Smart Load section was sitting unused — it now has a home. Until the capability lands, plants without Smart Load hardware will see the rows render as 'unavailable'; the gating story tightens up once the modbus side ships.
  • AC-Coupled card on Controls (Export Priority, EPS Enable, AC Charge Limit, AC Discharge Limit), gated by capabilities.has_ac_config_block from PlantCapabilities — present on AC-coupled / All-in-One, absent on hybrids.
  • Mode card additions: Real Time Control switch + Inverter Max Output Active Power number (the active-power-rate knob added in feat(controls): EMS export + flexi parity, RTC and active-power knobs #83).
  • Energy → All-Time Totals: adds Battery Charged / Battery Discharged from the e_battery_charge_total / e_battery_discharge_total sensors (gated server-side by skip_if_none).
  • DASHBOARD_VERSION → 8 so the existing Repairs issue prompts users on existing installs to regenerate.
  • Matching changes in dashboard/template.yaml for manual-setup users, with inline comments noting that the AC-Coupled and Smart Load cards should be removed by users whose hardware doesn't carry the corresponding capability.

Refs #52, #76, #83, #89, #90, #106.

Test plan

  • Full local test suite green (uv run pytest): 235 passed (was 228 + 7 new).
  • New tests cover: Mode card extras present, AC-Coupled card hidden / emitted on capability, Smart Load 10-slot enumeration, suppressibility, EMS path excludes both new cards, Energy view lists battery totals.
  • Manual: regenerate dashboard on a single-phase hybrid — AC-Coupled card absent, Smart Load present with rows unavailable.
  • Manual: regenerate on an AC-coupled / All-in-One — AC-Coupled card present and entities resolve.
  • Manual: regenerate on an EMS plant — neither new card appears.

🤖 Generated with Claude Code

Summary by CodeRabbit

  • New Features
    • Enhanced dashboard with new AC-Coupled controls for systems with AC battery capability
    • Added Smart Load slot scheduling interface with 10 configurable time slots
    • Battery total charge/discharge entities now displayed in All-Time Totals section
    • New inverter mode controls: Real Time Control and Inverter Max Output Power settings

… totals

Closes high-priority gaps between exposed entities and the generated dashboard:

- Smart Load slots 1–10 on Controls (`has_smart_load` kwarg; defaults
  open until givenergy-modbus exposes a capability we can gate on per
  #181 / 2.1.3 — wired through with a TODO).
- AC-Coupled card on Controls (export priority, EPS, AC charge/discharge
  limits) gated by `has_ac_config_block` from PlantCapabilities.
- Mode card additions: Real Time Control, Inverter Max Output Power.
- Energy → All-Time Totals: Battery Charged / Battery Discharged.
- Bumps DASHBOARD_VERSION to 8 so the Repairs prompt fires on existing
  installs. Refs #52, #76, #83, #89, #90, #106.
@coderabbitai

coderabbitai Bot commented Jun 4, 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 42 minutes and 7 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: e5a88d46-3e9f-4c14-8fee-be70d18c96af

📥 Commits

Reviewing files that changed from the base of the PR and between 2a375f7 and b273e0a.

📒 Files selected for processing (2)
  • custom_components/givenergy_local/__init__.py
  • custom_components/givenergy_local/dashboard.py
📝 Walkthrough

Walkthrough

This PR extends the Lovelace dashboard generator to conditionally render AC-Coupled and Smart Load control cards based on inverter capabilities. The service handler now derives has_ac_config_block from coordinator capabilities and has_smart_load from the EMS flag, passing both to generate_dashboard(). New functions dynamically build these card YAML blocks, and the template defines the layout. Dashboard version increments to 8, and comprehensive tests validate all conditional rendering paths.

Changes

Dashboard Capability-Driven Conditional Controls

Layer / File(s) Summary
Service handler capability enrichment
custom_components/givenergy_local/__init__.py
The SERVICE_GENERATE_DASHBOARD handler reads coordinator.data.capabilities to determine AC config block availability, computes has_smart_load as the inverse of the EMS flag, and passes both to generate_dashboard().
Function signature and version schema
custom_components/givenergy_local/dashboard.py
DASHBOARD_VERSION bumped to 8; generate_dashboard() signature extended with has_ac_config_block and has_smart_load keyword parameters, with docstring documenting their conditional rendering effects.
Conditional AC-Coupled and Smart Load rendering
custom_components/givenergy_local/dashboard.py
_controls_view() refactored to accept capability flags, compute optional card strings, and inject AC-Coupled and Smart Load card YAML. Two new control entities added (Real Time Control switch, Inverter Max Output Power). New builder functions _ac_coupled_card() and _smart_load_card() construct entity rows for the optional cards.
Dashboard template controls cards
dashboard/template.yaml
AC-Coupled card template defines export priority, EPS enable, and AC charge/discharge limits; Smart Load card template defines slots 1–3 with inline comments indicating the pattern for slots 4–10. New Mode control entities added.
Battery charge/discharge totals
custom_components/givenergy_local/dashboard.py, dashboard/template.yaml
All-Time Totals energy section reordered to include battery_charge_total and battery_discharge_total entries in updated positions.
Version and comprehensive test coverage
tests/test_dashboard.py
Version assertion updated to 8. Seven new tests validate Mode card entity presence, AC-Coupled gating by has_ac_config_block, Smart Load 10-slot rendering and suppression via has_smart_load, EMS omission of both optional cards, and Energy view battery totals.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Possibly related PRs

  • dewet22/givenergy-hass#41: Both PRs modify the dashboard generator; PR #41 introduced DASHBOARD_VERSION and generate_dashboard(), while this PR extends the function signature with capability-derived flags for conditional card rendering.
  • dewet22/givenergy-hass#96: Both PRs extend the generate_dashboard() function and service entrypoint to branch YAML output based on system flags, with this PR adding capability-derived controls on top of existing EMS branching.

Poem

🐰 A dashboard that listens, adapts, and grows,
AC and Smart Load where capability shows—
Batteries charge, discharge totals align,
Real-time control and inverter max shine,
Version eight glows, with tests to define! 🌟

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately summarizes the main changes: Smart Load and AC-Coupled controls, mode control enhancements, and battery totals—all key features in the changeset.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
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-gaps-pr-a

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.

@deepsource-io

deepsource-io Bot commented Jun 4, 2026

Copy link
Copy Markdown

DeepSource Code Review

We reviewed changes in 265e724...2a375f7 on this pull request. Below is the summary for the review, and you can see the individual issues we found as inline review comments.

See full review on DeepSource ↗

PR Report Card

Overall Grade   Security  

Reliability  

Complexity  

Hygiene  

Code Review Summary

Analyzer Status Updated (UTC) Details
Python Jun 4, 2026 6:12a.m. Review ↗

Important

AI Review is run only on demand for your team. We're only showing results of static analysis review right now. To trigger AI Review, comment @deepsourcebot review on this thread.

@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 updates the dashboard generation to conditionally include AC-coupled controls and Smart Load slot scheduling based on device capabilities, while also adding new entities like battery charge/discharge totals and real-time control switches. The review feedback suggests dynamically joining the optional cards to ensure clean and consistent spacing in the generated YAML when cards are disabled.

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.

Comment on lines +573 to +574
ac_coupled_card = _ac_coupled_card(inv) if has_ac_config_block else ""
smart_load_card = _smart_load_card(inv) if has_smart_load else ""

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

medium

To prevent inconsistent spacing and empty lines in the generated YAML when some cards are disabled (or when both are disabled), we can dynamically collect the active cards in a list, strip any leading/trailing newlines, and join them with double newlines. This ensures that there is always exactly one empty line separating the cards.

    cards = []
    if has_ac_config_block:
        cards.append(_ac_coupled_card(inv).strip("\n"))
    if has_smart_load:
        cards.append(_smart_load_card(inv).strip("\n"))
    extra_cards = "\n" + "\n\n".join(cards) + "\n" if cards else "\n"

- entity: time.givenergy_inverter_{inv}_discharge_slot_2_end
name: Slot 2 End

{ac_coupled_card}{smart_load_card}

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

medium

Use the dynamically joined extra_cards variable to ensure clean and consistent spacing between the preceding and following cards.

Suggested change
{ac_coupled_card}{smart_load_card}
{extra_cards}

@coderabbitai coderabbitai 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.

Actionable comments posted: 2

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@custom_components/givenergy_local/__init__.py`:
- Around line 568-570: The AC-coupled dashboard flag is computed from
coordinator.data.capabilities as has_ac_config_block without excluding
three-phase systems, but the AC-coupled entities in switch.py are only created
when not caps.is_three_phase, causing UI cards with missing entities; change the
computation in __init__.py (where caps = coordinator.data.capabilities and
has_ac_config_block is set) to include the three-phase exclusion (i.e., set
has_ac_config_block only when caps exists, caps.has_ac_config_block is true, and
caps.is_three_phase is false) so the dashboard gating aligns with the entity
registration logic in switch.py.

In `@custom_components/givenergy_local/dashboard.py`:
- Around line 101-109: Docstrings for the dashboard options (e.g., the
has_ac_config_block and has_smart_load entries) contain Unicode EN DASH
characters (“–”) which trigger RUF002; replace those EN DASH characters with
plain ASCII hyphens/minus ("-") in the docstrings around the referenced blocks
and the other occurrence (~lines 663-684) so all ranges use '-' instead of '–',
then run the project formatting/lint fix commands (uv run ruff check --fix && uv
run ruff format) to ensure the warning is resolved and formatting is consistent.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: fbe05bcf-2757-47a4-a0fb-6fa71d8d882e

📥 Commits

Reviewing files that changed from the base of the PR and between 265e724 and 2a375f7.

📒 Files selected for processing (4)
  • custom_components/givenergy_local/__init__.py
  • custom_components/givenergy_local/dashboard.py
  • dashboard/template.yaml
  • tests/test_dashboard.py

Comment thread custom_components/givenergy_local/__init__.py
Comment thread custom_components/givenergy_local/dashboard.py
Exclude three-phase systems from the AC-coupled card — switch.py and
number.py both gate AC-coupled entities on `not caps.is_three_phase`, so
the dashboard flag must match.  Also replace EN DASH characters in
docstrings with plain ASCII hyphens (ruff RUF002).

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@deepsource-io

deepsource-io Bot commented Jun 4, 2026

Copy link
Copy Markdown

DeepSource Code Review

We reviewed changes in 265e724...b273e0a on this pull request. Below is the summary for the review, and you can see the individual issues we found as inline review comments.

See full review on DeepSource ↗

Important

Some issues found as part of this review are outside of the diff in this pull request and aren't shown in the inline review comments due to GitHub's API limitations. You can see those issues on the DeepSource dashboard.

PR Report Card

Overall Grade   Security  

Reliability  

Complexity  

Hygiene  

Code Review Summary

Analyzer Status Updated (UTC) Details
Python Jun 4, 2026 6:30a.m. Review ↗

Important

AI Review is run only on demand for your team. We're only showing results of static analysis review right now. To trigger AI Review, comment @deepsourcebot review on this thread.

@dewet22

dewet22 commented Jun 4, 2026

Copy link
Copy Markdown
Owner Author

CodeRabbit's two findings addressed in b273e0a:

  1. has_ac_config_block three-phase exclusion: Fixed — __init__.py now checks caps.has_ac_config_block and not caps.is_three_phase, matching the gate in switch.py:102 and number.py:213.

  2. EN DASH in docstrings (RUF002): Replaced with - in the three affected docstring lines and confirmed ruff check passes.

Gemini's spacing suggestion: the generated YAML already produces exactly one blank line between cards in all combinations (both absent, one present, both present) — verified by inspecting the output. No change needed there.

@dewet22 dewet22 merged commit 12e1732 into main Jun 4, 2026
9 of 10 checks passed
@dewet22 dewet22 deleted the feat/dashboard-gaps-pr-a branch June 4, 2026 06:36
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.

1 participant