Skip to content

Improve handling of missing thermostat data#861

Merged
bouwew merged 18 commits intomainfrom
bad_thermostat
Mar 7, 2026
Merged

Improve handling of missing thermostat data#861
bouwew merged 18 commits intomainfrom
bad_thermostat

Conversation

@bouwew
Copy link
Contributor

@bouwew bouwew commented Mar 7, 2026

Partly a solution for plugwise/plugwise-beta#1030

Summary by CodeRabbit

Release Notes

  • New Features

    • Enhanced system robustness with improved handling for scenarios where thermostat data is missing or unavailable.
  • Chores

    • Released version v1.11.3.
    • Replaced node-based code linting tool with Python-based alternative.
  • Tests

    • Added test coverage for missing thermostat data scenarios.

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Mar 7, 2026

Warning

Rate limit exceeded

@bouwew has exceeded the limit for the number of commits that can be reviewed per hour. Please wait 19 minutes and 27 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.

⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: f37f1992-c317-4301-9790-6ec847094e03

📥 Commits

Reviewing files that changed from the base of the PR and between 82f1440 and 0afb80b.

📒 Files selected for processing (1)
  • CHANGELOG.md
📝 Walkthrough

Walkthrough

This PR adds a new test case for missing thermostat data by introducing a new fixture (adam_bad_thermostat), updating version to v1.11.3, and adding safety guards in plugwise/helper.py to handle missing thermostat data gracefully. Most fixture files have JSON array formatting reformatted to multi-line style.

Changes

Cohort / File(s) Summary
Version and Release Updates
CHANGELOG.md, pyproject.toml
Version bump to v1.11.3; changelog entry for improved missing thermostat data handling and code optimizations; markdownlint tool migration note.
Core Logic Improvements
plugwise/helper.py
Added early-return guards in _control_state and _regulation_control methods to safely handle missing thermostat data; cached thermostat variable; updated regulation control zone profile handling.
New Test Infrastructure
fixtures/adam_bad_thermostat/data.json, tests/data/adam/adam_bad_thermostat.json, userdata/adam_bad_thermostat/core.domain_objects.xml, tests/test_adam.py
New test fixture for missing thermostat scenario; new async test method test_connect_adam_jvonk; comprehensive domain object definitions for bad thermostat test case.
Fixture Data Formatting
fixtures/adam_*/*.json, fixtures/anna_*/*.json, fixtures/legacy_*/data.json, fixtures/m_adam_*/data.json, fixtures/m_anna_*/data.json, fixtures/stretch_*/data.json
Consistent reformatting of JSON arrays from single-line to multi-line representations across 25+ fixture files; no semantic changes to data values or structure.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Possibly related PRs

Suggested labels

bug

Suggested reviewers

  • CoMPaTech
🚥 Pre-merge checks | ✅ 3
✅ 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 'Handle missing thermostat data' directly matches the main change in the PR, which adds safety checks and guards throughout the codebase to manage missing thermostat data.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.

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

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch bad_thermostat

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 March 7, 2026 10:17
@codecov
Copy link

codecov bot commented Mar 7, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 100.00%. Comparing base (65251da) to head (0afb80b).
⚠️ Report is 19 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff            @@
##              main      #861   +/-   ##
=========================================
  Coverage   100.00%   100.00%           
=========================================
  Files           21        21           
  Lines         3443      3456   +13     
=========================================
+ Hits          3443      3456   +13     

☔ 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.

@bouwew bouwew marked this pull request as ready for review March 7, 2026 10:47
@bouwew bouwew requested a review from a team as a code owner March 7, 2026 10:47
@coderabbitai coderabbitai bot added the bug Something isn't working label Mar 7, 2026
@bouwew bouwew changed the title Handle missing thermostat data Improve handling of missing thermostat data Mar 7, 2026
@sonarqubecloud
Copy link

sonarqubecloud bot commented Mar 7, 2026

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)
tests/test_adam.py (2)

20-21: Consider a more descriptive test name.

The test name test_connect_adam_jvonk appears to reference a user identifier rather than describing the test scenario. A more descriptive name would improve test readability and maintainability.

💡 Suggested rename
-    async def test_connect_adam_jvonk(self):
-        """Test Adam with missing thermostat data."""
+    async def test_connect_adam_missing_thermostat_data(self):
+        """Test Adam gracefully handles missing thermostat data in a zone."""
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@tests/test_adam.py` around lines 20 - 21, Rename the test function
test_connect_adam_jvonk to a descriptive name that reflects its intent (e.g.,
test_connect_adam_missing_thermostat_data or
test_adam_handles_missing_thermostat) so the purpose is clear; update the
function definition and any references/imports/pytest markers to use the new
name and run the test suite to ensure no references remain to
test_connect_adam_jvonk.

19-29: Test validates graceful handling but skips data validation.

The test correctly verifies that the API can initialize and load data without crashing when thermostat data is missing. Using skip_testing=True is appropriate here since the fixture intentionally lacks the thermostat key, which would fail normal fixture validation.

However, consider capturing the warning log to verify the guard logic is actually triggered. This would make the test more explicit about what behavior is being validated.

💡 Optional: Add log capture to verify warning is logged
`@pytest.mark.asyncio`
async def test_connect_adam_jvonk(self, caplog):
    """Test Adam with missing thermostat data."""
    self.smile_setup = "adam_bad_thermostat"

    testdata = await self.load_testdata(SMILE_TYPE, self.smile_setup)
    server, api, client = await self.connect_wrapper(raise_timeout=True)
    await self.device_test(api, "2023-12-17 00:00:01", testdata, skip_testing=True)

    # Verify warning about incomplete thermostat data was logged
    assert "Thermostat data in Zone" in caplog.text
    assert "is incomplete" in caplog.text

    await api.close_connection()
    await self.disconnect(server, client)
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@tests/test_adam.py` around lines 19 - 29, Add log-capture assertions to
test_connect_adam_jvonk to ensure the guard for missing thermostat data actually
logged a warning: modify the test_connect_adam_jvonk test to accept the pytest
caplog fixture, run the same setup (load_testdata, connect_wrapper, device_test
with skip_testing=True), then assert that caplog contains the expected warning
substrings (e.g., "Thermostat data in Zone" and "is incomplete" or the exact
message emitted where the guard lives) before closing the API and disconnecting;
reference the existing test_connect_adam_jvonk, load_testdata, connect_wrapper,
and device_test helpers to locate where to add the caplog usage and assertions.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@CHANGELOG.md`:
- Line 5: Update the v1.11.3 changelog entry that currently reads "Better handle
missing thermostat data via PR [`#860`]" to reference the correct pull request
number `#861`; locate the string in CHANGELOG.md (the v1.11.3 line) and replace
"[`#860`](https://github.com/plugwise/python-plugwise/pull/860)" with
"[`#861`](https://github.com/plugwise/python-plugwise/pull/861)" so the link
points to the correct PR.

---

Nitpick comments:
In `@tests/test_adam.py`:
- Around line 20-21: Rename the test function test_connect_adam_jvonk to a
descriptive name that reflects its intent (e.g.,
test_connect_adam_missing_thermostat_data or
test_adam_handles_missing_thermostat) so the purpose is clear; update the
function definition and any references/imports/pytest markers to use the new
name and run the test suite to ensure no references remain to
test_connect_adam_jvonk.
- Around line 19-29: Add log-capture assertions to test_connect_adam_jvonk to
ensure the guard for missing thermostat data actually logged a warning: modify
the test_connect_adam_jvonk test to accept the pytest caplog fixture, run the
same setup (load_testdata, connect_wrapper, device_test with skip_testing=True),
then assert that caplog contains the expected warning substrings (e.g.,
"Thermostat data in Zone" and "is incomplete" or the exact message emitted where
the guard lives) before closing the API and disconnecting; reference the
existing test_connect_adam_jvonk, load_testdata, connect_wrapper, and
device_test helpers to locate where to add the caplog usage and assertions.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: c6a3bb22-6016-481b-99f4-15b53cdd6d9b

📥 Commits

Reviewing files that changed from the base of the PR and between 65251da and 82f1440.

📒 Files selected for processing (39)
  • CHANGELOG.md
  • fixtures/adam_bad_thermostat/data.json
  • fixtures/adam_heatpump_cooling/data.json
  • fixtures/adam_jip/data.json
  • fixtures/adam_multiple_devices_per_zone/data.json
  • fixtures/adam_onoff_cooling_fake_firmware/data.json
  • fixtures/adam_plus_anna/data.json
  • fixtures/adam_plus_anna_new/data.json
  • fixtures/adam_plus_anna_new_regulation_off/data.json
  • fixtures/adam_zone_per_device/data.json
  • fixtures/anna_elga_2/data.json
  • fixtures/anna_elga_2_cooling/data.json
  • fixtures/anna_elga_2_schedule_off/data.json
  • fixtures/anna_elga_no_cooling/data.json
  • fixtures/anna_heatpump_cooling/data.json
  • fixtures/anna_heatpump_cooling_fake_firmware/data.json
  • fixtures/anna_heatpump_heating/data.json
  • fixtures/anna_loria_cooling_active/data.json
  • fixtures/anna_loria_driessens/data.json
  • fixtures/anna_loria_heating_idle/data.json
  • fixtures/anna_p1/data.json
  • fixtures/anna_v4/data.json
  • fixtures/anna_v4_dhw/data.json
  • fixtures/anna_v4_no_tag/data.json
  • fixtures/anna_without_boiler_fw441/data.json
  • fixtures/legacy_anna/data.json
  • fixtures/legacy_anna_2/data.json
  • fixtures/m_adam_cooling/data.json
  • fixtures/m_adam_heating/data.json
  • fixtures/m_adam_jip/data.json
  • fixtures/m_adam_multiple_devices_per_zone/data.json
  • fixtures/m_anna_heatpump_cooling/data.json
  • fixtures/m_anna_heatpump_idle/data.json
  • fixtures/stretch_v23/data.json
  • plugwise/helper.py
  • pyproject.toml
  • tests/data/adam/adam_bad_thermostat.json
  • tests/test_adam.py
  • userdata/adam_bad_thermostat/core.domain_objects.xml

CHANGELOG.md Outdated
## v1.11.3

- More code optimizations via PR[#843](https://github.com/plugwise/python-plugwise/pull/843)
- Better handle missing thermostat data via PR [#860](https://github.com/plugwise/python-plugwise/pull/860)
Copy link
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟡 Minor

Fix the PR reference in the v1.11.3 entry.

Line 5 points to PR #860, but this change set is PR #861, so the changelog entry appears to link to the wrong implementation history.

✏️ Proposed fix
-- Better handle missing thermostat data via PR [`#860`](https://github.com/plugwise/python-plugwise/pull/860)
+- Better handle missing thermostat data via PR [`#861`](https://github.com/plugwise/python-plugwise/pull/861)
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
- Better handle missing thermostat data via PR [#860](https://github.com/plugwise/python-plugwise/pull/860)
- Better handle missing thermostat data via PR [`#861`](https://github.com/plugwise/python-plugwise/pull/861)
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@CHANGELOG.md` at line 5, Update the v1.11.3 changelog entry that currently
reads "Better handle missing thermostat data via PR [`#860`]" to reference the
correct pull request number `#861`; locate the string in CHANGELOG.md (the v1.11.3
line) and replace "[`#860`](https://github.com/plugwise/python-plugwise/pull/860)"
with "[`#861`](https://github.com/plugwise/python-plugwise/pull/861)" so the link
points to the correct PR.

@bouwew bouwew merged commit c12d6fa into main Mar 7, 2026
17 checks passed
@bouwew bouwew deleted the bad_thermostat branch March 7, 2026 10:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant