Skip to content

Conversation

@bouwew
Copy link
Contributor

@bouwew bouwew commented Dec 19, 2025

Summary by CodeRabbit

  • Refactor
    • Core data handling updated to mutate entity objects in place across the integration instead of assembling and returning separate data maps. Internal APIs changed but user-facing behavior remains unchanged.
  • Documentation
    • Changelog updated with an "Ongoing" note about code optimizations.

✏️ Tip: You can customize this high-level summary in your review settings.

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Dec 19, 2025

Walkthrough

Functions across core and legacy modules were changed to stop returning/updating separate data dicts and instead mutate the provided entity/zone objects in-place; multiple method signatures dropped the data parameter and now return None.

Changes

Cohort / File(s) Summary
Entity switching
plugwise/common.py
_entity_switching_group signature updated to remove data; now assigns entity["switches"]["relay"] directly (in-place mutation).
Core data module
plugwise/data.py
Many functions changed to accept and mutate entity in-place (signatures changed; returns removed): e.g., _add_or_update_notifications, _get_location_data, _get_entity_data, _check_availability, _get_adam_data, _climate_data, _get_schedule_states_with_off. Climate, schedules, sensors, notifications, and Anna/thermostat logic now write directly into entity.
Core helper module
plugwise/helper.py
_get_zone_data(loc_id, zone) and _get_measurement_data(entity_id, entity) now update the passed zone/entity in-place and return None; measurement/power paths mutate the entity rather than returning a data dict.
Legacy data module
plugwise/legacy/data.py
_get_entity_data, _climate_data, _get_anna_control_state updated to accept and mutate entity; _update_gw_entities now relies on in-place mutation (no returned data).
Legacy helper module
plugwise/legacy/helper.py
_get_measurement_data(entity_id, entity) signature changed; function updates provided entity in-place instead of returning a data map and removed internal entity lookups.
Changelog
CHANGELOG.md
Added an "Ongoing" subsection with a bullet noting code optimizations via PR #837; no code changes here.

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~45 minutes

  • Pay attention to all updated call-sites to ensure the correct entity/zone object is passed and no code expects a returned data.
  • Review concurrency/shared-reference risks where entities are mutated in-place.
  • Validate climate, schedule, Anna/thermostat, measurement, and switching-group logic for behavioral parity after relocation of mutations.
  • Inspect legacy module paths for consistent semantics with core changes.

Possibly related PRs

Suggested reviewers

  • CoMPaTech

Poem

🐇 I nibbled through code, neat and spry,
Moved bits to burrows where they’ll lie.
Entities now wear the seeds I sow,
Mutations snug where data flows. 🌱✨

Pre-merge checks and finishing touches

✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title 'Optimize data collection' accurately reflects the main change: refactoring data handling to use in-place entity mutation instead of separate data structures across multiple files.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.
✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch rework-data

📜 Recent review details

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between ab97c11 and 8487ea7.

📒 Files selected for processing (2)
  • CHANGELOG.md (1 hunks)
  • plugwise/legacy/helper.py (2 hunks)
✅ Files skipped from review due to trivial changes (1)
  • CHANGELOG.md
🧰 Additional context used
🧠 Learnings (1)
📚 Learning: 2024-12-22T09:37:24.648Z
Learnt from: bouwew
Repo: plugwise/python-plugwise PR: 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.

Applied to files:

  • plugwise/legacy/helper.py
🧬 Code graph analysis (1)
plugwise/legacy/helper.py (2)
plugwise/helper.py (1)
  • _get_measurement_data (323-373)
plugwise/constants.py (1)
  • GwEntityData (527-589)
🔇 Additional comments (3)
plugwise/legacy/helper.py (3)

257-265: Defensive access and in-place mutation correctly implemented.

The power branch correctly implements the refactoring pattern:

  • Line 261 uses entity.get("dev_class") for safe key access, addressing the previous review concern
  • Lines 264-265 update the provided entity in-place and return early, which is appropriate for the power type

293-293: Final in-place mutation completes the refactoring pattern.

The final entity.update(data) correctly applies the collected measurement data to the provided entity, completing the in-place mutation pattern for the non-power code path.


252-252: Method signature correctly reflects in-place mutation refactoring pattern.

