Skip to content

Conversation

@bouwew
Copy link
Contributor

@bouwew bouwew commented Feb 20, 2025

And adapt/improve where required/possible

Summary by CodeRabbit

  • New Features

    • Enhanced error reporting to alert users when key data is missing.
    • Added a new constant NONE for better error handling.
  • Refactor

    • Streamlined sensor data processing with simplified rounding and default handling.
    • Adjusted function outputs for improved clarity and efficiency.
    • Improved control flow in the appliance heater information processing, allowing for early exits when no valid heater ID is found.
    • Modified appliance information retrieval to ensure a new object is returned when no valid data is found.

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Feb 20, 2025

Warning

Rate limit exceeded

@bouwew has exceeded the limit for the number of commits or files that can be reviewed per hour. Please wait 12 minutes and 12 seconds before requesting another review.

⌛ How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.

Please see our FAQ for further information.

📥 Commits

Reviewing files that changed from the base of the PR and between 5eddea6 and a5354aa.

📒 Files selected for processing (2)
  • CHANGELOG.md (1 hunks)
  • pyproject.toml (1 hunks)

Walkthrough

The changes introduce a new constant NONE in the plugwise/util.py file and modify the check_heater_central function to return NONE when the hc_list is empty. The power_data_energy_diff function has been updated to return None, reflecting a change in its return type. Additionally, the _appl_heater_central_info method in the SmileCommon class now includes a conditional check for self._heater_id to improve control flow. The _appliance_info_finder method in SmileHelper has also been adjusted to return a new instance of Munch() when no valid appliance information is found.

Changes

File Change Summary
plugwise/util.py - New Constant: Added NONE.
- Function Update: Modified check_heater_central to return NONE for empty hc_list.
- Return Type Change: Updated power_data_energy_diff to return None instead of GwEntityData.
- Rounding Logic: Streamlined format_measure for efficiency.
plugwise/common.py - Control Flow Update: Added early return in _appl_heater_central_info if self._heater_id is NONE.
plugwise/helper.py - Return Behavior Change: Updated _appliance_info_finder to return a new instance of Munch() instead of the existing appl object when no valid appliance information is found.

Possibly related PRs

  • Energy-device-related improvements #647: The changes in the main PR, particularly the introduction of the constant NONE and modifications to the check_heater_central function, are directly related to the changes in the retrieved PR, which also involves the handling of heater IDs and their validation.
  • Continuous improvement #678: The changes in the main PR are related to the modifications in the plugwise/util.py file, specifically in the format_measure function, which is also altered in the retrieved PR.
  • Improve model_id implementation #619: The changes in the main PR, specifically the introduction of the constant NONE and its usage in the check_heater_central function, are related to the modifications in the retrieved PR where NONE is checked in the _appl_heater_central_info method.

Suggested labels

quality

Suggested reviewers

  • CoMPaTech

Poem

Hi! I'm your hoppy rabbit,
Dancing through the code so free. 🐇
New checks and streamlined logic,
Bring order where chaos used to be.
Leaping forward with each bug untangled,
I celebrate these changes with glee!


Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

❤️ Share
🪧 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 or @coderabbitai title 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.

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)
plugwise/util.py (1)

235-235: LGTM! Consider documenting the side effect.

The function logic has been improved by:

  • Using get with a default value for safer dictionary access
  • Conditionally rounding only when f_val is a float
  • Modifying data in place instead of returning it

Consider adding a docstring note about the side effect of modifying the data parameter in place:

 def power_data_energy_diff(
     measurement: str,
     net_string: SensorType,
     f_val: float | int,
     data: GwEntityData,
 ) -> None:
-    """Calculate differential energy."""
+    """Calculate differential energy.
+    
+    Note: This function modifies the `data` parameter in place.
+    """

Also applies to: 242-246

📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between a349cc9 and 10a2872.

