Skip to content

Add optional battery capacity override for Fronius GEN24#404

Merged
MaStr merged 3 commits into
mainfrom
claude/fronius-battery-capacity-uw8s9c
Jul 22, 2026
Merged

Add optional battery capacity override for Fronius GEN24#404
MaStr merged 3 commits into
mainfrom
claude/fronius-battery-capacity-uw8s9c

Conversation

@MaStr

@MaStr MaStr commented Jul 22, 2026

Copy link
Copy Markdown
Owner

Summary

Adds support for an optional capacity configuration parameter that allows users to override the battery capacity value queried from the Fronius GEN24 inverter's Solar.API. This is useful when the inverter's reported DesignedCapacity does not match the actual usable capacity.

Changes

  • FroniusWR initialization: Modified __init__ to read capacity from config (defaults to -1 if not provided), replacing the hardcoded initialization
  • Capacity query logic: Updated get_capacity() to return the configured override if set (≥ 0), otherwise query and cache from inverter as before
  • Factory pattern: Extended Inverter.create_inverter() to forward the optional capacity parameter to FroniusWR
  • Configuration: Added capacity parameter documentation to batcontrol_config_dummy.yaml and docs/configuration/inverter-configuration.md
  • Tests: Added comprehensive test suite (test_fronius_capacity.py) covering:
    • Default behavior (capacity queried from inverter)
    • Override behavior (configured capacity used instead)
    • Integration with get_max_capacity()
  • Factory tests: Updated existing factory tests to include the new capacity parameter in expected calls

Implementation Details

  • The capacity override uses a sentinel value of -1 to distinguish "not configured" from "configured to 0"
  • When configured, the override avoids an extra HTTP call to the inverter's storage endpoint
  • Backward compatible: existing configs without the capacity key continue to work unchanged
  • Follows the existing factory pattern used for other optional Fronius parameters (fronius_inverter_id, fronius_controller_id)

https://claude.ai/code/session_01SBpQyLv7qhW6Gb1q6yrKcG

Adds an optional 'capacity' config key for the fronius_gen24 inverter type.
When set, batcontrol uses this fixed value in Wh instead of querying
DesignedCapacity from the inverter's Solar.API at startup, mirroring the
existing behavior of the fronius-modbus and mqtt inverter backends.
Copilot AI review requested due to automatic review settings July 22, 2026 10:59

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Adds an optional capacity override for the Fronius GEN24 inverter backend so users can supply a fixed battery capacity (Wh) when the inverter’s reported DesignedCapacity is inaccurate, while keeping the previous behavior (query + cache from Solar.API) as the default.

Changes:

  • Forward new capacity parameter through the inverter factory to FroniusWR (default -1 sentinel).
  • Use the configured override in FroniusWR.get_capacity() when set; otherwise query/caches DesignedCapacity from Solar.API as before.
  • Add documentation and tests covering default vs override behavior and factory forwarding.

Reviewed changes

Copilot reviewed 6 out of 6 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
src/batcontrol/inverter/inverter.py Forwards optional capacity config into the Fronius GEN24 inverter config mapping.
src/batcontrol/inverter/fronius.py Reads capacity from config and returns it from get_capacity() when configured.
tests/batcontrol/inverter/test_inverter_factory.py Updates factory expectations and adds a test ensuring capacity is forwarded.
tests/batcontrol/inverter/test_fronius_capacity.py New tests for default capacity query vs configured override and get_max_capacity() integration.
config/batcontrol_config_dummy.yaml Documents the new optional capacity parameter in the reference config.
docs/configuration/inverter-configuration.md Documents capacity for Fronius GEN24 inverter configuration.

Comment thread src/batcontrol/inverter/fronius.py Outdated
Comment on lines +186 to +188
# Optional override: use a fixed capacity from config instead of
# querying it from the inverter (DesignedCapacity via Solar.API).
self.capacity = config.get('capacity', -1)
Addresses Copilot review feedback: a quoted numeric capacity in YAML
(e.g. '10000') previously reached the self.capacity >= 0 comparison
as a string and raised TypeError. Coerce during initialization and
raise a clear RuntimeError on invalid input instead.
Copilot AI review requested due to automatic review settings July 22, 2026 11:04

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 6 out of 6 changed files in this pull request and generated 2 comments.

Comment on lines +690 to +694
""" Coerce the configured 'capacity' value to a float.
Accepts numbers or numeric strings (as YAML may quote them),
so runtime behavior stays deterministic instead of raising a
TypeError later out of get_capacity().
"""

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

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

Checked this against the rest of the file: send_request's docstring already uses this exact same continuation-indent style (aligned under the opening """ text rather than flush with the def body), so _parse_capacity_config is consistent with existing precedent here. pylint also raises no docstring-formatting warning for it. Leaving as-is; happy to revisit if there's a specific lint rule this should satisfy.


Generated by Claude Code

Comment thread src/batcontrol/inverter/fronius.py
float() happily parses 'inf'/'nan', which would make self.capacity >= 0
false (NaN) or propagate inf/NaN into downstream energy calculations.
Reject non-finite values explicitly, per Copilot review feedback.
Copilot AI review requested due to automatic review settings July 22, 2026 11:09

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 6 out of 6 changed files in this pull request and generated 1 comment.

Comment on lines +702 to +706
if not math.isfinite(parsed_capacity):
raise RuntimeError(
f"Invalid 'capacity' config value: {capacity!r}. Must be a finite number (Wh)."
)
return parsed_capacity
@MaStr
MaStr merged commit e6c098d into main Jul 22, 2026
14 checks passed
@MaStr
MaStr deleted the claude/fronius-battery-capacity-uw8s9c branch July 22, 2026 11:19
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.

3 participants