Skip to content

Add water_heater platform to cover domestic_hot_water heating#1085

Draft
bouwew wants to merge 49 commits into
mainfrom
water_heater
Draft

Add water_heater platform to cover domestic_hot_water heating#1085
bouwew wants to merge 49 commits into
mainfrom
water_heater

Conversation

@bouwew

@bouwew bouwew commented Jun 7, 2026

Copy link
Copy Markdown
Contributor

Summary by CodeRabbit

Release Notes

  • New Features

    • Added a Plugwise “Water heater” platform to view and control DHW mode (comfort/off) and set the DHW target temperature.
  • Changes

    • DHW mode control has been moved from the previous switch to the water-heater entity.
    • DHW target temperature calculation and temperature setpoint mapping were updated.
    • Localization for DHW mode labels was updated.
  • Tests

    • Added water-heater snapshot and control tests, updated fixtures/snapshots, and adjusted related number/snapshot coverage.

@coderabbitai

coderabbitai Bot commented Jun 7, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

📝 Walkthrough

Walkthrough

The PR adds a complete water heater platform to Plugwise that registers heater_central devices, manages DHW operation modes (comfort, off, auto, boost), reports current and target temperatures from device state, and controls setpoints via the coordinator API. DHW temperature control is moved from the number platform to this dedicated water heater entity. All test fixtures are updated with DHW mode configuration, and comprehensive snapshot tests validate both Adam and Anna device scenarios.

Changes

Water Heater Platform Implementation

Layer / File(s) Summary
Platform declaration and constants
custom_components/plugwise/const.py
Adds DHW_MODE constant and declares Platform.WATER_HEATER in the PLATFORMS list to register the new water heater platform.
Water heater entity implementation
custom_components/plugwise/water_heater.py
Implements async_setup_entry that filters heater_central devices with non-None max_dhw_temperature, creates entity instances, and wires them to the coordinator's device-update listener. PlugwiseWaterHeaterEntity sets Celsius as temperature unit, declares OPERATION_MODE and TARGET_TEMPERATURE feature support, exposes current_operation from dhw_mode, current_temperature from water_temperature sensor, operation_list from dhw_modes, and target_temperature from device bounds. Control methods async_set_operation_mode and async_set_temperature forward to coordinator API.
Number platform refactoring
custom_components/plugwise/number.py, tests/components/plugwise/test_number.py, tests/components/plugwise/snapshots/test_number.ambr
Removes MAX_DHW_TEMP import and NUMBER_TYPES entry; updates boiler temperature setpoint to use MAX_BOILER_TEMP instead. Deletes test_adam_dhw_setpoint_change test case and removes corresponding snapshot entries since DHW temperature control now lives in the water heater platform.
Switch platform refactoring
custom_components/plugwise/switch.py
Removes DHW_CM_SWITCH constant import and entity description from PLUGWISE_SWITCHES tuple. DHW control switches are no longer created; operation mode management is now exclusively through the water heater platform.
Dependency update and localization
custom_components/plugwise/manifest.json, custom_components/plugwise/strings.json, custom_components/plugwise/translations/en.json, custom_components/plugwise/translations/nl.json
Updates plugwise package requirement to git branch @dhw_update. Adds water_heater entity localization block with DHW mode label and state translations for auto, boost, comfort, and off in both English and Dutch. Extends select_dhw_mode translations with comfort and off states.
Test fixture updates
tests/components/plugwise/fixtures/anna_v4_dhw/data.json, tests/components/plugwise/fixtures/*/data.json
New anna_v4_dhw fixture provides complete thermostat, gateway, and heater_central device test data with DHW configuration. All existing fixtures (adam_plus_anna_new, anna_heatpump_heating, anna_p1, anna_v4, m_adam_cooling, m_adam_heating, m_adam_heating_off_schedule, m_adam_jip, m_anna_heatpump_cooling) are updated to replace switches.dhw_cm_switch with dhw_mode, dhw_modes array, and select_dhw_mode field.
Water heater tests and snapshots
tests/components/plugwise/test_water_heater.py, tests/components/plugwise/snapshots/test_water_heater.ambr, tests/components/plugwise/snapshots/test_select.ambr
Introduces three async tests: Adam snapshot test (DHW off); Adam setpoint change test (validates set_temperature calls coordinator set_number with 65°C and set_operation_mode calls set_dhw_mode); Anna snapshot test (DHW on with anna_v4_dhw fixture). Provides entity registry and state snapshots for both scenarios. Select snapshot updated with select.opentherm_dhw_mode coverage.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Possibly related PRs

  • plugwise/plugwise-beta#844: Modifies custom_components/plugwise/manifest.json to update the plugwise library dependency version.
  • plugwise/plugwise-beta#1078: Updates the plugwise package dependency in custom_components/plugwise/manifest.json, directly overlapping manifest configuration changes.
  • plugwise/plugwise-beta#958: Both PRs modify custom_components/plugwise/const.py constants; this PR adds DHW_MODE while that PR manages zone-profile selectors.

Suggested reviewers

  • CoMPaTech
🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly and specifically describes the main change: adding a water_heater platform for domestic hot water heating control.
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 docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch water_heater

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 June 7, 2026 12:18
@coderabbitai coderabbitai Bot added the enhancement New feature or request label Jun 7, 2026

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Actionable comments posted: 3

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

78-78: ⚡ Quick win

Remove redundant device_id attribute.

Line 78 stores self.device_id = device_id, but the parent PlugwiseEntity class already stores this value as self._dev_id (set in the super().init call on line 77). Line 116 then uses self.device_id, which could directly use self._dev_id instead.

♻️ Proposed fix to use inherited _dev_id
     def __init__(
         self,
         coordinator: PlugwiseDataUpdateCoordinator,
         device_id: str,
     ) -> None:
         """Initialise the water_heater."""
         super().__init__(coordinator, device_id)
-        self.device_id = device_id
         self._attr_unique_id = f"{device_id}-water_heater"

Then update line 116:

-        await self.coordinator.api.set_number(self.device_id, MAX_DHW_TEMP, temperature)
+        await self.coordinator.api.set_number(self._dev_id, MAX_DHW_TEMP, temperature)
🤖 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/water_heater.py` at line 78, Remove the redundant
self.device_id assignment in the water_heater constructor and use the inherited
identifier stored on the parent PlugwiseEntity as self._dev_id instead; delete
the line that sets self.device_id = device_id and replace any subsequent uses of
self.device_id (e.g., where referenced on line 116) with self._dev_id so the
class relies on the parent-stored device id.
🤖 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/water_heater.py`:
- Around line 90-98: The current_operation property returns STATE_ON/STATE_OFF
based on self.device.get(BINARY_SENSORS, {}).get("dhw_state"), which mismatches
the component's operation_list ["heat","off"]; update current_operation (in
water_heater.py) to return MODE_HEAT when dhw_state is truthy and MODE_OFF when
falsy (use MODE_HEAT and MODE_OFF constants instead of STATE_ON/STATE_OFF) so
the returned operation values match the operation_list.
- Line 55: The current conditional in water_heater.py uses DEV_CLASS ==
"heater_central" plus checking BINARY_SENSORS.dhw_state, which causes DHW
entities to be skipped for heater_central fixtures that simply lack that key;
either (A) update the fixture/mapping data for the specific devices so they
expose binary_sensors.dhw_state if they truly support DHW, or (B) change the
code to stop assuming all heater_central devices are DHW-capable and instead
rely solely on the presence of dhw_state (replace the condition
"device[DEV_CLASS] == 'heater_central' and device.get(BINARY_SENSORS,
{}).get('dhw_state') is not None" with a check that only tests
device.get(BINARY_SENSORS, {}).get('dhw_state') is not None), ensuring DHW
entities are created only when dhw_state exists.

In `@tests/components/plugwise/snapshots/test_water_heater.ambr`:
- Line 126: The snapshot shows operation_mode='on' because the water_heater's
current_operation property is returning the wrong value; update the
current_operation property in custom_components/plugwise/water_heater.py to
consult the device's operation_list and dhw_state (or dhw_active) and return the
matching operation string (e.g., 'heat' when dhw_state is true) instead of 'on'
or a hardcoded value; ensure the property uses the same identifiers used
elsewhere (operation_list, dhw_state/current_dhw_state) and falls back safely if
the expected operation is not present, then regenerate the failing snapshot
test.

---

Nitpick comments:
In `@custom_components/plugwise/water_heater.py`:
- Line 78: Remove the redundant self.device_id assignment in the water_heater
constructor and use the inherited identifier stored on the parent PlugwiseEntity
as self._dev_id instead; delete the line that sets self.device_id = device_id
and replace any subsequent uses of self.device_id (e.g., where referenced on
line 116) with self._dev_id so the class relies on the parent-stored device id.
🪄 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: c08a6d55-857c-4383-88c8-b0e63557a0e1

📥 Commits

Reviewing files that changed from the base of the PR and between 698972a and 380307f.

📒 Files selected for processing (20)
  • custom_components/plugwise/const.py
  • custom_components/plugwise/coordinator.py
  • custom_components/plugwise/number.py
  • custom_components/plugwise/translations/en.json
  • custom_components/plugwise/water_heater.py
  • tests/components/plugwise/conftest.py
  • tests/components/plugwise/fixtures/anna_v4_dhw/data.json
  • tests/components/plugwise/snapshots/test_number.ambr
  • tests/components/plugwise/snapshots/test_water_heater.ambr
  • tests/components/plugwise/test_binary_sensor.py
  • tests/components/plugwise/test_button.py
  • tests/components/plugwise/test_climate.py
  • tests/components/plugwise/test_config_flow.py
  • tests/components/plugwise/test_diagnostics.py
  • tests/components/plugwise/test_init.py
  • tests/components/plugwise/test_number.py
  • tests/components/plugwise/test_select.py
  • tests/components/plugwise/test_sensor.py
  • tests/components/plugwise/test_switch.py
  • tests/components/plugwise/test_water_heater.py
💤 Files with no reviewable changes (2)
  • custom_components/plugwise/number.py
  • tests/components/plugwise/snapshots/test_number.ambr

Comment thread custom_components/plugwise/water_heater.py Outdated
Comment thread custom_components/plugwise/water_heater.py
Comment thread tests/components/plugwise/snapshots/test_water_heater.ambr Outdated
@coderabbitai coderabbitai Bot added the require-dev-pass Require actions to pass against HA dev-branch (and silently fail on HA master-branch) label Jun 7, 2026

@github-actions github-actions Bot left a comment

Copy link
Copy Markdown

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.

@github-actions github-actions Bot left a comment

Copy link
Copy Markdown

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:

Error: Incompatible while testing against dev HA-core and required to pass.
✔️ Success: No problem with testing against released HA-core.

@github-actions github-actions Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

⚠️ Warning while testing for RELEASED HA-core:

✔️ Success: No problem with testing against dev HA-core.
✔️ Success: No problem with testing against released HA-core.

@bouwew bouwew force-pushed the water_heater branch 2 times, most recently from 8c219bc to 2e4983f Compare June 14, 2026 10:13

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🤖 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/translations/nl.json`:
- Around line 301-310: The water_heater object in the translations/nl.json file
is missing a closing brace. After the "state" object closes with its closing
brace (following the "off": "Uit" line), add another closing brace `}` with
proper indentation to properly close the "water_heater" object before the comma
that precedes the "exceptions" object. This will fix the malformed JSON
structure.
🪄 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: ee0cf205-fd55-45ff-9146-652fb05b3295

📥 Commits

Reviewing files that changed from the base of the PR and between c425ba4 and 8c219bc.

📒 Files selected for processing (23)
  • custom_components/plugwise/const.py
  • custom_components/plugwise/manifest.json
  • custom_components/plugwise/number.py
  • custom_components/plugwise/strings.json
  • custom_components/plugwise/switch.py
  • custom_components/plugwise/translations/en.json
  • custom_components/plugwise/translations/nl.json
  • custom_components/plugwise/water_heater.py
  • tests/components/plugwise/fixtures/adam_plus_anna_new/data.json
  • tests/components/plugwise/fixtures/anna_heatpump_heating/data.json
  • tests/components/plugwise/fixtures/anna_p1/data.json
  • tests/components/plugwise/fixtures/anna_v4/data.json
  • tests/components/plugwise/fixtures/anna_v4_dhw/data.json
  • tests/components/plugwise/fixtures/m_adam_cooling/data.json
  • tests/components/plugwise/fixtures/m_adam_heating/data.json
  • tests/components/plugwise/fixtures/m_adam_heating_off_schedule/data.json
  • tests/components/plugwise/fixtures/m_adam_jip/data.json
  • tests/components/plugwise/fixtures/m_anna_heatpump_cooling/data.json
  • tests/components/plugwise/snapshots/test_number.ambr
  • tests/components/plugwise/snapshots/test_select.ambr
  • tests/components/plugwise/snapshots/test_water_heater.ambr
  • tests/components/plugwise/test_number.py
  • tests/components/plugwise/test_water_heater.py
💤 Files with no reviewable changes (4)
  • custom_components/plugwise/number.py
  • custom_components/plugwise/switch.py
  • tests/components/plugwise/test_number.py
  • tests/components/plugwise/snapshots/test_number.ambr
✅ Files skipped from review due to trivial changes (4)
  • custom_components/plugwise/manifest.json
  • tests/components/plugwise/fixtures/adam_plus_anna_new/data.json
  • tests/components/plugwise/fixtures/m_adam_heating_off_schedule/data.json
  • tests/components/plugwise/snapshots/test_water_heater.ambr
🚧 Files skipped from review as they are similar to previous changes (3)
  • tests/components/plugwise/fixtures/anna_v4_dhw/data.json
  • custom_components/plugwise/const.py
  • tests/components/plugwise/test_water_heater.py

Comment thread custom_components/plugwise/translations/nl.json
@sonarqubecloud

Copy link
Copy Markdown

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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

75-78: ⚡ Quick win

Remove redundant None check after .get() with default.

Line 75 uses .get(MAX_DHW_TEMP, {}) which returns an empty dict if the key is missing, so max_dhw_temp_bounds can never be None. Either remove the if check on line 76 or change line 75 to .get(MAX_DHW_TEMP) (no default) if you need to handle the missing-key case.

♻️ Proposed fix
-        max_dhw_temp_bounds = self.device.get(MAX_DHW_TEMP, {})
-        if max_dhw_temp_bounds is not None:
+        if (max_dhw_temp_bounds := self.device.get(MAX_DHW_TEMP)) is not None:
             self._attr_max_temp = max_dhw_temp_bounds.get(UPPER_BOUND, 75.0)
             self._attr_min_temp = max_dhw_temp_bounds.get(LOWER_BOUND, 40.0)
🤖 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/water_heater.py` around lines 75 - 78, The None
check on line 76 is redundant because the `.get(MAX_DHW_TEMP, {})` call on line
75 returns an empty dictionary as the default value, never None. Remove the `if
max_dhw_temp_bounds is not None:` condition and unindent the two assignment
statements for `_attr_max_temp` and `_attr_min_temp` so they always execute.
This simplifies the code since the dictionary is guaranteed to exist (either
populated or empty).
🤖 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.

Nitpick comments:
In `@custom_components/plugwise/water_heater.py`:
- Around line 75-78: The None check on line 76 is redundant because the
`.get(MAX_DHW_TEMP, {})` call on line 75 returns an empty dictionary as the
default value, never None. Remove the `if max_dhw_temp_bounds is not None:`
condition and unindent the two assignment statements for `_attr_max_temp` and
`_attr_min_temp` so they always execute. This simplifies the code since the
dictionary is guaranteed to exist (either populated or empty).

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 352c02ab-f84c-454b-8d84-43450b48b9b0

📥 Commits

Reviewing files that changed from the base of the PR and between 8c219bc and ed21630.

📒 Files selected for processing (23)
  • custom_components/plugwise/const.py
  • custom_components/plugwise/manifest.json
  • custom_components/plugwise/number.py
  • custom_components/plugwise/strings.json
  • custom_components/plugwise/switch.py
  • custom_components/plugwise/translations/en.json
  • custom_components/plugwise/translations/nl.json
  • custom_components/plugwise/water_heater.py
  • tests/components/plugwise/fixtures/adam_plus_anna_new/data.json
  • tests/components/plugwise/fixtures/anna_heatpump_heating/data.json
  • tests/components/plugwise/fixtures/anna_p1/data.json
  • tests/components/plugwise/fixtures/anna_v4/data.json
  • tests/components/plugwise/fixtures/anna_v4_dhw/data.json
  • tests/components/plugwise/fixtures/m_adam_cooling/data.json
  • tests/components/plugwise/fixtures/m_adam_heating/data.json
  • tests/components/plugwise/fixtures/m_adam_heating_off_schedule/data.json
  • tests/components/plugwise/fixtures/m_adam_jip/data.json
  • tests/components/plugwise/fixtures/m_anna_heatpump_cooling/data.json
  • tests/components/plugwise/snapshots/test_number.ambr
  • tests/components/plugwise/snapshots/test_select.ambr
  • tests/components/plugwise/snapshots/test_water_heater.ambr
  • tests/components/plugwise/test_number.py
  • tests/components/plugwise/test_water_heater.py
💤 Files with no reviewable changes (4)
  • tests/components/plugwise/test_number.py
  • tests/components/plugwise/snapshots/test_number.ambr
  • custom_components/plugwise/switch.py
  • custom_components/plugwise/number.py
✅ Files skipped from review due to trivial changes (2)
  • tests/components/plugwise/fixtures/m_adam_heating/data.json
  • tests/components/plugwise/snapshots/test_water_heater.ambr
🚧 Files skipped from review as they are similar to previous changes (14)
  • custom_components/plugwise/strings.json
  • tests/components/plugwise/fixtures/anna_p1/data.json
  • tests/components/plugwise/fixtures/anna_v4_dhw/data.json
  • tests/components/plugwise/fixtures/anna_v4/data.json
  • custom_components/plugwise/translations/nl.json
  • tests/components/plugwise/fixtures/adam_plus_anna_new/data.json
  • custom_components/plugwise/manifest.json
  • tests/components/plugwise/fixtures/m_adam_heating_off_schedule/data.json
  • tests/components/plugwise/fixtures/anna_heatpump_heating/data.json
  • tests/components/plugwise/snapshots/test_select.ambr
  • custom_components/plugwise/translations/en.json
  • tests/components/plugwise/test_water_heater.py
  • tests/components/plugwise/fixtures/m_adam_cooling/data.json
  • tests/components/plugwise/fixtures/m_anna_heatpump_cooling/data.json

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request require-dev-pass Require actions to pass against HA dev-branch (and silently fail on HA master-branch)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant