Skip to content

Conversation

@DCSBL
Copy link
Collaborator

@DCSBL DCSBL commented Dec 5, 2025

No description provided.

@codecov
Copy link

codecov bot commented Dec 5, 2025

Codecov Report

❌ Patch coverage is 97.14286% with 1 line in your changes missing coverage. Please review.
✅ Project coverage is 98.95%. Comparing base (b9dfbe6) to head (aa53a6e).
⚠️ Report is 2 commits behind head on main.

Files with missing lines Patch % Lines
homewizard_energy/models.py 97.05% 0 Missing and 1 partial ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #574      +/-   ##
==========================================
- Coverage   99.06%   98.95%   -0.11%     
==========================================
  Files           9        9              
  Lines         639      673      +34     
  Branches       51       61      +10     
==========================================
+ Hits          633      666      +33     
  Misses          3        3              
- Partials        3        4       +1     

☔ 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 adds support for a permissions parameter in the batteries endpoint to handle charge/discharge restrictions. The implementation maps user-facing modes (ZERO_CHARGE_ONLY, ZERO_DISCHARGE_ONLY) to the API's representation using a ZERO mode combined with specific permissions.

Key Changes:

  • Introduces a Permissions enum with CHARGE_ALLOWED and DISCHARGE_ALLOWED values
  • Adds a from_mode() static method to BatteriesUpdate for translating user-facing modes to API format
  • Implements __post_deserialize__() on Batteries to convert API responses back to user-facing modes based on permissions

Reviewed changes

Copilot reviewed 8 out of 8 changed files in this pull request and generated 4 comments.

Show a summary per file
File Description
homewizard_energy/models.py Adds Permissions enum, permissions field, from_mode() translation method, and __post_deserialize__() for mode mapping
homewizard_energy/v2/init.py Refactors batteries() method to use BatteriesUpdate.from_mode() for mode translation
tests/v2/test_v2_batteries.py Adds test for __post_deserialize__() mode/permissions mapping logic
tests/v2/fixtures/HWE-P1/batteries.json Adds permissions field to test fixture
tests/v2/fixtures/HWE-KWH1/batteries.json Adds permissions field to test fixture
tests/v2/fixtures/HWE-KWH3/batteries.json Adds permissions field to test fixture
tests/v2/snapshots/test_v2_homewizard_energy.ambr Updates snapshots to include permissions in Batteries objects
tests/v2/snapshots/test_v2_batteries.ambr Updates snapshots to include permissions in Batteries objects
Comments suppressed due to low confidence (1)

tests/v2/test_v2_batteries.py:111

  • The test test_batteries_update doesn't test the new user-facing modes (ZERO_CHARGE_ONLY and ZERO_DISCHARGE_ONLY) or the from_mode() method. Consider adding test cases for these modes to ensure the from_mode() method correctly translates them to the appropriate API mode and permissions.
@pytest.mark.parametrize(
    ("mode"),
    [
        Batteries.Mode.ZERO,
        Batteries.Mode.TO_FULL,
        Batteries.Mode.STANDBY,
    ],
)
async def test_batteries_update(
    mode: Batteries.Mode,
    snapshot: SnapshotAssertion,
):
    """Test Batteries update."""
    data = BatteriesUpdate(
        mode=mode,
    )
    assert snapshot == data.to_dict()

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

@DCSBL DCSBL merged commit a183e55 into main Dec 5, 2025
31 of 33 checks passed
@DCSBL DCSBL deleted the permissions-api branch December 5, 2025 14:21
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