The signature change from returning GwEntityData to accepting an entity parameter and returning None is consistent with the broader refactoring where methods mutate provided entity objects in-place. The defensive access using entity.get("dev_class") addresses the earlier direct indexing concern. Both the power-type branch (with early return after update) and non-power path (with final update) properly mutate the entity in-place. All callers have been appropriately updated to pass the entity parameter.


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

Comment @coderabbitai help to get the list of available commands and usage tips.

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

181-183: Clarify the dual-object pattern in _get_location_data.

This method uses a slightly different pattern: zone receives climate data via in-place mutation (line 181), while data from _get_zone_data is returned separately (line 183). The caller _update_zones then merges them with zone.update(data).

This works correctly but is less intuitive than the pure in-place mutation pattern used elsewhere. Consider adding a brief comment explaining why climate data is written to zone while sensor data comes from data.

📜 Review details

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 5f4371c and a18165f.

📒 Files selected for processing (5)
  • plugwise/common.py (2 hunks)
  • plugwise/data.py (8 hunks)
  • plugwise/helper.py (3 hunks)
  • plugwise/legacy/data.py (1 hunks)
  • plugwise/legacy/helper.py (2 hunks)
🧰 Additional context used
🧠 Learnings (2)
📚 Learning: 2024-12-22T09:37:24.648Z
Learnt from: bouwew
Repo: plugwise/python-plugwise PR: 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.

Applied to files:

  • plugwise/legacy/helper.py
📚 Learning: 2025-10-11T14:05:29.022Z
Learnt from: bouwew
Repo: plugwise/python-plugwise PR: 797
File: fixtures/adam_anna_new_2/data.json:1-304
Timestamp: 2025-10-11T14:05:29.022Z
Learning: In Plugwise fixture data (data.json files), location IDs referenced in device entries don't always need corresponding top-level location objects. Only climate zones (ThermoZone entries with dev_class "climate") require full top-level definitions with thermostats, schedules, and presets. Simple organizational locations that just group devices (like single plugs) can be referenced without top-level entries.

Applied to files:

  • plugwise/data.py
🧬 Code graph analysis (3)
plugwise/common.py (1)
plugwise/constants.py (1)
  • GwEntityData (527-589)
plugwise/legacy/helper.py (2)
plugwise/helper.py (1)
  • _get_measurement_data (324-376)
plugwise/constants.py (1)
  • GwEntityData (527-589)
plugwise/helper.py (2)
plugwise/legacy/helper.py (1)
  • _get_measurement_data (252-294)
plugwise/constants.py (1)
  • GwEntityData (527-589)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (1)
  • GitHub Check: Ruff check and force
🔇 Additional comments (15)
plugwise/helper.py (2)

324-340: LGTM - Signature change and early return path are consistent.

The refactor correctly updates the entity in-place before returning. The pattern of building a local data dict and then merging via entity.update(data) is a clean approach that maintains the existing logic while supporting in-place mutation.


375-376: LGTM - Final return path correctly mutates entity in-place.

Consistent with the early return path at lines 339-340.

plugwise/legacy/helper.py (2)

252-265: LGTM - Consistent refactor with non-legacy helper.

The signature change and early return path follow the same in-place mutation pattern. Based on learnings, this legacy code is fully separated from plugwise/helper.py, so the parallel refactoring is appropriate.


293-294: LGTM - Final return path correctly mutates entity in-place.

Consistent with the pattern established in the method.

plugwise/legacy/data.py (3)

31-50: LGTM - Refactor to in-place mutation is well-structured.

The call order ensures entity["switches"] is initialized by _get_measurement_data (line 39) before _entity_switching_group (line 42) accesses it. The early return on line 46 for non-thermostat entities is appropriate.


52-78: LGTM - Climate data now mutates entity directly.

All assignments correctly target entity[...] instead of a separate data dict. The logic remains unchanged.


80-89: LGTM - Anna control state logic correctly refactored.

The loop variable rename from data to device (line 84) improves clarity, distinguishing between the target entity being updated and the device being inspected.

plugwise/data.py (7)

58-61: LGTM - Entity data and notifications now use in-place mutation.

The refactor correctly removes return value handling and updates entities directly.


107-122: LGTM - Notifications method signature simplified.

The method now mutates entity directly, writing to entity["binary_sensors"] and entity["notifications"]. This is cleaner than the previous approach of updating a separate data dict.


185-212: LGTM - Entity data collection refactored to in-place mutation.

All helper method calls correctly pass entity for in-place updates. The pattern is consistent with the rest of the refactor.


214-228: LGTM - Availability check now mutates entity directly.

Clean refactor removing the data parameter.


230-257: LGTM - Adam data collection refactored correctly.

All entity[...] assignments are properly targeted.


259-301: LGTM - Climate data method refactored to in-place mutation.

All assignments correctly target entity[...]. The logic for determining climate mode remains unchanged.


324-341: LGTM - Schedule states method refactored correctly.

The method now reads from and writes to entity directly. Line 334's condition entity["climate_mode"] == "auto" correctly references the entity's state that was set earlier in _climate_data.

plugwise/common.py (1)

178-189: The concern raised is unfounded. entity["switches"] is always initialized before _entity_switching_group() is called. The _get_measurement_data() method creates and initializes the switches dict with entity.update(data) before control returns to _entity_switching_group(), ensuring the dict exists on the entity.

@codecov
Copy link

codecov bot commented Dec 19, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 100.00%. Comparing base (f52f0c5) to head (8487ea7).
⚠️ Report is 10 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff            @@
##              main      #837   +/-   ##
=========================================
  Coverage   100.00%   100.00%           
=========================================
  Files           21        21           
  Lines         3451      3442    -9     
=========================================
- Hits          3451      3442    -9     

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

📜 Review details

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 2a50706 and ab97c11.

📒 Files selected for processing (2)
  • plugwise/helper.py (2 hunks)
  • plugwise/legacy/helper.py (2 hunks)
🧰 Additional context used
🧠 Learnings (1)
📚 Learning: 2024-12-22T09:37:24.648Z
Learnt from: bouwew
Repo: plugwise/python-plugwise PR: 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.

Applied to files:

  • plugwise/legacy/helper.py
  • plugwise/helper.py
🧬 Code graph analysis (2)
plugwise/legacy/helper.py (2)
plugwise/helper.py (1)
  • _get_measurement_data (323-373)
plugwise/constants.py (1)
  • GwEntityData (527-589)
plugwise/helper.py (2)
plugwise/constants.py (1)
  • GwEntityData (527-589)
plugwise/legacy/helper.py (3)
  • _appliance_measurements (316-344)
  • _get_actuator_functionalities (346-379)
  • _get_measurement_data (252-293)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (1)
  • GitHub Check: Process test coverage
🔇 Additional comments (3)
plugwise/legacy/helper.py (1)

252-293: LGTM! In-place mutation pattern correctly implemented.

The refactoring from returning data to mutating the provided entity parameter in-place is consistent and reduces unnecessary data copying. The method correctly:

  • Collects data in a local dict
  • Updates the entity via entity.update(data) at appropriate points (lines 264, 293)
  • Returns None as indicated by the signature
plugwise/helper.py (2)

308-321: LGTM! Zone data collection correctly refactored for in-place mutation.

The _get_zone_data method has been successfully refactored to mutate the provided zone parameter in-place rather than returning data. The implementation is clean and consistent with the broader refactoring pattern.


323-373: LGTM! Measurement data collection correctly refactored with defensive field access.

The _get_measurement_data method refactoring is well-implemented:

  • Correctly uses entity.get("dev_class") at line 331 for safe optional field access (since GwEntityData has total=False)
  • Updates the provided entity parameter in-place via entity.update(data) at lines 337 and 373
  • Returns None as indicated by the signature
  • Early return optimization at lines 337-338 for power-only scenarios

The defensive access pattern here is the correct approach and aligns with GwEntityData being a TypedDict with optional keys.

@sonarqubecloud
Copy link

@bouwew bouwew marked this pull request as ready for review December 20, 2025 17:06
@bouwew bouwew requested a review from a team as a code owner December 20, 2025 17:06
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.

Looking good

@bouwew bouwew merged commit 20b7108 into main Dec 20, 2025
18 checks passed
@bouwew bouwew deleted the rework-data branch December 20, 2025 18:43
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