Skip to content

Conversation

@bouwew
Copy link
Contributor

@bouwew bouwew commented Nov 8, 2025

Fix a missed count, also line up fixture and test-json format for easier comparing and updating.

Summary by CodeRabbit

  • Bug Fixes
    • Improved cooling-mode data handling and counter accounting; setpoint keys are now handled more safely.
  • Tests
    • Updated and flattened test fixture data; added assertions to device tests and simplified test runner invocation.
  • Documentation
    • CHANGELOG updated with an "Ongoing" section noting testing and fixture alignment.
  • Chores
    • Streamlined test infrastructure and test execution configuration.

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Nov 8, 2025

Walkthrough

Adjusted setpoint and entity-counting logic in plugwise/data.py, added guarded setpoint removals and a debug log on gateway updates, flattened many test JSON fixtures by removing the top-level "devices" wrapper, simplified the test runner script, and changed tests to capture and assert returned items from device_test.

Changes

Cohort / File(s) Summary
Core data logic
plugwise/data.py
Reworked Anna thermostat setpoint handling (replace thermostat with temp_dict keys setpoint_low/setpoint_high), guarded removal of setpoint from sensors, adjusted internal _count arithmetic (cooling path +3 total; conditional decrement when removing setpoint), and added DEBUG logging after gateway entity updates. Also incremented _count when cooling_enabled added to Adam binary_sensors.
Test runner
scripts/tests_and_coverage.sh
Replaced previous pytest invocation and coverage fallback with a single deterministic pytest -xrpP --log-level debug tests/ call; removed coverage flags and fallback behavior.
Test fixtures — flattened device maps
tests/data/anna/*.json, tests/data/adam/*.json, tests/data/p1/*.json, tests/data/stretch/*.json, tests/data/*/*_UPDATED_DATA.json, tests/data/*/…
Removed the outer "devices" wrapper across many fixtures and promoted per-device entries to top-level keys; in several fixtures device blocks were restructured/promoted (fields preserved, access path changed). One fixture (tests/data/p1/p1v4.json) deleted.
Tests — Adam
tests/test_adam.py
device_test return value captured as test_items and asserted equal to self.entity_items in multiple tests.
Tests — Init
tests/test_init.py
Inner helper now returns computed asserts; caller wraps testdata into {"devices": testdata} and propagates returned asserts.
Changelog
CHANGELOG.md
Added "Ongoing" subsection noting testing/fixture and counter alignment fixes.

Sequence Diagram(s)

sequenceDiagram
    participant Caller as Test runner / Consumer
    participant Data as plugwise/data.py
    participant Logger as LOGGER
    participant Counter as _count

    Note over Caller,Data: Device/fixture processing and counting (high level)

    Caller->>Data: load device(s) (now top-level keys)
    Data->>Data: detect thermostat type (Anna / Adam)
    alt Anna cooling path
        Data->>Data: build temp_dict with setpoint_low & setpoint_high
        Data->>Data: if "setpoint" in sensors?
        alt exists
            Data->>Data: remove sensors["setpoint"]
            Data->>Counter: _count -= 1
        else not exists
            Note right of Data: skip removal
        end
        Data->>Counter: _count += 3
    end

    alt Adam path
        Data->>Data: add "cooling_enabled" to binary_sensors
        Data->>Counter: _count += 1
    end

    Data->>Logger: DEBUG "gateway entity updated"
    Logger-->>Caller: log output
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

  • Review focus:
    • plugwise/data.py — verify setpoint -> temp_dict changes, guarded removal, and _count arithmetic correctness across cooling and location code paths.
    • Spot-check several representative flattened JSON fixtures for accidental data loss or schema regressions.
    • Confirm tests expecting returned device_test value align with its implementation.

Possibly related PRs

Suggested labels

bug, enhancement

Suggested reviewers

  • bouwew

Poem

"🐰 I hopped through counts and setpoints bright,

Flattened fields into the open light.
A debug twitch, a guarded little skip,
Tests now check the harvest from my trip.
Carrot-cake for careful code — delight!"

Pre-merge checks and finishing touches

❌ Failed checks (1 inconclusive)
Check name Status Explanation Resolution
Title check ❓ Inconclusive The title 'Improve testing' is vague and generic, using non-descriptive language that doesn't convey the specific changes made in this substantial changeset. Consider a more specific title that reflects the main changes, such as 'Refactor test data structure and fix count alignment' or 'Flatten JSON test fixtures and align test counters'.
✅ Passed checks (2 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%.
✨ 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_main

📜 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 6b0a695 and 7fce160.

📒 Files selected for processing (2)
  • CHANGELOG.md (1 hunks)
  • plugwise/data.py (3 hunks)
✅ Files skipped from review due to trivial changes (1)
  • CHANGELOG.md
🧰 Additional context used
🧠 Learnings (1)
📚 Learning: 2024-12-13T11:26:00.100Z
Learnt from: bouwew
Repo: plugwise/python-plugwise PR: 671
File: plugwise/legacy/data.py:97-106
Timestamp: 2024-12-13T11:26:00.100Z
Learning: In `plugwise/legacy/data.py`, the legacy thermostat does not support cooling, so handling of the cooling state is unnecessary in this code.

Applied to files:

  • plugwise/data.py
🔇 Additional comments (3)
plugwise/data.py (3)

141-155: LGTM! Counter arithmetic and comments are now accurate.

The setpoint handling logic is correct:

  • Thermostat dict: adds 2 keys (setpoint_low, setpoint_high), removes 1 (setpoint)
  • Sensors dict: adds 2 keys (setpoint_low, setpoint_high), conditionally removes 1 (setpoint)
  • Counter adjustment: +3 base increment, -1 when setpoint exists in sensors = net +2 or +3

The improved inline comments clearly document each step, addressing the previous review concern about misleading arithmetic.


173-175: Good defensive programming.

The guarded removal prevents potential KeyError exceptions and ensures the counter is only decremented when an actual removal occurs. This aligns well with the conditional handling pattern used in _update_for_cooling.


248-248: LGTM! Counter increment is correct.

The counter increment accurately tracks the addition of the cooling_enabled binary sensor, consistent with counting patterns used elsewhere in the file.


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.

@codecov
Copy link

codecov bot commented Nov 8, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 100.00%. Comparing base (afc9a02) to head (7fce160).
⚠️ Report is 17 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff            @@
##              main      #815   +/-   ##
=========================================
  Coverage   100.00%   100.00%           
=========================================
  Files           21        21           
  Lines         3377      3390   +13     
=========================================
+ Hits          3377      3390   +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 November 8, 2025 16:13
@bouwew bouwew requested a review from a team as a code owner November 8, 2025 16:13
@bouwew bouwew changed the title Improve double-check of test items Improve testing Nov 8, 2025
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 (1)
plugwise/data.py (1)

83-83: Replace informal debug message with descriptive text.

The debug message "HOI count" uses informal language. Consider using a more descriptive message that explains what is being counted.

-            LOGGER.debug("HOI count: %s", self._count)
+            LOGGER.debug("Entity data item count: %s", self._count)
📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between afc9a02 and 6b0a695.

📒 Files selected for processing (45)
  • plugwise/data.py (5 hunks)
  • scripts/tests_and_coverage.sh (1 hunks)
  • tests/data/adam/adam_heatpump_cooling.json (1 hunks)
  • tests/data/adam/adam_jip.json (1 hunks)
  • tests/data/adam/adam_multiple_devices_per_zone.json (1 hunks)
  • tests/data/adam/adam_onoff_cooling_fake_firmware.json (1 hunks)
  • tests/data/adam/adam_plus_anna.json (1 hunks)
  • tests/data/adam/adam_plus_anna_new.json (1 hunks)
  • tests/data/adam/adam_plus_anna_new_UPDATED_DATA.json (1 hunks)
  • tests/data/adam/adam_plus_anna_new_regulation_off.json (1 hunks)
  • tests/data/adam/adam_zone_per_device.json (1 hunks)
  • tests/data/anna/anna_elga_2.json (1 hunks)
  • tests/data/anna/anna_elga_2_cooling.json (1 hunks)
  • tests/data/anna/anna_elga_2_cooling_UPDATED_DATA.json (1 hunks)
  • tests/data/anna/anna_elga_2_schedule_off.json (1 hunks)
  • tests/data/anna/anna_elga_no_cooling.json (1 hunks)
  • tests/data/anna/anna_heatpump_cooling.json (1 hunks)
  • tests/data/anna/anna_heatpump_cooling_fake_firmware.json (1 hunks)
  • tests/data/anna/anna_heatpump_heating.json (1 hunks)
  • tests/data/anna/anna_heatpump_heating_UPDATED_DATA.json (1 hunks)
  • tests/data/anna/anna_loria_cooling_active.json (1 hunks)
  • tests/data/anna/anna_loria_driessens.json (1 hunks)
  • tests/data/anna/anna_loria_heating_idle.json (1 hunks)
  • tests/data/anna/anna_p1.json (1 hunks)
  • tests/data/anna/anna_v4.json (1 hunks)
  • tests/data/anna/anna_v4_UPDATED_DATA.json (1 hunks)
  • tests/data/anna/anna_v4_dhw.json (1 hunks)
  • tests/data/anna/anna_v4_no_modules.json (1 hunks)
  • tests/data/anna/anna_v4_no_tag.json (1 hunks)
  • tests/data/anna/anna_without_boiler_fw441.json (1 hunks)
  • tests/data/anna/legacy_anna.json (1 hunks)
  • tests/data/anna/legacy_anna_2.json (1 hunks)
  • tests/data/p1/p1v4.json (0 hunks)
  • tests/data/p1/p1v4_442_single.json (1 hunks)
  • tests/data/p1/p1v4_442_single_UPDATED_DATA.json (1 hunks)
  • tests/data/p1/p1v4_442_triple.json (1 hunks)
  • tests/data/p1/smile_p1_v2.json (1 hunks)
  • tests/data/p1/smile_p1_v2_2.json (1 hunks)
  • tests/data/p1/smile_p1_v2_2_UPDATED_DATA.json (1 hunks)
  • tests/data/stretch/stretch_v23.json (1 hunks)
  • tests/data/stretch/stretch_v27_no_domain.json (1 hunks)
  • tests/data/stretch/stretch_v31.json (1 hunks)
  • tests/data/stretch/stretch_v31_UPDATED_DATA.json (1 hunks)
  • tests/test_adam.py (7 hunks)
  • tests/test_init.py (2 hunks)
💤 Files with no reviewable changes (1)
  • tests/data/p1/p1v4.json
🧰 Additional context used
🧠 Learnings (4)
📚 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:

  • tests/data/anna/anna_loria_driessens.json
  • tests/data/adam/adam_plus_anna_new.json
  • tests/data/anna/anna_v4_no_modules.json
  • tests/data/adam/adam_heatpump_cooling.json
  • tests/data/anna/anna_loria_heating_idle.json
  • tests/data/p1/smile_p1_v2_2.json
  • tests/data/anna/anna_heatpump_heating_UPDATED_DATA.json
  • tests/data/anna/anna_v4_UPDATED_DATA.json
  • tests/data/anna/anna_elga_no_cooling.json
  • tests/data/stretch/stretch_v23.json
  • tests/data/anna/anna_elga_2_cooling.json
  • tests/data/anna/anna_p1.json
  • tests/data/p1/p1v4_442_triple.json
  • tests/data/adam/adam_onoff_cooling_fake_firmware.json
  • tests/data/anna/legacy_anna.json
  • tests/data/anna/anna_loria_cooling_active.json
  • tests/data/anna/anna_v4.json
  • tests/data/adam/adam_zone_per_device.json
  • tests/data/anna/anna_heatpump_cooling_fake_firmware.json
  • tests/data/anna/anna_heatpump_heating.json
  • tests/data/adam/adam_plus_anna_new_regulation_off.json
  • tests/data/stretch/stretch_v31.json
  • tests/data/anna/anna_v4_dhw.json
  • tests/data/anna/legacy_anna_2.json
  • tests/data/anna/anna_heatpump_cooling.json
  • tests/data/p1/smile_p1_v2.json
  • tests/data/p1/p1v4_442_single_UPDATED_DATA.json
  • tests/data/p1/p1v4_442_single.json
  • tests/data/adam/adam_jip.json
  • tests/data/adam/adam_plus_anna.json
  • tests/data/adam/adam_multiple_devices_per_zone.json
  • tests/data/anna/anna_elga_2_cooling_UPDATED_DATA.json
  • tests/data/anna/anna_elga_2_schedule_off.json
  • tests/data/stretch/stretch_v31_UPDATED_DATA.json
  • tests/data/adam/adam_plus_anna_new_UPDATED_DATA.json
  • tests/data/anna/anna_v4_no_tag.json
  • tests/data/anna/anna_without_boiler_fw441.json
  • tests/data/stretch/stretch_v27_no_domain.json
  • tests/data/anna/anna_elga_2.json
📚 Learning: 2024-12-13T11:26:00.100Z
Learnt from: bouwew
Repo: plugwise/python-plugwise PR: 671
File: plugwise/legacy/data.py:97-106
Timestamp: 2024-12-13T11:26:00.100Z
Learning: In `plugwise/legacy/data.py`, the legacy thermostat does not support cooling, so handling of the cooling state is unnecessary in this code.

Applied to files:

  • tests/data/adam/adam_heatpump_cooling.json
  • tests/data/anna/anna_loria_heating_idle.json
  • plugwise/data.py
  • tests/data/anna/anna_elga_2_cooling.json
  • tests/data/adam/adam_onoff_cooling_fake_firmware.json
  • tests/data/anna/anna_loria_cooling_active.json
  • tests/data/anna/anna_elga_2_cooling_UPDATED_DATA.json
  • tests/data/anna/anna_elga_2_schedule_off.json
  • tests/data/anna/anna_elga_2.json
📚 Learning: 2024-10-06T16:03:27.250Z
Learnt from: bouwew
Repo: plugwise/python-plugwise PR: 630
File: tests/data/adam/adam_g_o.json:0-0
Timestamp: 2024-10-06T16:03:27.250Z
Learning: The minimal information for the `heater_central` device is due to a known bug still present in the code.

Applied to files:

  • tests/data/anna/anna_heatpump_heating_UPDATED_DATA.json
  • tests/data/anna/anna_heatpump_cooling_fake_firmware.json
  • tests/data/anna/anna_heatpump_heating.json
📚 Learning: 2025-01-29T19:14:31.257Z
Learnt from: CoMPaTech
Repo: plugwise/python-plugwise PR: 698
File: fixtures/m_adam_multiple_devices_per_zone/data.json:21-21
Timestamp: 2025-01-29T19:14:31.257Z
Learning: MAC addresses in test fixtures of the python-plugwise repository are mock addresses and do not represent real device information.

Applied to files:

  • tests/data/adam/adam_zone_per_device.json
  • tests/data/stretch/stretch_v31.json
  • tests/data/adam/adam_multiple_devices_per_zone.json
  • tests/data/stretch/stretch_v27_no_domain.json
🧬 Code graph analysis (1)
tests/test_adam.py (1)
tests/test_init.py (1)
  • device_test (479-603)
🪛 Gitleaks (8.28.0)
tests/test_adam.py

[high] 36-36: Detected a Generic API Key, potentially exposing access to various services and sensitive operations.

(generic-api-key)


[high] 215-215: Detected a Generic API Key, potentially exposing access to various services and sensitive operations.

(generic-api-key)


[high] 416-416: Detected a Generic API Key, potentially exposing access to various services and sensitive operations.

(generic-api-key)

🔇 Additional comments (49)
tests/data/anna/anna_v4_UPDATED_DATA.json (1)

1-53: LGTM — Valid fixture structure supporting fixture flattening refactoring.

The JSON fixture is syntactically valid with reasonable, realistic data values. The three top-level device entries (boiler/HVAC, thermostat/climate, and weather sensor) are properly structured and internally consistent. Field naming follows project conventions (snake_case).

This flattened structure aligns with the PR's stated goal of simplifying test fixtures by removing the "devices" wrapper, and mirrors the pattern across related fixture files documented in the enriched summary.

To confirm fixture integrity across the broader refactoring, please verify:

  1. Test code consuming this fixture can still locate and access devices by their hex IDs (now at top level rather than nested).
  2. The changes to plugwise/data.py (mentioned in the AI summary) correctly handle this flattened structure when parsing fixtures.

If you'd like, I can generate a verification script to search for usages of this fixture file in the test suite to confirm compatibility.

tests/data/anna/anna_elga_no_cooling.json (1)

1-93: Fixture successfully flattened to top-level device entries.

The JSON structure is valid and consistent. All three devices are properly defined as top-level entries with appropriate fields for their device classes (gateway, heater_central, thermostat). Location references are present and follow the expected pattern per the fixture design—organizational locations without corresponding top-level entries is acceptable for non-climate devices.

Please verify that all test code consuming this fixture has been updated to handle the new flattened structure (previously nested under a "devices" key). Based on the PR summary, tests should have been updated to capture and assert returned items accordingly.

tests/data/anna/anna_loria_cooling_active.json (1)

1-96: Fixture structure properly flattened and valid.

The JSON is well-formed and correctly implements the flattened structure per the PR objectives. Device entries are elevated to root-level keys with internal structure preserved. Setpoint values are consistent with their bounds, and location references align with the learning that location IDs need not have top-level definitions unless they're climate zones with thermostat data.

To confirm this fixture integrates correctly with the test suite, please verify:

  1. The test code that loads this fixture expects the flattened root-level structure (not a nested "devices" wrapper).
  2. Any tests that assert on device properties (e.g., cooling state, setpoints) match the values in this file.
tests/data/p1/p1v4_442_single_UPDATED_DATA.json (1)

1-19: LGTM - Fixture properly flattened.

JSON structure is valid, sensor naming conventions are consistent, and device ID keying matches the PR's flattening pattern.

tests/data/p1/p1v4_442_triple.json (1)

1-56: LGTM - Device hierarchy and fixture properly structured.

Gateway and smartmeter are correctly organized at top-level with appropriate location references. JSON is valid, sensor naming is consistent, and the notification structure is properly nested.

tests/data/p1/p1v4_442_single.json (1)

1-43: LGTM - Single meter variant properly structured.

Device hierarchy is correct, location references are appropriate, and sensor data reflects realistic differences between meter types. Unicode escaping in vendor name is properly handled.

tests/data/anna/anna_p1.json (1)

1-104: Valid fixture structure with proper flattening.

The JSON fixture is syntactically valid and correctly flattened per the PR's intent. All four devices have required fields (dev_class, name, vendor, location), and data types are correct. Location reference 5b13651d79c4454684fd268850b1bff8 (lines 10) is undefined at root level, but this is acceptable per your learnings—only climate-zone devices require full top-level location definitions, and this thermostat is a "thermostat" class, not a "climate" class.

One structural note: device da7be222ab3b420c927f3e49fade0304 (the P1 smartmeter) shares its ID as the location for multiple devices. This dual role appears intentional in your test architecture but is worth confirming during test validation.

Verify that the test code consuming this fixture has been updated to handle the flattened root-level structure (removal of the old "devices" wrapper) and correctly traverses the device entries.

tests/data/adam/adam_jip.json (1)

1-379: JSON fixture structure refactored cleanly.

The fixture successfully flattens device entries from a nested "devices" container to root-level objects while preserving all device data and internal field structure. All 11 devices maintain complete field integrity.

tests/data/p1/smile_p1_v2_2_UPDATED_DATA.json (1)

1-16: P1 fixture flattened consistently.

Single smartmeter device successfully moved to root level with all sensor data preserved. Follows the established fixture restructuring pattern.

scripts/tests_and_coverage.sh (1)

59-64: Verify coverage reporting removal.

The pytest invocation has been simplified by removing --cov, --no-cov-on-fail, and --cov-report term-missing options. While the new command is cleaner (with improved -xrpP flags for better output), this represents a meaningful change to test reporting.

  • Is coverage now handled by a separate command or CI step?
  • Was coverage reporting a blocker or optional for these test runs?
  • Does this change affect CI/CD coverage requirements?

The change aligns with the PR's "improve double-check" goal if coverage is being refactored elsewhere, but please confirm the new test coverage strategy.

tests/data/anna/anna_v4_no_modules.json (1)

1-20: Anna fixture (no modules) flattened correctly.

Gateway device successfully elevated to root level. All metadata and sensor data preserved. Fixture minimal and appropriate given filename intent.

tests/data/adam/adam_heatpump_cooling.json (1)

1-807: Complex heatpump cooling fixture restructured successfully.

This comprehensive fixture with ~31 devices (climate zones, thermostats, valve actuators, gateway, heater central) is successfully flattened. All internal cross-references (thermostat arrays, location IDs) remain intact. Cooling-related fields and modes are preserved throughout.

tests/data/stretch/stretch_v23.json (1)

1-354: Stretch gateway fixture flattened with references verified.

~17 devices including gateway, lamps, appliances, and switchgroup are successfully promoted to root level. Cross-references between devices (e.g., switchgroup members array) remain valid and point to existing device IDs.

tests/data/adam/adam_multiple_devices_per_zone.json (1)

1-605: Multi-device-per-zone fixture flattened with cross-references intact.

~24 devices are successfully promoted to root level, including 5 climate zones with multiple thermostatic devices per zone (e.g., Badkamer has 2 thermostat devices in primary array). All cross-references between zones and their assigned devices remain valid.

tests/data/anna/anna_loria_heating_idle.json (1)

1-96: Anna Loria heating-idle fixture correctly structured.

Three core devices (thermostat, gateway, heater central) are successfully flattened to root level. Heating state correctly set to idle (heating_state: false, control_state: "idle"), and cooling disabled as expected for Anna. All nested control structures preserved.

plugwise/data.py (3)

13-13: LGTM: LOGGER import added for debug logging.

The LOGGER import supports the new debug logging at line 83.


170-172: LGTM: Added safety check before removing setpoint.

The conditional check prevents attempting to remove a non-existent key and correctly decrements the counter only when removal occurs. This is a good defensive coding practice.


245-245: LGTM: Counter increment added for cooling_enabled binary sensor.

The counter increment correctly reflects the addition of the cooling_enabled binary sensor.

tests/data/anna/anna_v4_dhw.json (1)

1-88: LGTM: Test fixture structure flattened consistently.

The "devices" wrapper has been removed and each device is now a top-level entry. This aligns with the PR's objective to restructure test data for improved validation. The device content appears preserved with only the structural organization changed.

tests/data/adam/adam_zone_per_device.json (1)

1-589: LGTM: Large test fixture restructured consistently.

This fixture has been flattened from a nested "devices" structure to top-level device entries. The restructuring is consistent with the broader PR pattern and preserves all device data while improving test data organization.

tests/data/anna/anna_v4.json (1)

1-88: LGTM: Test fixture structure flattened consistently.

This fixture follows the same flattening pattern as its sibling anna_v4_dhw.json, with device entries promoted to top-level keys. The restructuring is consistent and maintains data integrity.

tests/data/stretch/stretch_v27_no_domain.json (1)

1-272: LGTM: Stretch test fixture restructured consistently.

The Stretch gateway and Circle device entries have been promoted to top-level keys, following the same flattening pattern as other fixtures in this PR. The restructuring maintains all device data while improving test data accessibility.

tests/data/anna/legacy_anna.json (1)

1-62: LGTM: Legacy test fixture restructured consistently.

The legacy Anna fixture has been flattened to match the new structure. This ensures consistency across all test fixtures while maintaining backward compatibility test coverage.

tests/data/adam/adam_plus_anna_new_UPDATED_DATA.json (1)

1-45: LGTM: Updated data fixture restructured consistently.

This UPDATED_DATA fixture contains partial device updates and has been flattened to match the new structure. The device IDs are now top-level keys with only the updated fields included, which is appropriate for a delta update file.

tests/data/anna/anna_elga_2_cooling.json (1)

1-91: LGTM: Cooling test fixture restructured and aligns with source code changes.

This cooling-enabled fixture has been flattened and correctly uses setpoint_high and setpoint_low (lines 54-55, 67-68) instead of a single setpoint. This structure aligns with the cooling logic changes in plugwise/data.py at lines 147-152 where setpoints are split for cooling scenarios.

tests/data/adam/adam_plus_anna.json (1)

1-129: Fixture flattening applied correctly. The restructuring from nested devices container to top-level device entries is consistent and complete. Cross-device references (e.g., thermostats array) correctly reference existing device IDs.

tests/data/anna/anna_heatpump_heating.json (1)

1-97: Fixture restructuring is consistent and complete. Device entries properly flattened to root level with all expected fields present for each device class.

tests/data/anna/anna_v4_no_tag.json (1)

1-88: Fixture restructuring applied consistently. All devices properly elevated to root level with complete metadata.

tests/data/p1/smile_p1_v2.json (1)

1-34: P1 fixture correctly flattened. Smartmeter and gateway elevated to root level with complete sensor and metadata fields.

tests/data/anna/anna_elga_2_cooling_UPDATED_DATA.json (1)

1-90: Fixture correctly structured with appropriate cooling variant data. Device entries properly flattened, cooling-related fields present in heater_central and thermostat as expected.

tests/data/anna/anna_elga_2_schedule_off.json (1)

1-91: Fixture variant correctly reflects schedule-off state. Device structure consistent with cooling variant, with appropriate value differences (select_schedule="off", idle state, disabled binary sensors).

tests/data/anna/anna_elga_2.json (1)

1-85: Fixture variant represents active heating scenario. Structure consistent with related anna_elga_2 variants, with appropriate state values for active heating operation.

tests/data/anna/legacy_anna_2.json (1)

1-64: Legacy fixture structure correct. Appropriately represents older Anna system without cooling support—note thermostat lacks cooling-related fields and preset is null. Structure consistent with flattening pattern.

tests/data/anna/anna_without_boiler_fw441.json (1)

1-61: LGTM! Structural refactoring aligns with PR objectives.

The removal of the top-level "devices" wrapper and promotion of device entries to root-level keys is consistent with the broader data shape migration across this PR. The internal device structures are preserved correctly.

tests/data/anna/anna_heatpump_cooling.json (1)

1-92: LGTM! Consistent structural refactoring.

The flattening of the device hierarchy is applied consistently. All device data is correctly preserved at the new root level.

tests/data/adam/adam_plus_anna_new_regulation_off.json (1)

1-286: LGTM! Complex fixture successfully restructured.

The flattening is correctly applied to this more complex fixture containing multiple device types (gateway, heater_central, plugs, thermostats, climate zones). All device relationships and data are preserved.

tests/data/adam/adam_plus_anna_new.json (1)

1-337: LGTM! Extensive fixture properly flattened.

The structural changes are correctly applied to this comprehensive fixture. All device entries and their relationships are preserved in the new flat structure.

tests/test_init.py (2)

540-540: Good addition: Return value enables validation.

Returning the asserts count allows callers to verify the number of assertions performed, improving test coverage and debugging capability.


598-602: Smart adaptation to flattened fixture structure.

Wrapping the flat testdata in a "devices" key maintains backward compatibility with the test_and_assert helper while working with the new root-level device entries in JSON fixtures. The return value propagation enables the caller to validate assertion counts.

tests/test_adam.py (3)

35-38: Excellent: Added assertion validates test coverage.

Capturing the return value from device_test and asserting it matches entity_items ensures that all expected items are actually being tested. This pattern improves test reliability.


214-217: LGTM! Consistent validation pattern across all tests.

The assertion pattern assert test_items == self.entity_items is consistently applied across all test methods, ensuring comprehensive validation of item counts throughout the test suite.

Also applies to: 289-291, 326-328, 350-352, 374-377, 415-418


36-36: Static analysis false positive: These are device IDs, not API keys.

The static analysis tool flagged these hexadecimal device IDs as potential API keys. These are test fixture identifiers used for assertions and pose no security risk. The warnings can be safely ignored.

Based on learnings (these are known test fixture identifiers in the Plugwise test suite).

Also applies to: 215-215, 416-416

tests/data/anna/anna_heatpump_heating_UPDATED_DATA.json (1)

1-38: LGTM! UPDATED_DATA fixture correctly restructured.

This minimal update fixture follows the same flattening pattern as other files in the PR, maintaining consistency across all test data files.

tests/data/anna/anna_heatpump_cooling_fake_firmware.json (1)

1-92: LGTM! Final fixture successfully restructured.

The structural refactoring is correctly applied to this test variant. All fixtures in the PR now follow the consistent flat root-level device structure.

tests/data/stretch/stretch_v31_UPDATED_DATA.json (1)

1-44: Fixture structure correctly flattened.

The fixture successfully promotes device entries to top-level objects keyed by device ID. Cross-references within the structure (members array at line 36–39 references other devices defined in the same fixture) are properly maintained.

tests/data/p1/smile_p1_v2_2.json (1)

1-34: Fixture structure correctly flattened.

Smartmeter and gateway entries are properly promoted to top-level, and cross-references (location IDs) are maintained consistently. All expected fields are present in each device entry.

One observation: the file annotation shows smile_p1_v2_2.json but the AI summary references smile_p1_v2_UPDATED_DATA.json. Please confirm whether the _2 suffix is intentional or if this file should follow the _UPDATED_DATA naming pattern used elsewhere in the PR.

tests/data/adam/adam_onoff_cooling_fake_firmware.json (1)

1-111: Complex fixture structure correctly flattened with proper referential integrity.

All four device entries (heater, gateway, thermostat, climate zone) are properly promoted to top-level and keyed by device ID. Cross-references are correctly maintained:

  • Thermostat (line 68–79) location references the climate zone ID
  • Climate zone's thermostats array (line 106–108) references the thermostat device ID
  • Climate zone has the full required structure per fixture design (active_preset, available_schedules, preset_modes, thermostat configuration, etc.)

Setpoint values are consistent between thermostat and climate zone (both 21.5).

tests/data/stretch/stretch_v31.json (1)

1-136: Comprehensive fixture correctly flattened with all cross-references validated.

All seven top-level entries (gateway, five individual devices, two group/report entries) are properly keyed by device ID. Cross-references within the structure are complete and valid:

  • Switch group d03738edfcc947f7b8f4573571d90d2d (line 88–99) members array references existing devices
  • Report group d950b314e9d8499f968e6db8d82ef78c (line 101–115) members array references all five defined devices
  • All individual devices consistently reference the gateway as their location
  • Each device retains its complete field set (dev_class, firmware, hardware, location, model, name, sensors, switches, vendor, zigbee_mac_address)
tests/data/anna/anna_loria_driessens.json (1)

1-102: JSON structure is valid and flattened correctly.

The fixture has been successfully restructured from a nested "devices" container to a root-level device map. All three devices (gateway, thermostat, and heater_central) are properly structured with required fields and location references intact. JSON syntax validation confirms no parsing errors.

@sonarqubecloud
Copy link

sonarqubecloud bot commented Nov 8, 2025

@bouwew bouwew merged commit 09e66c8 into main Nov 8, 2025
18 checks passed
@bouwew bouwew deleted the test_main branch November 8, 2025 16:33
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