📒 Files selected for processing (1)
  • plugwise/util.py (5 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (2)
  • GitHub Check: Run pytest using Python 3.12
  • GitHub Check: Run pytest using Python 3.13.0
🔇 Additional comments (3)
plugwise/util.py (3)

31-31: LGTM!

The import of DataMissingError is correctly placed and used in the check_heater_central function.


97-100: LGTM! Consider adding test coverage for the error case.

The error handling for missing central heating boiler is well-implemented with a descriptive message. However, the pragma: no cover suggests this edge case isn't tested.

Would you like me to help generate test cases for this error scenario?


209-215: LGTM!

The rounding logic has been improved with clearer, more direct assignments while maintaining consistent precision levels.

@codecov
Copy link

codecov bot commented Feb 20, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 100.00%. Comparing base (7e2560d) to head (a5354aa).
Report is 19 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff            @@
##              main      #713   +/-   ##
=========================================
  Coverage   100.00%   100.00%           
=========================================
  Files           21        21           
  Lines         3419      3418    -1     
=========================================
- Hits          3419      3418    -1     

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

plugwise/util.py Outdated
if not hc_list:
raise DataMissingError(
"No Central heating boiler found, please create an Issue"
) # pragma: no cover
Copy link
Member

Choose a reason for hiding this comment

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

Thats a bit vague - as we probably re-raise this from the front-end, I'd suggest we make a BoilerDataMissingError (and don't care too much about the actual message since we don't necessarily raise user errors from the supporting lib

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Agreed, I'll let it return NONE then we can detect that someplace else if we really want that.

@bouwew
Copy link
Contributor Author

bouwew commented Feb 21, 2025

In a next PR, checking for the presence of a heater_central, when the Smile-type is thermostat, will be added.

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)
plugwise/util.py (1)

32-32: Consider implementing error handling using DataMissingError.

The DataMissingError is imported but never used. Based on past review comments, this exception was intended to be used for handling missing boiler data. Consider implementing proper error handling:

  1. Raise DataMissingError in check_heater_central when hc_list is empty
  2. Handle the exception in the frontend code

Apply this diff to implement error handling:

 def check_heater_central(xml: etree.Element) -> str:
     """Find the valid heater_central, helper-function for _appliance_info_finder().
 
     Solution for Core Issue #104433,
     for a system that has two heater_central appliances.
     """
     locator = "./appliance[type='heater_central']"
     hc_count = 0
     hc_list: list[dict[str, bool]] = []
     for heater_central in xml.findall(locator):
         hc_count += 1
         hc_id: str = heater_central.attrib["id"]
         has_actuators: bool = (
             heater_central.find("actuator_functionalities/") is not None
         )
         # Filter for Plug/Circle/Stealth heater_central -- Pw-Beta Issue #739
         if heater_central.find("name").text == "Central heating boiler":
             hc_list.append({hc_id: has_actuators})
 
     if not hc_list:
-        return NONE  # pragma: no cover
+        raise DataMissingError("No valid heater central found")  # pragma: no cover
🧰 Tools
🪛 Ruff (0.8.2)

32-32: plugwise.exceptions.DataMissingError imported but unused

Remove unused import: plugwise.exceptions.DataMissingError

(F401)

📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 42666a6 and a842e36.

📒 Files selected for processing (2)
  • plugwise/common.py (1 hunks)
  • plugwise/util.py (6 hunks)
🧰 Additional context used
🪛 Ruff (0.8.2)
plugwise/util.py

32-32: plugwise.exceptions.DataMissingError imported but unused

Remove unused import: plugwise.exceptions.DataMissingError

(F401)

🔇 Additional comments (4)
plugwise/common.py (1)

79-81: LGTM! Early return pattern improves error handling.

The addition of an early return when no valid heater ID is found prevents unnecessary processing and improves the control flow.

plugwise/util.py (3)

98-100: LGTM! Improved error handling for empty heater list.

The addition of an early return with NONE when no heater is found improves error handling and aligns with the changes in _appl_heater_central_info.


207-214: LGTM! Streamlined rounding logic.

The rounding logic has been simplified and optimized while maintaining the same functionality.


240-245: LGTM! Simplified differential energy calculation.

The logic for calculating differential energy has been streamlined and improved.

@bouwew bouwew force-pushed the digisaster-contrib branch from a842e36 to ad09f6d Compare February 21, 2025 14:32
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: 1

🧹 Nitpick comments (2)
plugwise/util.py (2)

98-100: Add test coverage for empty hc_list case.

The empty list check is marked with # pragma: no cover, indicating missing test coverage for this edge case.

Would you like me to help generate test cases to cover this scenario?


104-107: Consider improving readability of heater ID selection.

While using next(iter()) is more concise, it might be less readable. Consider using a more explicit approach:

-            if next(iter(item.values())):
-                heater_central_id = next(iter(item))  # pragma: no cover
-                # Stop when a valid id is found
-                break  # pragma: no cover
+            heater_id, has_actuators = next(iter(item.items()))  # Unpack the only key-value pair
+            if has_actuators:
+                heater_central_id = heater_id  # pragma: no cover
+                break  # Stop when a valid id is found  # pragma: no cover
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between a842e36 and c47e045.

📒 Files selected for processing (2)
  • plugwise/common.py (1 hunks)
  • plugwise/util.py (6 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • plugwise/common.py
🧰 Additional context used
🪛 Ruff (0.8.2)
plugwise/util.py

32-32: plugwise.exceptions.DataMissingError imported but unused

Remove unused import: plugwise.exceptions.DataMissingError

(F401)

🪛 GitHub Actions: Latest commit
plugwise/util.py

[error] 32-32: Ruff: plugwise.exceptions.DataMissingError imported but unused. Remove unused import.

🔇 Additional comments (2)
plugwise/util.py (2)

233-245: LGTM! Good improvements to the energy calculation logic.

The changes improve the function by:

  • Modifying data in place instead of returning it
  • Adding type safety for rounding operations
  • Simplifying the differential energy calculation

207-214: LGTM! Clear and well-structured rounding logic.

The changes improve readability by making the rounding rules explicit and easier to understand.

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: 1

📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between c47e045 and c085924.

📒 Files selected for processing (2)
  • plugwise/common.py (1 hunks)
  • plugwise/util.py (5 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • plugwise/common.py
⏰ Context from checks skipped due to timeout of 90000ms (2)
  • GitHub Check: Create pytest cache for Python 3.12
  • GitHub Check: Create pytest cache for Python 3.13.0
🔇 Additional comments (5)
plugwise/util.py (5)

16-16: LGTM!

The NONE constant import is correctly placed with other constants from plugwise.constants.


97-98: LGTM!

Good defensive programming practice to handle the case when no valid heater central is found.


206-213: LGTM!

The rounding logic has been simplified and made more consistent:

  • 3 decimal places for special formats
  • 1 decimal place for voltage measurements
  • 2 decimal places for values < 10
  • 1 decimal place for values >= 10

232-244: LGTM!

Good improvements to the function:

  • Changed to modify data in-place instead of returning it
  • Simplified energy differential calculation
  • Added safe dictionary access using get
  • Made rounding conditional on value type

141-141: LGTM!

The removal of data assignment aligns with power_data_energy_diff now modifying data in-place.

@bouwew bouwew force-pushed the digisaster-contrib branch from 29871fd to d90fe51 Compare February 22, 2025 08:34
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)
plugwise/util.py (1)

103-106: Consider improving readability and test coverage.

The logic simplification using next(iter()) is more concise but might be less intuitive. Additionally, these code paths are not covered by tests.

Consider this more readable alternative:

-            if next(iter(item.values())):
-                heater_central_id = next(iter(item))  # pragma: no cover
-                # Stop when a valid id is found
-                break  # pragma: no cover
+            hc_id, has_actuators = next(iter(item.items()))
+            if has_actuators:
+                heater_central_id = hc_id
+                break

Also, please add test cases for multiple heater central scenarios.

📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between c085924 and d90fe51.

📒 Files selected for processing (3)
  • plugwise/common.py (1 hunks)
  • plugwise/helper.py (1 hunks)
  • plugwise/util.py (5 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • plugwise/common.py
⏰ Context from checks skipped due to timeout of 90000ms (1)
  • GitHub Check: Check commit
🔇 Additional comments (6)
plugwise/helper.py (1)

256-256: LGTM! Improved safety by returning a new Munch instance.

The change ensures that unrecognized appliance types return a clean, empty object instead of potentially returning a modified input object. This is a safer approach that prevents data leakage and makes the behavior more predictable.

plugwise/util.py (5)

16-16: LGTM!

Good practice to import and use a constant instead of a magic value.


97-98: LGTM!

Good addition of an early return when no heater central is found, improving code readability.


141-141: LGTM!

Correctly removed assignment as power_data_energy_diff now modifies the data in place.


206-213: LGTM!

The rounding logic is now more consistent and easier to follow with clear conditions for different precisions.


232-244: LGTM!

Good improvements:

  • Return type now correctly indicates the function modifies data in place
  • More concise and clearer logic for energy differential calculation
  • Conditional rounding based on the value type

@bouwew bouwew force-pushed the digisaster-contrib branch from d90fe51 to e814e3d Compare February 24, 2025 13:21
@bouwew bouwew marked this pull request as ready for review February 24, 2025 13:39
@bouwew bouwew requested a review from a team as a code owner February 24, 2025 13:39
@sonarqubecloud
Copy link

@bouwew bouwew changed the title Implement improvment-contributions from digisaster Implement improvement-contributions from digisaster Feb 24, 2025
@bouwew bouwew merged commit 5ad6992 into main Feb 24, 2025
19 checks passed
@bouwew bouwew deleted the digisaster-contrib branch February 24, 2025 14:00
@coderabbitai coderabbitai bot mentioned this pull request Dec 21, 2025
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.

3 participants