-
Notifications
You must be signed in to change notification settings - Fork 8
Add water_heater platform to cover domestic_hot_water heating #1085
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Draft
bouwew
wants to merge
49
commits into
main
Choose a base branch
from
water_heater
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from all commits
Commits
Show all changes
49 commits
Select commit
Hold shift + click to select a range
f7bddbb
Implement water_heater platform for DHW function
bouwew 6d56366
Ruffed
bouwew 367cbb2
Add test_water_heater.py
bouwew 88d261f
Improve water_heater and supported_features detection
bouwew baada33
Correct mocked_adam to fixture with water_heater
bouwew ca9842f
Fixes
bouwew 38a476d
Save new test_water_heater snapshot
bouwew c23e788
Add anna_v4_dhw fixture
bouwew d1f5714
Add 2nd water_heater testcase
bouwew 90b23bc
Save updates: snapshot, ruffed
bouwew 84a31e3
Update related test asserts
bouwew 81bebfd
Add water_heater async_set_temperature()
bouwew 4b57714
Add test case
bouwew 9434959
Add missing import
bouwew 18ed93c
Ruffed
bouwew e620c6e
Number: remove max_dhw-temperature, handled by water_heater
bouwew cca185e
Revert assert update after remove double number entity
bouwew b728755
Save updated number snapshot
bouwew 4b7f07c
hass -> _hass
bouwew 59576b8
Correct current_operation modes, as suggested
bouwew d8aa416
Re-ruffed
bouwew 0647495
Improve, as suggested
bouwew fe2269a
Change modes, add set_operation_mode(), and more
bouwew 7f2085a
Correct W0237
bouwew 970a013
Save snapshot updates
bouwew 34c158d
Tighten water_heater criterium
bouwew d31e3dd
Adapt async_set_operation_mode() to backend update
bouwew 538aed7
Call set_dwh_mode() directly
bouwew 5cdbede
Link to updated library
bouwew 08ed08a
Refresh test-fixtures
bouwew 70cddf2
Remove dhw_cm_switch, function moved to water_heater platform
bouwew 1e34876
Save updated select snapshot
bouwew 734cb74
Cleaning up
bouwew 16c2ebb
Simplify, remove logging, add pragma-no cover
bouwew dc5d527
Add set_operation_mode test
bouwew e9ffdb0
Revert LOGGER removal
bouwew 6080c8a
Update current_operation property
bouwew d5cc98c
Collect operation_list from device
bouwew c6a29cb
Fix test
bouwew 71bd824
Fix water_heater typing
bouwew 4115ebd
Save updated test snapshot
bouwew 59ea17a
Update strings.json, translations
bouwew e0a37f2
Prettier fixes
bouwew 14e8479
Rework water_heater strings
bouwew f1f0306
Pass length of operation_list to determine set-method
bouwew 6e5d5c8
Fix set_dhw_mode() args
bouwew 4f6b6bc
Fix test assert
bouwew 5ba1e83
Add pragma-no-cover
bouwew ed21630
Replace strings by constants
bouwew File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,118 @@ | ||
| """Plugwise water heater component for HomeAssistant.""" | ||
|
|
||
| from typing import Any | ||
|
|
||
| from homeassistant.components.water_heater import ( | ||
| WaterHeaterEntity, | ||
| WaterHeaterEntityFeature, | ||
| ) | ||
| from homeassistant.const import ( | ||
| ATTR_NAME, | ||
| ATTR_TEMPERATURE, | ||
| STATE_OFF, | ||
| UnitOfTemperature, | ||
| ) | ||
| from homeassistant.core import HomeAssistant, callback | ||
| from homeassistant.helpers.entity_platform import AddConfigEntryEntitiesCallback | ||
|
|
||
| from .const import ( | ||
| DHW_MODE, | ||
| DHW_MODES, | ||
| DHW_SETPOINT, | ||
| LOGGER, | ||
| LOWER_BOUND, | ||
| MAX_DHW_TEMP, | ||
| SENSORS, | ||
| TARGET_TEMP, | ||
| UPPER_BOUND, | ||
| ) | ||
| from .coordinator import PlugwiseConfigEntry, PlugwiseDataUpdateCoordinator | ||
| from .entity import PlugwiseEntity | ||
| from .util import plugwise_command | ||
|
|
||
|
|
||
| async def async_setup_entry( | ||
|
Check warning on line 34 in custom_components/plugwise/water_heater.py
|
||
| _hass: HomeAssistant, | ||
| entry: PlugwiseConfigEntry, | ||
| async_add_entities: AddConfigEntryEntitiesCallback, | ||
| ) -> None: | ||
| """Set up Plugwise water_heater from a config entry.""" | ||
| coordinator = entry.runtime_data | ||
|
|
||
| @callback | ||
| def _add_entities() -> None: | ||
| """Add Entities.""" | ||
| if not coordinator.new_devices: | ||
| return | ||
|
|
||
| entities: list[PlugwiseWaterHeaterEntity] = [] | ||
| for device_id in coordinator.new_devices: | ||
| device = coordinator.data[device_id] | ||
| if device.get(MAX_DHW_TEMP) is not None: | ||
| entities.append(PlugwiseWaterHeaterEntity(coordinator, device_id)) | ||
| LOGGER.debug("Add %s water_heater", device[ATTR_NAME]) | ||
| async_add_entities(entities) | ||
|
|
||
| _add_entities() | ||
| entry.async_on_unload(coordinator.async_add_listener(_add_entities)) | ||
|
|
||
|
|
||
| class PlugwiseWaterHeaterEntity(PlugwiseEntity, WaterHeaterEntity): | ||
| """Representation of a Plugwise water heater.""" | ||
|
|
||
| _attr_name = None | ||
| _attr_temperature_unit = UnitOfTemperature.CELSIUS | ||
|
|
||
| def __init__( | ||
| self, | ||
| coordinator: PlugwiseDataUpdateCoordinator, | ||
| device_id: str, | ||
| ) -> None: | ||
| """Initialise the water_heater.""" | ||
| super().__init__(coordinator, device_id) | ||
| self._attr_unique_id = f"{device_id}-water_heater" | ||
|
|
||
| max_dhw_temp_bounds = self.device.get(MAX_DHW_TEMP, {}) | ||
| if max_dhw_temp_bounds 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) | ||
| self._attr_supported_features = WaterHeaterEntityFeature.OPERATION_MODE | ||
| self._attr_supported_features |= WaterHeaterEntityFeature.TARGET_TEMPERATURE | ||
|
|
||
|
|
||
| @property | ||
| def current_operation(self) -> str | None: | ||
| """Return current readable operation mode.""" | ||
| return self.device.get(DHW_MODE) | ||
|
|
||
|
coderabbitai[bot] marked this conversation as resolved.
|
||
| @property | ||
| def current_temperature(self) -> float | None: | ||
| """Return the current water temperature.""" | ||
| return self.device.get(SENSORS, {}).get("water_temperature") | ||
|
|
||
| @property | ||
| def operation_list(self) -> list[str]: | ||
| """Return the list of available operation modes.""" | ||
| if (op_list := self.device.get(DHW_MODES, [])): | ||
| return op_list | ||
| return [STATE_OFF] # pragma: no cover | ||
|
|
||
| @property | ||
| def target_temperature(self) -> float | None: | ||
| """Return the water temperature we try to reach.""" | ||
| return ( | ||
| self.device.get(MAX_DHW_TEMP, {}).get(TARGET_TEMP) | ||
| or self.device.get(SENSORS, {}).get(DHW_SETPOINT) | ||
| ) | ||
|
|
||
| @plugwise_command | ||
| async def async_set_operation_mode(self, operation_mode: str) -> None: | ||
| """Set the operation mode.""" | ||
| list_type: int = len(self.operation_list) | ||
| await self.coordinator.api.set_dhw_mode(DHW_MODE, self._dev_id, list_type, operation_mode) | ||
|
|
||
| @plugwise_command | ||
| async def async_set_temperature(self, **kwargs: Any) -> None: | ||
| """Set new target temperature.""" | ||
| if (temperature := kwargs.get(ATTR_TEMPERATURE)) is not None: | ||
| await self.coordinator.api.set_number(self._dev_id, MAX_DHW_TEMP, float(temperature)) | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.