Add optional battery capacity override for Fronius GEN24#404
Conversation
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.
There was a problem hiding this comment.
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
capacityparameter through the inverter factory toFroniusWR(default-1sentinel). - Use the configured override in
FroniusWR.get_capacity()when set; otherwise query/cachesDesignedCapacityfrom 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. |
| # 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.
| """ 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(). | ||
| """ |
There was a problem hiding this comment.
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
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.
| if not math.isfinite(parsed_capacity): | ||
| raise RuntimeError( | ||
| f"Invalid 'capacity' config value: {capacity!r}. Must be a finite number (Wh)." | ||
| ) | ||
| return parsed_capacity |
Summary
Adds support for an optional
capacityconfiguration 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 reportedDesignedCapacitydoes not match the actual usable capacity.Changes
__init__to readcapacityfrom config (defaults to -1 if not provided), replacing the hardcoded initializationget_capacity()to return the configured override if set (≥ 0), otherwise query and cache from inverter as beforeInverter.create_inverter()to forward the optionalcapacityparameter to FroniusWRcapacityparameter documentation tobatcontrol_config_dummy.yamlanddocs/configuration/inverter-configuration.mdtest_fronius_capacity.py) covering:get_max_capacity()capacityparameter in expected callsImplementation Details
capacitykey continue to work unchangedfronius_inverter_id,fronius_controller_id)https://claude.ai/code/session_01SBpQyLv7qhW6Gb1q6yrKcG