-
Notifications
You must be signed in to change notification settings - Fork 6
Add support for permissions parameter in api/batteries endpoint #574
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
Codecov Report❌ Patch coverage is
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. 🚀 New features to boost your workflow:
|
There was a problem hiding this 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
Permissionsenum withCHARGE_ALLOWEDandDISCHARGE_ALLOWEDvalues - Adds a
from_mode()static method toBatteriesUpdatefor translating user-facing modes to API format - Implements
__post_deserialize__()onBatteriesto 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_updatedoesn't test the new user-facing modes (ZERO_CHARGE_ONLY and ZERO_DISCHARGE_ONLY) or thefrom_mode()method. Consider adding test cases for these modes to ensure thefrom_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.
No description provided.