Skip to content

Fixing Core Issue #171955#1073

Merged
bouwew merged 26 commits into
mainfrom
Testing_for_anna
May 24, 2026
Merged

Fixing Core Issue #171955#1073
bouwew merged 26 commits into
mainfrom
Testing_for_anna

Conversation

@bouwew
Copy link
Copy Markdown
Contributor

@bouwew bouwew commented May 24, 2026

Summary by CodeRabbit

  • Refactor

    • Improved Plugwise climate entity's state restoration and HVAC mode switching logic for better reliability and maintainability.
  • Tests

    • Enhanced test coverage to verify HVAC mode transitions and schedule state handling.

Review Change Stack

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented May 24, 2026

Warning

Review limit reached

@bouwew, we couldn't start this review because you've used your available PR reviews for now.

Your plan currently allows 1 review/hour. Refill in 32 minutes and 54 seconds.

Your organization has run out of usage credits. Purchase more in the billing tab.

⌛ How to resolve this issue?

After more review capacity refills, 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 trial, open-source, and free plans. In all cases, review capacity refills continuously over time.

Please see our FAQ for further information.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: f5b914b4-2343-4444-87b4-cc6750010444

📥 Commits

Reviewing files that changed from the base of the PR and between 4d61362 and 4d54ca0.

📒 Files selected for processing (8)
  • .github/workflows/core_next.yml
  • .github/workflows/test.yml
  • CHANGELOG.md
  • custom_components/plugwise/climate.py
  • pyproject.toml
  • scripts/core-testing.sh
  • tests/components/plugwise/fixtures/m_adam_heating_off_schedule/data.json
  • tests/components/plugwise/test_climate.py
📝 Walkthrough

Walkthrough

The PR refactors the Plugwise climate entity's stored-state restoration and HVAC mode control. The PlugwiseClimateExtraStoredData.from_dict classmethod was removed; stored-state fields are now initialized in __init__ and restored directly from extra_data.as_dict(). The HVAC control was rewritten with a non-nullable _regulation_mode_for_hvac return and new branching logic that explicitly handles transitions from OFF, AUTO, and schedule-dependent modes, replacing prior helper methods.

Changes

Climate entity restoration and HVAC control

Layer / File(s) Summary
Stored-state restoration refactoring
custom_components/plugwise/climate.py
PlugwiseClimateExtraStoredData removes its from_dict classmethod; _last_active_schedule is now initialized in PlugwiseClimateEntity.__init__, and the async_added_to_hass restore flow is rewritten to read last_active_schedule and previous_action_mode directly from extra_data.as_dict() when available.
HVAC mode control rewrite
custom_components/plugwise/climate.py
_regulation_mode_for_hvac return type changes from str | None to str (always non-nullable), and async_set_hvac_mode is replaced with conditional logic that branches on OFF, AUTO, and schedule-dependent transitions; prior helpers _set_manual_hvac_mode and _set_auto_hvac_mode are removed.
HVAC transition test coverage
tests/components/plugwise/test_climate.py
New test assertions in test_anna_climate_entity_climate_changes verify that when a device reports climate_mode = "heat" and set_hvac_mode(AUTO) is called again, set_schedule_state is invoked a second time with STATE_ON and the restored "standaard" schedule.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Possibly related PRs

  • plugwise/plugwise-beta#793: Both PRs modify async_set_hvac_mode HVAC transition logic in the climate entity.
  • plugwise/plugwise-beta#779: Both PRs refactor PlugwiseClimateEntity HVAC handling in custom_components/plugwise/climate.py.
  • plugwise/plugwise-beta#945: Both PRs refactor stored-state persistence and restoration of _last_active_schedule and _previous_action_mode to drive async_set_hvac_mode branching.

Suggested reviewers

  • CoMPaTech
🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 inconclusive)

Check name Status Explanation Resolution
Title check ❓ Inconclusive The title references Core Issue #171955 but does not clearly describe what the issue is or what was fixed. It lacks specificity about the actual change being made. Consider providing a more descriptive title that explains the nature of the fix, such as 'Fix HVAC mode restoration and switching logic' or similar that indicates the core change.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch Testing_for_anna

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.

@coderabbitai coderabbitai Bot requested a review from CoMPaTech May 24, 2026 11:49
Copy link
Copy Markdown
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: 2

🧹 Nitpick comments (1)
custom_components/plugwise/climate.py (1)

165-170: 💤 Low value

Cache as_dict() result and consider defensive access.

extra_data.as_dict() is called twice unnecessarily. Caching the result improves efficiency and using .get() adds defensive handling for potentially malformed stored data.

♻️ Suggested refactor
         extra_data = await self.async_get_last_extra_data()
         if extra_data is not None:
-            self._last_active_schedule = extra_data.as_dict()["last_active_schedule"]
-            self._previous_action_mode = (
-                extra_data.as_dict()["previous_action_mode"] or HVACAction.HEATING.value
-            )
+            data = extra_data.as_dict()
+            self._last_active_schedule = data.get("last_active_schedule")
+            self._previous_action_mode = (
+                data.get("previous_action_mode") or HVACAction.HEATING.value
+            )
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@custom_components/plugwise/climate.py` around lines 165 - 170, The code calls
extra_data.as_dict() twice and doesn't defensively access keys; modify the block
that awaits async_get_last_extra_data() to first assign extra =
extra_data.as_dict() once, then set self._last_active_schedule =
extra.get("last_active_schedule") and self._previous_action_mode =
extra.get("previous_action_mode") or HVACAction.HEATING.value so you cache the
dict and use .get() with the existing HVACAction.HEATING.value fallback for
malformed or missing data.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@custom_components/plugwise/climate.py`:
- Around line 330-342: The transition logic wrongly falls through to the
"transition to AUTO" schedule-on block for HEAT↔COOL changes; add an explicit
branch before the schedule-on code that detects manual regulation mode switches
(check self.hvac_mode vs previous/desired mode and membership in
REGULATION_MODES and presence of cooling) and call await
self._api.set_regulation_mode(self._location, <desired_mode>) then return,
leaving the existing set_schedule_state(self._location, STATE_ON,
self._last_active_schedule) only for HVACMode.AUTO transitions and keeping the
HomeAssistantError for missing _last_active_schedule unchanged.
- Around line 286-292: The _regulation_mode_for_hvac function can raise
UnboundLocalError because it uses two separate ifs and may leave mode undefined
for unexpected HVACMode values; change the branching to an if/elif (check
hvac_mode == HVACMode.HEAT then elif hvac_mode == HVACMode.COOL) and add an
explicit fallback (raise a ValueError or return a safe default) so that
_regulation_mode_for_hvac, HVACMode and HVACAction usage is deterministic and
fails fast for unsupported modes.

---

Nitpick comments:
In `@custom_components/plugwise/climate.py`:
- Around line 165-170: The code calls extra_data.as_dict() twice and doesn't
defensively access keys; modify the block that awaits
async_get_last_extra_data() to first assign extra = extra_data.as_dict() once,
then set self._last_active_schedule = extra.get("last_active_schedule") and
self._previous_action_mode = extra.get("previous_action_mode") or
HVACAction.HEATING.value so you cache the dict and use .get() with the existing
HVACAction.HEATING.value fallback for malformed or missing data.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 269b3e71-9fd1-4561-a5c5-d9a03cec384b

📥 Commits

Reviewing files that changed from the base of the PR and between a8bad92 and 4d61362.

📒 Files selected for processing (2)
  • custom_components/plugwise/climate.py
  • tests/components/plugwise/test_climate.py

Comment thread custom_components/plugwise/climate.py
Comment thread custom_components/plugwise/climate.py
Copy link
Copy Markdown

@github-actions github-actions Bot left a comment

Choose a reason for hiding this comment

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

Error while testing for Development HA-core:

⚠️ Warning: Incompatible while testing against dev HA-core.
✔️ Success: No problem with testing against released HA-core.

Copy link
Copy Markdown

@github-actions github-actions Bot left a comment

Choose a reason for hiding this comment

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

Error while testing for Development HA-core:

⚠️ Warning: Incompatible while testing against dev HA-core.
✔️ Success: No problem with testing against released HA-core.

Copy link
Copy Markdown

@github-actions github-actions Bot left a comment

Choose a reason for hiding this comment

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

Error while testing for Development HA-core:

⚠️ Warning: Incompatible while testing against dev HA-core.
✔️ Success: No problem with testing against released HA-core.

Copy link
Copy Markdown

@github-actions github-actions Bot left a comment

Choose a reason for hiding this comment

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

Error while testing for Development HA-core:

⚠️ Warning: Incompatible while testing against dev HA-core.
✔️ Success: No problem with testing against released HA-core.

Copy link
Copy Markdown

@github-actions github-actions Bot left a comment

Choose a reason for hiding this comment

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

Error while testing for Development HA-core:

⚠️ Warning: Incompatible while testing against dev HA-core.
✔️ Success: No problem with testing against released HA-core.

Copy link
Copy Markdown

@github-actions github-actions Bot left a comment

Choose a reason for hiding this comment

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

Error while testing for Development HA-core:

⚠️ Warning: Incompatible while testing against dev HA-core.
✔️ Success: No problem with testing against released HA-core.

@CoMPaTech
Copy link
Copy Markdown
Member

Dev shows linting errors, let's not fix them as part of the core issue this is because the changes in ruff and lint (https://github.com/plugwise/plugwise-beta/actions/runs/26361229109/job/77597017252?pr=1073#step:4:5986)

@CoMPaTech
Copy link
Copy Markdown
Member

Confirmed working here (no error, green checkmark, changing hvac_mode)

@bouwew bouwew force-pushed the Testing_for_anna branch from d5614aa to 4a75cc8 Compare May 24, 2026 13:09
Copy link
Copy Markdown

@github-actions github-actions Bot left a comment

Choose a reason for hiding this comment

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

Error while testing for Development HA-core:

⚠️ Warning: Incompatible while testing against dev HA-core.
✔️ Success: No problem with testing against released HA-core.

Copy link
Copy Markdown

@github-actions github-actions Bot left a comment

Choose a reason for hiding this comment

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

Error while testing for Development HA-core:

⚠️ Warning: Incompatible while testing against dev HA-core.
✔️ Success: No problem with testing against released HA-core.

Copy link
Copy Markdown

@github-actions github-actions Bot left a comment

Choose a reason for hiding this comment

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

Error while testing for Development HA-core:

⚠️ Warning: Incompatible while testing against dev HA-core.
✔️ Success: No problem with testing against released HA-core.

Copy link
Copy Markdown

@github-actions github-actions Bot left a comment

Choose a reason for hiding this comment

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

Error while testing for Development HA-core:

⚠️ Warning: Incompatible while testing against dev HA-core.
✔️ Success: No problem with testing against released HA-core.

@bouwew bouwew marked this pull request as ready for review May 24, 2026 17:57
@bouwew bouwew requested a review from a team as a code owner May 24, 2026 17:57
@bouwew bouwew added the needs_upstreaming Things that are here in -beta but must be upstreamed to HA-core label May 24, 2026
@CoMPaTech CoMPaTech requested a review from Copilot May 24, 2026 18:01
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

The multiple if statements should be cleaned up, but lets leave that for another time, just to mark for future optimisation

Copy link
Copy Markdown
Contributor

Copilot AI left a 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 pull request targets Home Assistant Core Issue #171955 by refactoring Plugwise climate state restoration and HVAC mode switching, and by adding/adjusting tests and fixtures to validate the new behavior.

Changes:

  • Refactors PlugwiseClimateEntity restore handling and HVAC mode transition logic (notably around OFF/AUTO/manual transitions).
  • Adds tests and a new fixture to cover regulation-off mode transitions and additional schedule/HVAC behavior.
  • Bumps package version/changelog and updates CI/cache and local core-testing script behavior.

Reviewed changes

Copilot reviewed 8 out of 8 changed files in this pull request and generated 5 comments.

Show a summary per file
File Description
custom_components/plugwise/climate.py Refactors restore + HVAC mode transition logic for Plugwise climate entities.
tests/components/plugwise/test_climate.py Adds/extends tests around regulation-off and schedule/HVAC transitions.
tests/components/plugwise/fixtures/m_adam_heating_off_schedule/data.json Adds a fixture representing Adam in regulation-off with schedule state.
scripts/core-testing.sh Updates HA-core clone validation to check requirements_test.txt.
pyproject.toml Bumps project version to 0.64.2.
CHANGELOG.md Adds v0.64.2 entry mentioning the Core issue fix and related PRs.
.github/workflows/test.yml Bumps cache version to invalidate prior caches.
.github/workflows/core_next.yml Bumps cache version to invalidate prior caches.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread custom_components/plugwise/climate.py Outdated
Comment thread custom_components/plugwise/climate.py
Comment thread custom_components/plugwise/climate.py
Comment thread custom_components/plugwise/climate.py
Comment thread custom_components/plugwise/climate.py
Copy link
Copy Markdown

@github-actions github-actions Bot left a comment

Choose a reason for hiding this comment

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

Error while testing for Development HA-core:

⚠️ Warning: Incompatible while testing against dev HA-core.
✔️ Success: No problem with testing against released HA-core.

@sonarqubecloud
Copy link
Copy Markdown

Copy link
Copy Markdown

@github-actions github-actions Bot left a comment

Choose a reason for hiding this comment

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

Error while testing for Development HA-core:

⚠️ Warning: Incompatible while testing against dev HA-core.
✔️ Success: No problem with testing against released HA-core.

@bouwew bouwew merged commit 2be9c13 into main May 24, 2026
13 checks passed
@bouwew bouwew deleted the Testing_for_anna branch May 24, 2026 18:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

needs_upstreaming Things that are here in -beta but must be upstreamed to HA-core

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants