Skip to content

Conversation

@bouwew
Copy link
Contributor

@bouwew bouwew commented Jun 28, 2025

Summary by CodeRabbit

  • Refactor
    • Improved device ordering to prioritize key device classes.
    • Centralized model-specific logic for switch attributes and states for clearer handling.
  • Chores
    • Updated project version to 1.7.7.
    • Enhanced changelog with detailed references to recent improvements.

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Jun 28, 2025

Walkthrough

The changes remove the _sort_gw_entities method from plugwise/helper.py and replace its usage with the newly introduced _reorder_devices method from plugwise/common.py to reorder device entities by priority. Additionally, a new helper function model_to_switch_items was added in plugwise/smile.py to centralize model-specific switch logic, with set_switch_state refactored accordingly. Version and changelog updates were also made.

Changes

File(s) Change Summary
plugwise/helper.py, plugwise/legacy/helper.py Removed _sort_gw_entities method and replaced calls to it with _reorder_devices from SmileCommon. Removed import of PRIORITY_DEVICE_CLASSES.
plugwise/common.py Added private method _reorder_devices in SmileCommon to reorder gw_entities by priority device classes.
plugwise/constants.py Swapped order of elements in PRIORITY_DEVICE_CLASSES tuple from ("heater_central", "gateway") to ("gateway", "heater_central").
plugwise/smile.py Added model_to_switch_items helper function to encapsulate model-specific switch attribute/state logic; refactored set_switch_state to use this helper.
CHANGELOG.md, pyproject.toml Updated project version from 1.7.6 to 1.7.7 and detailed changelog entry referencing PRs #762-#765.

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant SmileLegacyHelper
    participant Appliances

    User->>SmileLegacyHelper: Call _all_appliances()
    SmileLegacyHelper->>Appliances: Create gateway entities
    SmileLegacyHelper->>SmileLegacyHelper: Call _reorder_devices()
    SmileLegacyHelper-->>User: Return reordered gw_entities
Loading
sequenceDiagram
    participant set_switch_state
    participant model_to_switch_items
    participant switch

    set_switch_state->>model_to_switch_items: Pass model, state, switch
    model_to_switch_items-->>set_switch_state: Return (state, switch)
    set_switch_state->>switch: Construct XML payload with updated values
Loading

Possibly related PRs

Suggested labels

quality

Poem

🐇 Hop, hop, hop, the helpers dance,
Devices sorted with a glance.
Switches shaped with clever art,
Code now clean, a work of heart.
Version bumped, the changelog sings,
Rabbits cheer for tidy things! 🥕✨

Warning

There were issues while running some tools. Please review the errors and either fix the tool's configuration or disable the tool if it's a critical failure.

🔧 Pylint (3.3.7)
plugwise/constants.py
plugwise/helper.py
plugwise/common.py
  • 1 others

📜 Recent review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between c4fab17 and d1ee9d5.

📒 Files selected for processing (4)
  • plugwise/common.py (2 hunks)
  • plugwise/constants.py (1 hunks)
  • plugwise/helper.py (1 hunks)
  • plugwise/legacy/helper.py (1 hunks)
✅ Files skipped from review due to trivial changes (1)
  • plugwise/constants.py
🚧 Files skipped from review as they are similar to previous changes (1)
  • plugwise/legacy/helper.py
🧰 Additional context used
🧠 Learnings (2)
📓 Common learnings
Learnt from: bouwew
PR: plugwise/python-plugwise#678
File: plugwise/legacy/helper.py:69-69
Timestamp: 2024-12-22T09:37:24.648Z
Learning: The code in plugwise/legacy/helper.py is fully separated from plugwise/helper.py. The user indicates that the problem signaled about the mismatch of the variable name (_home_location vs _home_loc_id) does not actually apply.
plugwise/helper.py (1)
Learnt from: bouwew
PR: plugwise/python-plugwise#678
File: plugwise/legacy/helper.py:69-69
Timestamp: 2024-12-22T09:37:24.648Z
Learning: The code in plugwise/legacy/helper.py is fully separated from plugwise/helper.py. The user indicates that the problem signaled about the mismatch of the variable name (_home_location vs _home_loc_id) does not actually apply.
🧬 Code Graph Analysis (1)
plugwise/helper.py (1)
plugwise/common.py (1)
  • _reorder_devices (156-164)
⏰ Context from checks skipped due to timeout of 90000ms (1)
  • GitHub Check: Run pytest using Python 3.13
🔇 Additional comments (3)
plugwise/helper.py (1)

162-162: LGTM! Clean refactoring to centralize device reordering logic.

The replacement of the removed _sort_gw_entities() method with _reorder_devices() successfully centralizes the device reordering functionality in the parent SmileCommon class, reducing code duplication and improving maintainability.

plugwise/common.py (2)

13-13: LGTM! Proper import addition for the new functionality.

The addition of PRIORITY_DEVICE_CLASSES to the imports is consistent with its usage in the new _reorder_devices method.


156-164: LGTM! Well-implemented device reordering logic.

The _reorder_devices method correctly centralizes the device reordering functionality with a clean implementation:

  • Uses dict(self.gw_entities).items() to safely iterate while modifying the dictionary
  • The break statement ensures only the first entity of each priority device class is moved, which aligns with the expected behavior
  • Properly reconstructs the dictionary with priority devices first, maintaining order within each group
  • Clear and descriptive method name and docstring

This successfully consolidates the reordering logic that was previously scattered across multiple files.

✨ Finishing Touches
  • 📝 Generate Docstrings
🧪 Generate Unit Tests
  • Create PR with Unit Tests
  • Post Copyable Unit Tests in Comment
  • Commit Unit Tests in branch reduce-complexity

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ 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.
    • Explain this complex logic.
    • 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 explain this code block.
    • @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 explain its main purpose.
    • @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.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

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.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai auto-generate unit tests to generate unit tests for this PR.
  • @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.

@codecov
Copy link

codecov bot commented Jun 28, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 100.00%. Comparing base (e2e7524) to head (d1ee9d5).
Report is 9 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff            @@
##              main      #765   +/-   ##
=========================================
  Coverage   100.00%   100.00%           
=========================================
  Files           21        21           
  Lines         3388      3382    -6     
=========================================
- Hits          3388      3382    -6     

☔ 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

@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/legacy/helper.py (1)

141-151: Consider simplifying the dictionary reordering logic.

The method correctly implements device reordering, but the implementation could be more concise. The current approach works but is somewhat verbose.

Consider this more direct approach:

 def _reorder_devices(self) -> None:
     """Place the gateway and optional heater_central devices as 1st and 2nd."""
+    reordered = {}
     for dev_class in PRIORITY_DEVICE_CLASSES:
         for entity_id, entity in dict(self.gw_entities).items():
             if entity["dev_class"] == dev_class:
-                tmp_entity = entity
-                self.gw_entities.pop(entity_id)
-                cleared_dict = self.gw_entities
-                add_to_front = {entity_id: tmp_entity}
-                self.gw_entities = {**add_to_front, **cleared_dict}
+                reordered[entity_id] = self.gw_entities.pop(entity_id)
                 break
+    self.gw_entities = {**reordered, **self.gw_entities}
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between e2e7524 and 4b47759.

📒 Files selected for processing (2)
  • plugwise/legacy/helper.py (1 hunks)
  • plugwise/smile.py (2 hunks)
🧰 Additional context used
🧠 Learnings (3)
📓 Common learnings
Learnt from: bouwew
PR: plugwise/python-plugwise#678
File: plugwise/legacy/helper.py:69-69
Timestamp: 2024-12-22T09:37:24.648Z
Learning: The code in plugwise/legacy/helper.py is fully separated from plugwise/helper.py. The user indicates that the problem signaled about the mismatch of the variable name (_home_location vs _home_loc_id) does not actually apply.
plugwise/legacy/helper.py (1)
Learnt from: bouwew
PR: plugwise/python-plugwise#678
File: plugwise/legacy/helper.py:69-69
Timestamp: 2024-12-22T09:37:24.648Z
Learning: The code in plugwise/legacy/helper.py is fully separated from plugwise/helper.py. The user indicates that the problem signaled about the mismatch of the variable name (_home_location vs _home_loc_id) does not actually apply.
plugwise/smile.py (1)
Learnt from: bouwew
PR: plugwise/python-plugwise#678
File: plugwise/legacy/helper.py:69-69
Timestamp: 2024-12-22T09:37:24.648Z
Learning: The code in plugwise/legacy/helper.py is fully separated from plugwise/helper.py. The user indicates that the problem signaled about the mismatch of the variable name (_home_location vs _home_loc_id) does not actually apply.
⏰ Context from checks skipped due to timeout of 90000ms (1)
  • GitHub Check: Run pytest using Python 3.13
🔇 Additional comments (3)
plugwise/legacy/helper.py (1)

139-139: Good refactoring: extracted device ordering logic.

The call to _reorder_devices() successfully separates the device ordering concern from the main appliance processing logic, improving code organization.

plugwise/smile.py (2)

40-58: Excellent refactoring: centralized model-specific switch logic.

The model_to_switch_items() function successfully centralizes model-specific switch attribute and state transformations. The use of a match statement provides clear, readable handling of different models, and the function signature is well-designed.


405-405: Clean integration of the helper function.

The replacement of inline conditional logic with a call to model_to_switch_items() successfully reduces complexity in the main method while maintaining the same functionality.

Copy link
Member

@CoMPaTech CoMPaTech left a comment

Choose a reason for hiding this comment

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

Nice working improving the quality with all those PRs

@sonarqubecloud
Copy link

@bouwew bouwew marked this pull request as ready for review June 28, 2025 13:36
@bouwew bouwew requested a review from a team as a code owner June 28, 2025 13:36
@bouwew bouwew merged commit 52f28a5 into main Jun 28, 2025
17 checks passed
@bouwew bouwew deleted the reduce-complexity branch June 28, 2025 13:36
This was referenced 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