Skip to content

Conversation

@DCSBL
Copy link
Collaborator

@DCSBL DCSBL commented Jan 9, 2026

Before:

# API 2.1.0
Batteries.from_json("{\"mode\": \"zero\"}") → “standby-- WRONG
Batteries.from_json("{\"mode\": \"standby\"}”) → “standby# API 2.2.0
Batteries.from_json("{\"mode\": \"zero\", \"permissions\": [\"charge_allowed\", \"discharge_allowed\"]}”) → “zero"
Batteries.from_json("{\"mode\": \"standby\", \"permissions\": []}”) → “standby

After:

# API 2.1.0
Batteries.from_json("{\"mode\": \"zero\"}") → “zero-- FIXED
Batteries.from_json("{\"mode\": \"standby\"}”) → “standby# API 2.2.0
Batteries.from_json("{\"mode\": \"zero\", \"permissions\": [\"charge_allowed\", \"discharge_allowed\"]}”) → “zero"
Batteries.from_json("{\"mode\": \"standby\", \"permissions\": []}”) → “standby

@codecov
Copy link

codecov bot commented Jan 9, 2026

Codecov Report

❌ Patch coverage is 92.85714% with 1 line in your changes missing coverage. Please review.
✅ Project coverage is 99.26%. Comparing base (824bdf9) to head (b4f0ed1).
⚠️ Report is 5 commits behind head on main.

Files with missing lines Patch % Lines
homewizard_energy/models.py 92.85% 0 Missing and 1 partial ⚠️
Additional details and impacted files
@@           Coverage Diff           @@
##             main     #587   +/-   ##
=======================================
  Coverage   99.26%   99.26%           
=======================================
  Files           9        9           
  Lines         679      682    +3     
  Branches       62       63    +1     
=======================================
+ Hits          674      677    +3     
  Misses          2        2           
  Partials        3        3           

☔ View full report in Codecov by Sentry.
📢 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.

Copy link
Contributor

Copilot AI left a comment

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 fixes a bug where older firmware (API 2.1.0) in battery 'zero' mode was incorrectly treated as 'standby' due to the missing permissions field. The fix distinguishes between a missing permissions field (older firmware) and an explicitly empty permissions array (intentional standby mode).

Key changes:

  • Made the permissions field nullable to distinguish between missing and empty
  • Added backwards compatibility logic to preserve 'zero' mode when permissions field is absent
  • Added test fixtures for both API versions (2.1.0 without permissions, 2.2.0 with permissions)

Reviewed changes

Copilot reviewed 5 out of 5 changed files in this pull request and generated no comments.

Show a summary per file
File Description
homewizard_energy/models.py Changed permissions field to nullable, updated deserialization logic, and added backwards compatibility in post_deserialize to keep mode as ZERO when permissions is None
tests/v2/test_v2_batteries.py Updated test parametrization to test both API 2.1.0 and 2.2.0 fixtures for HWE-P1 model
tests/v2/fixtures/HWE-P1/batteries_2_1_0.json Added fixture for API 2.1.0 (older firmware) with mode="zero" but no permissions field
tests/v2/fixtures/HWE-P1/batteries_2_2_0.json Added fixture for API 2.2.0 (newer firmware) with mode="zero" and permissions field
tests/v2/snapshots/test_v2_batteries.ambr Updated snapshots to reflect expected behavior for both API versions

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@DCSBL DCSBL enabled auto-merge (squash) January 11, 2026 16:25
@DCSBL DCSBL merged commit 44869d2 into main Jan 11, 2026
32 of 33 checks passed
@DCSBL DCSBL deleted the fix-nill-permission-treaded-as-standby branch January 11, 2026 16:27
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.

1 participant