Decode out-of-range battery percentages to None#10
Merged
Conversation
An initializing battery (and the odd communication glitch) reports a state of energy or state of health outside 0-100: negative values, values just above 100, or plain float garbage. Those are not readings, and for a consumer graphing the percentage they are indistinguishable from real data. Both long-standing community integrations (solaredge-modbus-multi and home-assistant-solaredge-modbus) reject these values for that reason. state_of_energy and state_of_health are now properties over private raw fields, following the site_limit pattern: a value outside 0-100 decodes to None, the boundaries are inclusive. The community dump snapshots only rename the raw keys; every captured value was within range.
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #10 +/- ##
=========================================
Coverage 100.00% 100.00%
=========================================
Files 7 7
Lines 814 824 +10
Branches 49 50 +1
=========================================
+ Hits 814 824 +10 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
There was a problem hiding this comment.
Pull request overview
This PR improves battery percentage decoding in python-solaredged by treating invalid battery state-of-energy and state-of-health readings as absent data (None), preventing out-of-range values from being consumed as real percentages.
Changes:
- Add percentage normalization for battery
state_of_energy/state_of_health, returningNonewhen values are outside0..100. - Add tests covering out-of-range inputs and confirming
0and100remain valid readings. - Update community dump snapshots and README to reflect the adjusted decoding behavior.
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
src/solaredged/components.py |
Adds _percentage() helper and switches battery SoE/SoH to validated properties over raw register fields. |
tests/test_solaredged.py |
Adds test coverage for out-of-range battery percentages and boundary values. |
tests/__snapshots__/test_community_dumps.ambr |
Updates snapshots to reflect renamed raw battery fields in decoded register-field output. |
README.md |
Documents that out-of-range battery percentages decode to None. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
…tage-range # Conflicts: # README.md
Comment on lines
+328
to
+332
| """A battery state of energy or health outside 0-100 decodes to None. | ||
|
|
||
| An initializing battery (and the odd communication glitch) reports | ||
| percentages outside the meaningful range; those are garbage, not readings. | ||
| """ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Breaking change
None for regular consumers:
state_of_energyandstate_of_healthkeep their names and types, and every in-range value reads exactly as before. Code that introspects_register_fieldssees the raw points under their new private names (_state_of_energy_raw,_state_of_health_raw).Proposed change
An initializing battery (and the odd communication glitch) reports a state of energy or state of health outside 0-100: negative values, values just above 100, or plain float garbage. Those are not readings, and a consumer graphing the percentage cannot tell them from real data. Both long-standing community integrations reject these values for that reason: solaredge-modbus-multi returns None outside 0-100, and home-assistant-solaredge-modbus validates the same bounds.
state_of_energyandstate_of_healthare now properties over private raw fields, following thesite_limitpattern: a value outside 0-100 decodes toNone, and the boundaries are inclusive so an empty or perfectly healthy battery still reads as a value. The community dump snapshots only rename the raw keys; every captured value was within range, so no real data changes.Type of change
Additional information
SolarEdgeBatterySOE)Checklist
poetry run pytestpasses locally. A pull request cannot be merged unless CI is green.poetry run prek run --all-filespasses (lint, format, and type checks).