Add water_heater platform to cover domestic_hot_water heating#1085
Add water_heater platform to cover domestic_hot_water heating#1085bouwew wants to merge 49 commits into
Conversation
📝 WalkthroughWalkthroughThe 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. ChangesWater Heater Platform Implementation
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~25 minutes Possibly related PRs
Suggested reviewers
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
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. Comment |
There was a problem hiding this comment.
Actionable comments posted: 3
🧹 Nitpick comments (1)
custom_components/plugwise/water_heater.py (1)
78-78: ⚡ Quick winRemove redundant device_id attribute.
Line 78 stores
self.device_id = device_id, but the parentPlugwiseEntityclass already stores this value asself._dev_id(set in the super().init call on line 77). Line 116 then usesself.device_id, which could directly useself._dev_idinstead.♻️ 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
📒 Files selected for processing (20)
custom_components/plugwise/const.pycustom_components/plugwise/coordinator.pycustom_components/plugwise/number.pycustom_components/plugwise/translations/en.jsoncustom_components/plugwise/water_heater.pytests/components/plugwise/conftest.pytests/components/plugwise/fixtures/anna_v4_dhw/data.jsontests/components/plugwise/snapshots/test_number.ambrtests/components/plugwise/snapshots/test_water_heater.ambrtests/components/plugwise/test_binary_sensor.pytests/components/plugwise/test_button.pytests/components/plugwise/test_climate.pytests/components/plugwise/test_config_flow.pytests/components/plugwise/test_diagnostics.pytests/components/plugwise/test_init.pytests/components/plugwise/test_number.pytests/components/plugwise/test_select.pytests/components/plugwise/test_sensor.pytests/components/plugwise/test_switch.pytests/components/plugwise/test_water_heater.py
💤 Files with no reviewable changes (2)
- custom_components/plugwise/number.py
- tests/components/plugwise/snapshots/test_number.ambr
8c219bc to
2e4983f
Compare
There was a problem hiding this comment.
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
📒 Files selected for processing (23)
custom_components/plugwise/const.pycustom_components/plugwise/manifest.jsoncustom_components/plugwise/number.pycustom_components/plugwise/strings.jsoncustom_components/plugwise/switch.pycustom_components/plugwise/translations/en.jsoncustom_components/plugwise/translations/nl.jsoncustom_components/plugwise/water_heater.pytests/components/plugwise/fixtures/adam_plus_anna_new/data.jsontests/components/plugwise/fixtures/anna_heatpump_heating/data.jsontests/components/plugwise/fixtures/anna_p1/data.jsontests/components/plugwise/fixtures/anna_v4/data.jsontests/components/plugwise/fixtures/anna_v4_dhw/data.jsontests/components/plugwise/fixtures/m_adam_cooling/data.jsontests/components/plugwise/fixtures/m_adam_heating/data.jsontests/components/plugwise/fixtures/m_adam_heating_off_schedule/data.jsontests/components/plugwise/fixtures/m_adam_jip/data.jsontests/components/plugwise/fixtures/m_anna_heatpump_cooling/data.jsontests/components/plugwise/snapshots/test_number.ambrtests/components/plugwise/snapshots/test_select.ambrtests/components/plugwise/snapshots/test_water_heater.ambrtests/components/plugwise/test_number.pytests/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
|
There was a problem hiding this comment.
🧹 Nitpick comments (1)
custom_components/plugwise/water_heater.py (1)
75-78: ⚡ Quick winRemove redundant None check after
.get()with default.Line 75 uses
.get(MAX_DHW_TEMP, {})which returns an empty dict if the key is missing, somax_dhw_temp_boundscan never beNone. Either remove theifcheck 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
📒 Files selected for processing (23)
custom_components/plugwise/const.pycustom_components/plugwise/manifest.jsoncustom_components/plugwise/number.pycustom_components/plugwise/strings.jsoncustom_components/plugwise/switch.pycustom_components/plugwise/translations/en.jsoncustom_components/plugwise/translations/nl.jsoncustom_components/plugwise/water_heater.pytests/components/plugwise/fixtures/adam_plus_anna_new/data.jsontests/components/plugwise/fixtures/anna_heatpump_heating/data.jsontests/components/plugwise/fixtures/anna_p1/data.jsontests/components/plugwise/fixtures/anna_v4/data.jsontests/components/plugwise/fixtures/anna_v4_dhw/data.jsontests/components/plugwise/fixtures/m_adam_cooling/data.jsontests/components/plugwise/fixtures/m_adam_heating/data.jsontests/components/plugwise/fixtures/m_adam_heating_off_schedule/data.jsontests/components/plugwise/fixtures/m_adam_jip/data.jsontests/components/plugwise/fixtures/m_anna_heatpump_cooling/data.jsontests/components/plugwise/snapshots/test_number.ambrtests/components/plugwise/snapshots/test_select.ambrtests/components/plugwise/snapshots/test_water_heater.ambrtests/components/plugwise/test_number.pytests/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



Summary by CodeRabbit
Release Notes
New Features
Changes
Tests