Skip to content

feat: House Consumption Today + correct the load mislabel (modbus 2.1.1)#111

Merged
dewet22 merged 4 commits into
mainfrom
feat/modbus-2.1.1-consumption
Jun 3, 2026
Merged

feat: House Consumption Today + correct the load mislabel (modbus 2.1.1)#111
dewet22 merged 4 commits into
mainfrom
feat/modbus-2.1.1-consumption

Conversation

@dewet22

@dewet22 dewet22 commented Jun 3, 2026

Copy link
Copy Markdown
Owner

Summary

Adopts givenergy-modbus 2.1.1 (#174), which corrected two single-phase field mislabels and added the real derived house-consumption figure. This fixes the dashboard's long-standing consumption cliff — givenergy_local showed ~0 consumption because the old "Load Energy Today" sensor read IR35, which is actually AC charge, not house load.

Changes

  • New "House Consumption Today" sensor (e_consumption_today) — the GE-app "Consumption today" derived value (PV generation + grid-in − grid-out − AC-charge), single-phase only (defensive getattr + skip_if_none). The dashboard "Consumed" series now points here; DASHBOARD_VERSION 5 → 6 so existing users are prompted to regenerate.
  • Renamed the mislabelled load sensor: e_load_daye_ac_charge_today ("AC Charge Today"). A unique_id migration (_migrate_unique_ids in __init__.py) re-points the existing entity in place so its history/statistics survive rather than orphaning it.
  • Held the inverter-output pair: e_inverter_out_day entity (key/name) unchanged — the rename is deferred until the matching total (IR45/46) is verified and renamed library-side — but its value_fn reads the renamed e_pv_generation_today directly to avoid a per-poll DeprecationWarning.
  • Pin → givenergy-modbus>=2.1.1.
  • GivTCP migration script: resilient recorder writes (chunk large imports, retry on HA's command-timeout, pace entities — fixes the timeout cascade that left entities cleared-but-not-reimported mid-run), and the house-consumption pair retargeted at the real house_consumption_today sensor.

Notes

  • The ha-entity-reviewer agent confirmed the unique_id migration is correct on every edge case (slicing, multi-inverter serials, collision handling, ordering before platform setup).
  • 188 tests pass (incl. a migration round-trip test); mypy at the established baseline.
  • Inverter-output entity rename is held pending a modbus handoff to confirm/rename e_inverter_out_total (IR45/46) so today+total move together.

🤖 Generated with Claude Code

Summary by CodeRabbit

  • New Features

    • Added "House Consumption Today" and "AC Charge Today" sensors
    • Updated generated dashboards to display consumption from the new sensor
  • Bug Fixes

    • Automatic entity unique-id migration preserves entity history and avoids collisions during sensor renames
  • Documentation

    • Updated migration guide to reflect new sensor mappings
  • Tests

    • Added tests covering new sensors and migration behavior

Review Change Stack

dewet22 and others added 2 commits June 3, 2026 09:41
… (modbus 2.1.1)

givenergy-modbus 2.1.1 (#174) corrected two single-phase mislabels and added the
real derived house-consumption figure:

- New "House Consumption Today" sensor (e_consumption_today) — the GE-app
  "Consumption today" value, single-phase only (defensive getattr + skip_if_none).
  The dashboard's "Consumed" series now points here, fixing the long-standing
  ~0/cliff that came from the old bogus load sensor. DASHBOARD_VERSION 5 → 6.
- e_load_day was never house load (it's AC charge); renamed the sensor to
  "AC Charge Today" (key e_ac_charge_today). A unique_id migration in __init__.py
  re-points the existing entity in place, preserving its history/statistics
  rather than orphaning it.
- e_inverter_out_day: entity held (key/name unchanged) pending verification of the
  matching total, but its value_fn now reads the renamed e_pv_generation_today
  field directly to avoid a per-poll DeprecationWarning.
- Recommended-entities set swaps e_load_day → e_consumption_today.

Pin bumped to givenergy-modbus>=2.1.1. Entity-reviewer confirmed the migration is
correct on all edge cases (slicing, multi-inverter, collision, ordering).

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
…e real sensor

Two changes to the GivTCP statistics migration, both validated during a live
recovery:

- Recorder-write resilience: chunk large imports, retry recorder mutations on
  HA's command-timeout (clear/import are idempotent), and pace entities so the
  single-threaded recorder can drain. This is the fix for the timeout cascade
  that previously left entities cleared-but-not-reimported mid-run.
- Re-include the house-consumption pair, now targeting house_consumption_today
  (givenergy-modbus #174's real derived consumption) instead of the old
  load_energy_today mislabel that read ~0. Catalogue doc updated to match.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@coderabbitai

coderabbitai Bot commented Jun 3, 2026

Copy link
Copy Markdown

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 53 minutes and 1 second. 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: 5d913733-9803-4438-b5b7-64b88dcf90f9

📥 Commits

Reviewing files that changed from the base of the PR and between 446231f and 723710c.

📒 Files selected for processing (1)
  • scripts/migrate_from_givtcp.py
📝 Walkthrough

Walkthrough

Adds unique_id migration for renamed sensor suffixes, updates inverter sensor descriptors and recommended keys to match givenergy-modbus v2.1.1, bumps dashboard schema and templates to use house_consumption_today, improves the GivTCP migration script (recorder retries, UTC handling, chunked imports), and adds tests covering the changes.

Changes

Alignment with givenergy-modbus v2.1.1

Layer / File(s) Summary
Upstream library version update
custom_components/givenergy_local/manifest.json, pyproject.toml
givenergy-modbus dependency is pinned to >=2.1.1,<3.0.0.
Sensor field definitions and test fixtures
custom_components/givenergy_local/sensor.py, custom_components/givenergy_local/const.py, tests/conftest.py
INVERTER_SENSORS adds e_consumption_today (single-phase, skip_if_none), replaces e_load_day with e_ac_charge_today, and rewires e_inverter_out_day to read e_pv_generation_today. EXPOSE_RECOMMENDED_ENTITY_KEYS and mock_inverter updated accordingly.
Entity unique_id migration in integration setup
custom_components/givenergy_local/__init__.py
Adds _RENAMED_UNIQUE_ID_SUFFIXES and _migrate_unique_ids to rewrite old unique_id suffixes to new ones; called at start of async_setup_entry before platform setup.
Dashboard updates and version bump
custom_components/givenergy_local/dashboard.py, dashboard/template.yaml, tests/test_dashboard.py
Increment DASHBOARD_VERSION to 6 and switch dashboard "Consumed" references from load_energy_today to house_consumption_today; update test expectation.
Integration tests for sensor and entity migration behavior
tests/test_sensor.py
Adds tests verifying e_consumption_today rendering, e_ac_charge_today unique_id existence (and old e_load_day absence), and migration that preserves entity_id while updating unique_id.
GivTCP migration script enhancements and recorder resilience
scripts/migrate_from_givtcp.py, docs/migration-from-givtcp.md
Map load_energy_today_kwhhouse_consumption_today, add _call_with_retry for recorder timeouts, chunk import_statistics, use consistent UTC in helpers, improve cutover detection, add pacing during apply, and update CLI/help/docs.

Sequence Diagram

sequenceDiagram
  participant Setup as async_setup_entry
  participant Migration as _migrate_unique_ids
  participant Registry as EntityRegistry
  participant Platform as PlatformSetup

  Setup->>Migration: call with config entry
  Migration->>Registry: list entities for config entry
  Registry-->>Migration: return entity entries
  Migration->>Migration: find entries with old suffix (e_load_day)
  Migration->>Registry: update unique_id → e_ac_charge_today (skip if target exists)
  Registry-->>Migration: confirm updates
  Migration-->>Setup: migration complete
  Setup->>Platform: forward to platform setup
  Platform-->>Setup: create entities with updated descriptors
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Possibly related PRs

Suggested reviewers

  • dewet22-codex

Poem

A rabbit hops through givenergy fields so green,
v2.1.1 arrives with sensors made clean.
IDs leap lanes from old names to new,
Dashboards plot consumption true.
Migration hums, records retry with cheer—hop on, updates are here! 🐇⚡

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 42.42% 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 title clearly describes the main changes: introducing 'House Consumption Today' sensor and correcting the mislabeled load sensor with the givenergy-modbus 2.1.1 upgrade.
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/modbus-2.1.1-consumption

Warning

Review ran into problems

🔥 Problems

Git: Failed to clone repository. Please run the @coderabbitai full review command to re-trigger a full review. If the issue persists, set path_filters to include or exclude specific files.


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 3, 2026

Copy link
Copy Markdown

DeepSource Code Review

We reviewed changes in 51fbcbf...723710c 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 3, 2026 12:05p.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.

Comment thread scripts/migrate_from_givtcp.py

@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 integration to support givenergy-modbus version 2.1.1, introducing a new derived house consumption sensor (e_consumption_today) and renaming the mislabelled e_load_day sensor to e_ac_charge_today. It includes a unique ID migration path to preserve historical data, updates the dashboard template, and enhances the GivTCP migration script with recorder write resilience (chunking, retries, and pacing). A critical issue was identified in the migration script where asyncio is used for pacing and retries but is not imported, which will lead to a NameError at runtime.

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 thread scripts/migrate_from_givtcp.py

@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: 1

🧹 Nitpick comments (1)
scripts/migrate_from_givtcp.py (1)

123-123: 💤 Low value

Optional: Replace ambiguous minus sign with standard hyphen.

The comment uses the Unicode MINUS SIGN (U+2212 "−") instead of the standard ASCII HYPHEN-MINUS (U+002D "-"). While cosmetic, using ASCII avoids potential copy-paste issues and aligns with Python style.

📝 Suggested fix
-    # align; validate the overlap before an --apply.
+    # align; validate the overlap before an --apply.
     ("load_energy_today_kwh", "house_consumption_today", "House consumption today", True),

(Replace "−" with "-" in "PV + grid-in − grid-out − AC-charge")

🤖 Prompt for 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.

In `@scripts/migrate_from_givtcp.py` at line 123, Replace the Unicode MINUS SIGN
characters in the comment "PV + grid-in − grid-out − AC-charge" with standard
ASCII hyphen-minus characters so it reads "PV + grid-in - grid-out - AC-charge";
update that exact comment string in scripts/migrate_from_givtcp.py to avoid the
U+2212 character and use U+002D instead.
🤖 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/sensor.py`:
- Around line 493-497: Replace the ambiguous Unicode minus sign (U+2212) used in
the inline comment explaining "Derived house consumption" with a plain ASCII
hyphen '-' so the comment reads e.g. "(PV gen + grid-in - grid-out -
AC-charge)"; search the comment block around the derived house consumption
explanation in sensor.py and update any other occurrences of U+2212 to '-' and
re-run the linter to confirm Ruff RUF003 is resolved.

---

Nitpick comments:
In `@scripts/migrate_from_givtcp.py`:
- Line 123: Replace the Unicode MINUS SIGN characters in the comment "PV +
grid-in − grid-out − AC-charge" with standard ASCII hyphen-minus characters so
it reads "PV + grid-in - grid-out - AC-charge"; update that exact comment string
in scripts/migrate_from_givtcp.py to avoid the U+2212 character and use U+002D
instead.
🪄 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: 9b6d98ed-82ba-4e18-8f84-2594f0b1737e

📥 Commits

Reviewing files that changed from the base of the PR and between 51fbcbf and 562a717.

⛔ Files ignored due to path filters (1)
  • uv.lock is excluded by !**/*.lock
📒 Files selected for processing (12)
  • custom_components/givenergy_local/__init__.py
  • custom_components/givenergy_local/const.py
  • custom_components/givenergy_local/dashboard.py
  • custom_components/givenergy_local/manifest.json
  • custom_components/givenergy_local/sensor.py
  • dashboard/template.yaml
  • docs/migration-from-givtcp.md
  • pyproject.toml
  • scripts/migrate_from_givtcp.py
  • tests/conftest.py
  • tests/test_dashboard.py
  • tests/test_sensor.py

Comment thread custom_components/givenergy_local/sensor.py
@dewet22-codex

Copy link
Copy Markdown
Collaborator

I’ve started reviewing this PR.

Comment thread scripts/migrate_from_givtcp.py Outdated
Addresses PR #111 review:
- DeepSource (run cyclomatic complexity 42): extract the cutover-suggestion
  print, plan construction, and summary table into helpers — run() drops from
  ~161 to ~91 lines. The battle-tested execute/write path is untouched.
- CodeRabbit/Gemini (RUF003): replace ambiguous U+2212 minus signs with ASCII
  hyphens in the consumption-formula comments (sensor.py, migrate script).

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Comment thread scripts/migrate_from_givtcp.py
Addresses PR #111 review:
- Codex: the docstring listed "House load today" under "Not migrated", but
  INVERTER_PAIRS now migrates it (as house consumption). Moved it into the
  default-migrated list and dropped the stale exclusion.
- DeepSource: replace _print_summary's four sum() comprehensions with a single
  Counter, cutting its cyclomatic complexity below the gate.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@dewet22-codex

Copy link
Copy Markdown
Collaborator

I’ve started re-reviewing this PR.

@dewet22-codex dewet22-codex left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Approved. I re-reviewed the current head and do not have any actionable concerns. I checked the updated diff and current GitHub checks; the earlier migration-script help-text finding has been addressed.

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