Skip to content

Decode out-of-range battery percentages to None#10

Merged
frenck merged 2 commits into
mainfrom
frenck/battery-percentage-range
Jul 15, 2026
Merged

Decode out-of-range battery percentages to None#10
frenck merged 2 commits into
mainfrom
frenck/battery-percentage-range

Conversation

@frenck

@frenck frenck commented Jul 15, 2026

Copy link
Copy Markdown
Owner

Breaking change

None for regular consumers: state_of_energy and state_of_health keep their names and types, and every in-range value reads exactly as before. Code that introspects _register_fields sees 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_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, 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

  • Dependency or tooling upgrade
  • Bugfix (non-breaking change that fixes an issue)
  • New feature (non-breaking change that adds functionality)
  • Deprecation (replaces or removes a feature, with a migration path)
  • Breaking change (a fix or feature that changes existing behavior)
  • Code quality, refactor, or test-only change
  • Documentation only

Additional information

Checklist

  • I fully understand the code in this pull request and can explain every line, including any AI-assisted changes.
  • The change is covered by tests, and poetry run pytest passes locally. A pull request cannot be merged unless CI is green.
  • poetry run prek run --all-files passes (lint, format, and type checks).
  • No commented-out or dead code is left in the pull request.

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.
Copilot AI review requested due to automatic review settings July 15, 2026 07:08
@frenck frenck added the bugfix Inconsistencies or issues which will cause a problem for users or implementers. label Jul 15, 2026
@codecov

codecov Bot commented Jul 15, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 100.00%. Comparing base (194c157) to head (f6a8c13).

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.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Copilot AI 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.

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, returning None when values are outside 0..100.
  • Add tests covering out-of-range inputs and confirming 0 and 100 remain 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.

Comment thread tests/test_solaredged.py
Copilot AI review requested due to automatic review settings July 15, 2026 07:16

Copilot AI 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.

Pull request overview

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

Comment thread tests/test_solaredged.py
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.
"""
@frenck
frenck merged commit 1542d9d into main Jul 15, 2026
31 checks passed
@frenck
frenck deleted the frenck/battery-percentage-range branch July 15, 2026 07:19
@github-actions github-actions Bot locked and limited conversation to collaborators Jul 16, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

bugfix Inconsistencies or issues which will cause a problem for users or implementers.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants