Skip to content

Conversation

@bouwew
Copy link
Contributor

@bouwew bouwew commented Dec 23, 2025

Also, replace all async_setup_component() use.

Summary by CodeRabbit

  • Tests

    • Added tests validating default device update intervals in different environments (Adam: 60s, P1: 10s), using simulated time to assert scheduled updates.
    • Updated tests to initialize via the configuration entries API rather than direct component setup.
  • Documentation

    • Added changelog entry noting the new tests and verification of default update intervals.

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

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Dec 23, 2025

Walkthrough

Refactors Plugwise tests to initialize integrations via config entries instead of direct component setup and adds tests asserting the integration's default update intervals for Adam (60s) and P1 (10s) using a freezer-driven coordinator update flow.

Changes

Cohort / File(s) Summary
Tests: config_entries setup & update-interval validation
tests/components/plugwise/test_init.py
Replaced direct async_setup_component() usage with mock_config_entry.add_to_hass() + hass.config_entries.async_setup(); added DEFAULT_SCAN_INTERVAL import; added test_update_interval_adam() and test_update_interval_p1() to assert coordinator update timings via freezer.
Changelog
CHANGELOG.md
Added "Ongoing" entry noting tests for integration default update_interval settings via PR.

Sequence Diagram(s)

(omitted — changes are test-focused and do not introduce a new multi-component runtime control flow that benefits from a sequence diagram)

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Possibly related PRs

Suggested labels

core-dev-compat, enhancement

Suggested reviewers

  • CoMPaTech

Poem

🐰 Hopping through intervals with tests so bright,
Adam waits sixty, P1 ten in sight.
Freeze the clock, hear the coordinator drum,
Two updates dance — hop, tick, then hum. 🥕

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 'Add testcases for update_interval' directly and clearly describes the main changes in the PR, which adds new test cases validating update interval behavior for different device types.
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 test-update-interval

📜 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 1e4d7fe and 5b2f882.

📒 Files selected for processing (2)
  • CHANGELOG.md
  • tests/components/plugwise/test_init.py
✅ Files skipped from review due to trivial changes (1)
  • CHANGELOG.md
🧰 Additional context used
🧠 Learnings (3)
📓 Common learnings
Learnt from: bouwew
Repo: plugwise/plugwise-beta PR: 906
File: tests/components/plugwise/test_binary_sensor.py:9-16
Timestamp: 2025-08-23T16:26:34.700Z
Learning: The Plugwise integration test files import utilities like `snapshot_platform`, `MockConfigEntry`, and `async_fire_time_changed` from `tests.common`, which is from the Home Assistant core repository at https://github.com/home-assistant/core/blob/master/tests/common.py, not from local test files.
Learnt from: bouwew
Repo: plugwise/plugwise-beta PR: 734
File: tests/components/plugwise/test_config_flow.py:58-58
Timestamp: 2024-10-08T15:35:25.180Z
Learning: In `tests/components/plugwise/test_config_flow.py`, the versions are mocked firmware versions for testing purposes and do not need to match the software version in `manifest.json`.
Learnt from: bouwew
Repo: plugwise/plugwise-beta PR: 734
File: tests/components/plugwise/test_config_flow.py:58-58
Timestamp: 2024-09-27T09:48:30.890Z
Learning: In `tests/components/plugwise/test_config_flow.py`, the versions are mocked firmware versions for testing purposes and do not need to match the software version in `manifest.json`.
Learnt from: bouwew
Repo: plugwise/plugwise-beta PR: 793
File: custom_components/plugwise/manifest.json:10-11
Timestamp: 2024-12-12T19:48:34.652Z
Learning: In the Plugwise integration, temporary use of alpha versions from test repositories is acceptable for testing purposes.
📚 Learning: 2025-08-23T16:26:34.700Z
Learnt from: bouwew
Repo: plugwise/plugwise-beta PR: 906
File: tests/components/plugwise/test_binary_sensor.py:9-16
Timestamp: 2025-08-23T16:26:34.700Z
Learning: The Plugwise integration test files import utilities like `snapshot_platform`, `MockConfigEntry`, and `async_fire_time_changed` from `tests.common`, which is from the Home Assistant core repository at https://github.com/home-assistant/core/blob/master/tests/common.py, not from local test files.

Applied to files:

  • tests/components/plugwise/test_init.py
📚 Learning: 2024-10-08T15:35:25.180Z
Learnt from: bouwew
Repo: plugwise/plugwise-beta PR: 734
File: tests/components/plugwise/test_config_flow.py:58-58
Timestamp: 2024-10-08T15:35:25.180Z
Learning: In `tests/components/plugwise/test_config_flow.py`, the versions are mocked firmware versions for testing purposes and do not need to match the software version in `manifest.json`.

Applied to files:

  • tests/components/plugwise/test_init.py
🧬 Code graph analysis (1)
tests/components/plugwise/test_init.py (1)
tests/components/plugwise/conftest.py (3)
  • mock_config_entry (81-95)
  • mock_smile_adam_heat_cool (185-208)
  • mock_smile_p1 (295-317)
⏰ 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). (2)
  • GitHub Check: Setup for HA-core (dev)
  • GitHub Check: Setup for HA-core (release/master)
🔇 Additional comments (4)
tests/components/plugwise/test_init.py (4)

17-17: LGTM!

The addition of DEFAULT_SCAN_INTERVAL to the imports is appropriate for the new update interval tests.


156-156: LGTM!

The migration from async_setup_component() to the config entries API setup is correct and consistent with the PR objectives.

Also applies to: 281-281


377-399: LGTM!

The test correctly validates the Adam update interval behavior:

  1. Confirms initial setup and first update
  2. Asserts the expected 60-second interval for thermostat type
  3. Advances time and verifies the coordinator triggers a second update

The direct dictionary indexing on lines 393-394 is appropriate in a test context—if the key is missing, the test should fail explicitly.


401-425: LGTM!

The test correctly validates the P1 update interval behavior, mirroring the structure of the Adam test and confirming the expected 10-second interval for power-type devices.


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

📜 Review details

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 64e5a25 and d0cda1a.

📒 Files selected for processing (2)
  • tests/components/plugwise/snapshots/test_select.ambr
  • tests/components/plugwise/test_init.py
🧰 Additional context used
🧠 Learnings (1)
📚 Learning: 2025-08-23T16:26:34.700Z
Learnt from: bouwew
Repo: plugwise/plugwise-beta PR: 906
File: tests/components/plugwise/test_binary_sensor.py:9-16
Timestamp: 2025-08-23T16:26:34.700Z
Learning: The Plugwise integration test files import utilities like `snapshot_platform`, `MockConfigEntry`, and `async_fire_time_changed` from `tests.common`, which is from the Home Assistant core repository at https://github.com/home-assistant/core/blob/master/tests/common.py, not from local test files.

Applied to files:

  • tests/components/plugwise/test_init.py
🧬 Code graph analysis (1)
tests/components/plugwise/test_init.py (1)
tests/components/plugwise/conftest.py (3)
  • mock_config_entry (81-95)
  • mock_smile_adam_heat_cool (185-208)
  • mock_smile_p1 (295-317)
⏰ 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: Prepare and validate pre-commit
🔇 Additional comments (2)
tests/components/plugwise/snapshots/test_select.ambr (1)

144-144: LGTM! Appropriate reclassification of schedule entities.

The snapshot correctly reflects the reclassification of thermostat schedule select entities from EntityCategory.CONFIG to None. This distinguishes user-facing operational settings (schedules) from gateway-level configuration settings, improving the UX by making schedules more prominent in the UI.

Also applies to: 266-266, 389-389, 454-454, 519-519, 584-584

tests/components/plugwise/test_init.py (1)

17-17: LGTM! Necessary import for new tests.

The addition of DEFAULT_SCAN_INTERVAL to the imports is required for the new update interval tests.

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

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
tests/components/plugwise/test_init.py (1)

33-33: Remove the unused import.

The async_setup_component import is no longer needed since all tests now use hass.config_entries.async_setup(mock_config_entry.entry_id) instead. The pre-commit hook flagged this import as unused.

🔎 Proposed fix
-from homeassistant.setup import async_setup_component
♻️ Duplicate comments (3)
tests/components/plugwise/test_init.py (3)

399-400: Use safe dictionary access instead of direct indexing.

Lines 399-400 use unsafe dictionary indexing on DEFAULT_SCAN_INTERVAL[mock_smile_adam_heat_cool.smile.type] without a fallback. If smile.type isn't in the dictionary, this will raise a KeyError. Consider using .get() with a default value to match the pattern used in the coordinator.

🔎 Proposed fix
-    assert DEFAULT_SCAN_INTERVAL[mock_smile_adam_heat_cool.smile.type] == timedelta(seconds=60)
-    freezer.tick(DEFAULT_SCAN_INTERVAL[mock_smile_adam_heat_cool.smile.type])
+    interval = DEFAULT_SCAN_INTERVAL.get(mock_smile_adam_heat_cool.smile.type, timedelta(seconds=60))
+    assert interval == timedelta(seconds=60)
+    freezer.tick(interval)

417-417: Fix the docstring copy-paste error.

The docstring says "Test Adam update interval" but this test is for the P1 gateway, not Adam.

🔎 Proposed fix
-    """Test Adam update interval."""
+    """Test P1 update interval."""

425-426: Use safe dictionary access instead of direct indexing.

Lines 425-426 use unsafe dictionary indexing on DEFAULT_SCAN_INTERVAL[mock_smile_p1.smile.type] without a fallback. If smile.type isn't in the dictionary, this will raise a KeyError. Consider using .get() with a default value to match the pattern used in the coordinator.

🔎 Proposed fix
-    assert DEFAULT_SCAN_INTERVAL[mock_smile_p1.smile.type] == timedelta(seconds=10)
-    freezer.tick(DEFAULT_SCAN_INTERVAL[mock_smile_p1.smile.type])
+    interval = DEFAULT_SCAN_INTERVAL.get(mock_smile_p1.smile.type, timedelta(seconds=10))
+    assert interval == timedelta(seconds=10)
+    freezer.tick(interval)
📜 Review details

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between d0cda1a and 6421361.

📒 Files selected for processing (1)
  • tests/components/plugwise/test_init.py
🧰 Additional context used
🧠 Learnings (1)
📚 Learning: 2025-08-23T16:26:34.700Z
Learnt from: bouwew
Repo: plugwise/plugwise-beta PR: 906
File: tests/components/plugwise/test_binary_sensor.py:9-16
Timestamp: 2025-08-23T16:26:34.700Z
Learning: The Plugwise integration test files import utilities like `snapshot_platform`, `MockConfigEntry`, and `async_fire_time_changed` from `tests.common`, which is from the Home Assistant core repository at https://github.com/home-assistant/core/blob/master/tests/common.py, not from local test files.

Applied to files:

  • tests/components/plugwise/test_init.py
🧬 Code graph analysis (1)
tests/components/plugwise/test_init.py (1)
tests/components/plugwise/conftest.py (3)
  • mock_config_entry (81-95)
  • mock_smile_adam_heat_cool (185-208)
  • mock_smile_p1 (295-317)
🪛 GitHub Actions: Test PR against HA-core
tests/components/plugwise/test_init.py

[error] 1-1: Pre-commit hook 'ruff' reported code changes and ultimately failed with exit code 1. 1 error fixed, 0 remaining. The hook modified the file (e.g., removal of an unused import: 'from homeassistant.setup import async_setup_component').

🔇 Additional comments (3)
tests/components/plugwise/test_init.py (3)

17-17: LGTM!

The import of DEFAULT_SCAN_INTERVAL is correctly added and used in the new test cases.


159-159: LGTM!

The migration from async_setup_component to hass.config_entries.async_setup(mock_config_entry.entry_id) is the correct approach for testing config entry-based integrations. This pattern is consistently applied across all affected tests.

Also applies to: 284-284, 364-364


383-405: Well-structured test for update interval verification.

The test correctly:

  • Sets up the config entry and verifies the LOADED state
  • Checks the initial update call count
  • Uses freezer.tick() to advance time by the expected interval
  • Triggers the coordinator update with async_fire_time_changed
  • Verifies the second update call

@bouwew bouwew force-pushed the test-update-interval branch 2 times, most recently from ed0e836 to f56ef94 Compare December 23, 2025 11:13
@bouwew bouwew marked this pull request as ready for review December 23, 2025 11:43
@bouwew bouwew requested a review from a team as a code owner December 23, 2025 11:43
@bouwew bouwew force-pushed the test-update-interval branch from 1e4d7fe to 5b2f882 Compare December 26, 2025 09:21
@sonarqubecloud
Copy link

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