Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Add preliminary support for HWE-BAT #438

Merged
merged 2 commits into from
Dec 27, 2024
Merged

Add preliminary support for HWE-BAT #438

merged 2 commits into from
Dec 27, 2024

Conversation

DCSBL
Copy link
Collaborator

@DCSBL DCSBL commented Dec 27, 2024

Add support for two new sensor values (cycles and state_of_charge_pct).

Important: These decision of these sensors are not yet final.

Summary by CodeRabbit

  • New Features

    • Added new attributes for cycles and state_of_charge_pct to the measurement data model.
    • Introduced new JSON files for device, measurement, and system configurations for the "HWE-BAT" model.
    • Enhanced test coverage with new test cases for the "HWE-BAT" model.
  • Bug Fixes

    • Updated existing test snapshots to include new attributes for consistency.
  • Documentation

    • Added detailed metadata for the new device, measurement, and system JSON files.

Copy link
Contributor

coderabbitai bot commented Dec 27, 2024

Walkthrough

The pull request introduces new optional attributes, cycles and state_of_charge_pct, to the Measurement data class in the HomeWizard Energy library. These attributes enhance the data model's capability to capture additional energy-related metrics. The changes include updates to the model definition, test snapshots, and the addition of new test fixtures for the "HWE-BAT" (Plug-in Battery) device type. The modifications extend the library's support for more comprehensive energy measurement tracking.

Changes

File Change Summary
homewizard_energy/v2/models.py Added optional `cycles: int
tests/v2/__snapshots__/test_v2_homewizard_energy.ambr Updated snapshots to include new cycles and state_of_charge_pct attributes
tests/v2/__snapshots__/test_v2_models.ambr Added new snapshots for HWE-BAT device, measurement, and system
tests/v2/fixtures/HWE-BAT/device.json New fixture for HWE-BAT device metadata
tests/v2/fixtures/HWE-BAT/measurement.json New fixture for HWE-BAT energy measurements
tests/v2/fixtures/HWE-BAT/system.json New fixture for HWE-BAT system configuration
tests/v2/test_v2_models.py Added test cases for HWE-BAT model across device, measurement, and system tests

Sequence Diagram

sequenceDiagram
    participant Client
    participant Measurement
    participant Device
    
    Client->>Measurement: Create with optional cycles and state_of_charge_pct
    Measurement-->>Client: Measurement object
    
    Client->>Device: Retrieve device measurements
    Device-->>Client: Return Measurement with new attributes
Loading

The sequence diagram illustrates how the new attributes can be incorporated into the measurement creation and retrieval process, showing the optional nature of the cycles and state_of_charge_pct attributes.


🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR. (Beta)
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@DCSBL DCSBL changed the title Add preliminery support for HWE-BAT Add preliminary support for HWE-BAT Dec 27, 2024
Copy link

codecov bot commented Dec 27, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 98.94%. Comparing base (e2f1979) to head (873dccd).
Report is 1 commits behind head on main.

Additional details and impacted files
@@           Coverage Diff           @@
##             main     #438   +/-   ##
=======================================
  Coverage   98.94%   98.94%           
=======================================
  Files           9        9           
  Lines         567      569    +2     
  Branches       41       41           
=======================================
+ Hits          561      563    +2     
  Misses          6        6           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

🧹 Nitpick comments (1)
tests/v2/test_v2_models.py (1)

43-48: Expanded measurement test coverage to HWE-BAT
Including "HWE-BAT" in the measurement parameterization is a solid improvement, ensuring that the new measurement fields (like cycles and state_of_charge_pct) are tested. Consider extending the test coverage to include edge or boundary values for these new fields.

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between f08b0e6 and 326d452.

📒 Files selected for processing (7)
  • homewizard_energy/v2/models.py (2 hunks)
  • tests/v2/__snapshots__/test_v2_homewizard_energy.ambr (1 hunks)
  • tests/v2/__snapshots__/test_v2_models.ambr (1 hunks)
  • tests/v2/fixtures/HWE-BAT/device.json (1 hunks)
  • tests/v2/fixtures/HWE-BAT/measurement.json (1 hunks)
  • tests/v2/fixtures/HWE-BAT/system.json (1 hunks)
  • tests/v2/test_v2_models.py (3 hunks)
✅ Files skipped from review due to trivial changes (3)
  • tests/v2/fixtures/HWE-BAT/system.json
  • tests/v2/fixtures/HWE-BAT/device.json
  • tests/v2/fixtures/HWE-BAT/measurement.json
🔇 Additional comments (13)
tests/v2/test_v2_models.py (2)

19-19: Introduced new test parameter for HWE-BAT device
The addition of "HWE-BAT" to the device test coverage looks good. This ensures that the new device type is properly tested alongside existing ones.


66-66: Added HWE-BAT to system test parameter
Including the "HWE-BAT" model in the system test ensures that all relevant device types have system-level coverage. No immediate issues are observed.

tests/v2/__snapshots__/test_v2_homewizard_energy.ambr (2)

6-6: Snapshot includes new fields for HWE-BAT
The snapshot's Measurement instances now capture cycles=None and state_of_charge_pct=None. This is aligned with the newly introduced attributes. Be sure to confirm that None states are tested for correctness.


9-9: Second snapshot with new optional fields
Similarly, this snapshot also shows the added attributes. Looks consistent with the updated model.

tests/v2/__snapshots__/test_v2_models.ambr (7)

2-3: Added snapshot for HWE-BAT device
Lines 2-3 introduce a new snapshot test for the HWE-BAT device. Validates product_type='HWE-BAT' and relevant fields. Implementation is consistent, no issues found.


8-9: Added snapshot for HWE-BAT measurement
Lines 8-9 show a new measurement snapshot for "HWE-BAT", including state_of_charge_pct=50.123. This aligns with the new attribute in the model.


12-12: Updated snapshot with new measurement fields
The updated snapshot includes cycles=None and state_of_charge_pct=None. Matches the model changes.


15-15: Updated snapshot with new measurement fields
Again, verifying that cycles=None and state_of_charge_pct=None are included in the measurement snapshot. No concerns.


18-18: Support for edge-case measurement snapshot
Shows cycles=None and state_of_charge_pct=None for an edge-case measurement. This ensures correct handling for uninitialized data.


21-21: Another updated snapshot with new measurement fields
Same pattern here with cycles=None and state_of_charge_pct=None. Good to see consistency across multiple fixtures.


23-24: Added system snapshot for HWE-BAT
These lines show the new system test snapshot for HWE-BAT. The fields match the data from the fixture (api_v1_enabled=None is tested as well).

homewizard_energy/v2/models.py (2)

81-82: New fields in Measurement data class
The attributes cycles (int | None) and state_of_charge_pct (float | None) effectively extend functionality for battery devices. This is well-structured, and using optional types is appropriate for cases where values may not be available.


189-190: Extended from_dict to map new attributes
Mapping cycles and state_of_charge_pct in from_dict ensures the new fields are deserialized properly. Good job including them consistently with other Measurement attributes.

@DCSBL DCSBL force-pushed the add-battery-sensor-support branch from 326d452 to ffd4652 Compare December 27, 2024 20:57
@DCSBL DCSBL enabled auto-merge (squash) December 27, 2024 20:58
Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

🧹 Nitpick comments (2)
tests/v2/__snapshots__/test_v2_models.ambr (1)

8-9: HWE-BAT measurement test snapshot is aligned with the newly introduced attributes.

The addition of cycles=123 and state_of_charge_pct=50.123 aligns well with the PR objectives. Ensure any new logic referencing these fields is also tested against unexpected or edge values (e.g., negative cycles or 100+ state_of_charge_pct).

tests/v2/fixtures/HWE-BAT/measurement.json (1)

1-10: New measurement fixture for HWE-BAT includes newly introduced fields.

The JSON structure (including cycles and state_of_charge_pct) is aligned with the updated Measurement data class. Double-check for potential data type validations (e.g., negative cycle counts, out-of-range SoC).

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 326d452 and ffd4652.

📒 Files selected for processing (7)
  • homewizard_energy/v2/models.py (2 hunks)
  • tests/v2/__snapshots__/test_v2_homewizard_energy.ambr (1 hunks)
  • tests/v2/__snapshots__/test_v2_models.ambr (1 hunks)
  • tests/v2/fixtures/HWE-BAT/device.json (1 hunks)
  • tests/v2/fixtures/HWE-BAT/measurement.json (1 hunks)
  • tests/v2/fixtures/HWE-BAT/system.json (1 hunks)
  • tests/v2/test_v2_models.py (3 hunks)
🚧 Files skipped from review as they are similar to previous changes (5)
  • tests/v2/fixtures/HWE-BAT/device.json
  • tests/v2/fixtures/HWE-BAT/system.json
  • homewizard_energy/v2/models.py
  • tests/v2/test_v2_models.py
  • tests/v2/snapshots/test_v2_homewizard_energy.ambr
🔇 Additional comments (8)
tests/v2/__snapshots__/test_v2_models.ambr (8)

2-3: Preliminary HWE-BAT test device addition looks good.

The new snapshot for test_device[HWE-BAT-fixtures1] is consistent with the HWE-BAT device definition and includes the expected battery-specific parameters.


10-10: Snapshot separator comment.
No functional changes detected here.


12-12: Updated label for HWE-P1 measurement test snapshot.
No issues found with changing the snapshot name and referencing for the same or extended attributes.


15-15: Re-labeled HWE-P1 measurement snapshot.
No concerns here; simply an additional scenario.


18-18: Another HWE-P1 measurement snapshot.
This still references older or default values for cycles and state_of_charge_pct (both are None). No issues found.


21-21: HWE-P1 measurement scenario #3.
Again, no functional changes aside from possible snapshot labeling for test coverage.


22-22: Snapshot separator comment.
No changes to functionality.


23-24: System snapshot for HWE-BAT.

The addition of this snapshot includes attributes relevant to HWE-BAT, such as disabling cloud and providing an uptime. Looks like a straightforward new test scenario.

@DCSBL DCSBL merged commit 0cdc49a into main Dec 27, 2024
30 checks passed
@DCSBL DCSBL deleted the add-battery-sensor-support branch December 27, 2024 21:12
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant