-
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
24
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
24 commits
Select commit
Hold shift + click to select a range
30f3a42
Implement water_heater platform for DHW function
bouwew c55595d
Ruffed
bouwew 3c4fae7
Add test_water_heater.py
bouwew c033fa0
Improve water_heater and supported_features detection
bouwew 015898a
Correct mocked_adam to fixture with water_heater
bouwew b63fa99
Fixes
bouwew 57fb144
Save new test_water_heater snapshot
bouwew deb9b16
Add anna_v4_dhw fixture
bouwew 7c64edc
Add 2nd water_heater testcase
bouwew c680b36
Save updates: snapshot, ruffed
bouwew fbbe906
Update related test asserts
bouwew a35f004
Add water_heater async_set_temperature()
bouwew 3c3ee48
Add test case
bouwew a063261
Add missing import
bouwew 6d2cf0b
Ruffed
bouwew a452dc7
Number: remove max_dhw-temperature, handled by water_heater
bouwew 2afef29
Revert assert update after remove double number entity
bouwew 1a061f4
Save updated number snapshot
bouwew 45236bc
hass -> _hass
bouwew 3762367
Correct current_operation modes, as suggested
bouwew 79a4bbc
Re-ruffed
bouwew fb7d486
Improve, as suggested
bouwew c425ba4
Change modes, add set_operation_mode(), and more
bouwew b64f79b
Correct W0237
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,134 @@ | ||
| """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, | ||
| STATE_ON, | ||
| UnitOfTemperature, | ||
| ) | ||
| from homeassistant.core import HomeAssistant, callback | ||
| from homeassistant.helpers.entity_platform import AddConfigEntryEntitiesCallback | ||
|
|
||
| from .const import ( | ||
| BINARY_SENSORS, | ||
| DEV_CLASS, | ||
| DHW_CM_SWITCH, | ||
| 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 | ||
|
|
||
| MODE_DHW_COMFORT = "Dhw comfort" | ||
| MODE_DHW_NORMAL = "Dhw normal" | ||
| OPERATION_MODES = [MODE_DHW_COMFORT, MODE_DHW_NORMAL] | ||
|
|
||
|
|
||
| async def async_setup_entry( | ||
|
Check warning on line 40 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[DEV_CLASS] == "heater_central" and device.get(BINARY_SENSORS, {}).get("dhw_state") 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_operation_list = OPERATION_MODES | ||
| _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" | ||
|
|
||
| self._attr_max_temp = self.device.get("max_dhw_temperature", {}).get(UPPER_BOUND, 75.0) | ||
| self._attr_min_temp = self.device.get("max_dhw_temperature", {}).get(LOWER_BOUND, 40.0) | ||
| self._attr_supported_features = WaterHeaterEntityFeature.OPERATION_MODE | ||
| self._supports_temperature_control = False | ||
| if self.device.get("max_dhw_temperature"): | ||
| self._attr_supported_features |= WaterHeaterEntityFeature.TARGET_TEMPERATURE | ||
| self._supports_temperature_control = True | ||
|
|
||
|
|
||
| @property | ||
| def current_operation(self) -> str | None: | ||
| """Return current readable operation mode.""" | ||
| if (state := self.device.get(BINARY_SENSORS, {}).get("dhw_state")) is not None: | ||
| if state: | ||
| return MODE_DHW_COMFORT | ||
| return MODE_DHW_NORMAL | ||
| return None | ||
|
|
||
|
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 target_temperature(self) -> float | None: | ||
| """Return the water temperature we try to reach.""" | ||
| return ( | ||
| self.device.get("max_dhw_temperature", {}).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.""" | ||
| state = STATE_ON if operation_mode == MODE_DHW_COMFORT else STATE_OFF | ||
| await self.coordinator.api.set_switch_state( | ||
| self._dev_id, | ||
| None, | ||
| DHW_CM_SWITCH, | ||
| state, | ||
| ) | ||
|
|
||
| @plugwise_command | ||
| async def async_set_temperature(self, **kwargs: Any) -> None: | ||
| """Set new target temperature.""" | ||
| temperature = kwargs.get(ATTR_TEMPERATURE) | ||
| if not self._supports_temperature_control or temperature is None: | ||
| return | ||
|
|
||
| await self.coordinator.api.set_number(self._dev_id, MAX_DHW_TEMP, temperature) | ||
| LOGGER.debug( | ||
| "Setting %s to %s was successful", MAX_DHW_TEMP, 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,98 @@ | ||
| { | ||
| "01b85360fdd243d0aaad4d6ac2a5ba7e": { | ||
| "active_preset": "home", | ||
| "available_schedules": [ | ||
| "Standaard", | ||
| "Thuiswerken", | ||
| "off" | ||
| ], | ||
| "climate_mode": "heat", | ||
| "control_state": "idle", | ||
| "dev_class": "thermostat", | ||
| "firmware": "2018-02-08T11:15:53+01:00", | ||
| "hardware": "6539-1301-5002", | ||
| "location": "eb5309212bf5407bb143e5bfa3b18aee", | ||
| "model": "ThermoTouch", | ||
| "name": "Anna", | ||
| "preset_modes": [ | ||
| "vacation", | ||
| "no_frost", | ||
| "away", | ||
| "asleep", | ||
| "home" | ||
| ], | ||
| "select_schedule": "off", | ||
| "sensors": { | ||
| "illuminance": 60.0, | ||
| "setpoint": 20.5, | ||
| "temperature": 20.6 | ||
| }, | ||
| "temperature_offset": { | ||
| "lower_bound": -2.0, | ||
| "resolution": 0.1, | ||
| "setpoint": 0.0, | ||
| "upper_bound": 2.0 | ||
| }, | ||
| "thermostat": { | ||
| "lower_bound": 4.0, | ||
| "resolution": 0.1, | ||
| "setpoint": 20.5, | ||
| "upper_bound": 30.0 | ||
| }, | ||
| "vendor": "Plugwise" | ||
| }, | ||
| "0466eae8520144c78afb29628384edeb": { | ||
| "binary_sensors": { | ||
| "plugwise_notification": false | ||
| }, | ||
| "dev_class": "gateway", | ||
| "firmware": "4.0.15", | ||
| "hardware": "AME Smile 2.0 board", | ||
| "location": "94c107dc6ac84ed98e9f68c0dd06bf71", | ||
| "mac_address": "012345670001", | ||
| "model": "Gateway", | ||
| "model_id": "smile_thermo", | ||
| "name": "Smile Anna", | ||
| "notifications": {}, | ||
| "sensors": { | ||
| "outdoor_temperature": 7.44 | ||
| }, | ||
| "vendor": "Plugwise" | ||
| }, | ||
| "cd0e6156b1f04d5f952349ffbe397481": { | ||
| "available": true, | ||
| "binary_sensors": { | ||
| "dhw_state": true, | ||
| "flame_state": true, | ||
| "heating_state": false | ||
| }, | ||
| "dev_class": "heater_central", | ||
| "location": "94c107dc6ac84ed98e9f68c0dd06bf71", | ||
| "max_dhw_temperature": { | ||
| "lower_bound": 30.0, | ||
| "resolution": 0.01, | ||
| "setpoint": 60.0, | ||
| "upper_bound": 60.0 | ||
| }, | ||
| "maximum_boiler_temperature": { | ||
| "lower_bound": 0.0, | ||
| "resolution": 1.0, | ||
| "setpoint": 70.0, | ||
| "upper_bound": 100.0 | ||
| }, | ||
| "model": "Generic heater", | ||
| "model_id": "2.32", | ||
| "name": "OpenTherm", | ||
| "sensors": { | ||
| "intended_boiler_temperature": 39.9, | ||
| "modulation_level": 0.0, | ||
| "return_temperature": 32.0, | ||
| "water_pressure": 2.2, | ||
| "water_temperature": 45.0 | ||
| }, | ||
| "switches": { | ||
| "dhw_cm_switch": false | ||
| }, | ||
| "vendor": "Bosch Thermotechniek B.V." | ||
| } | ||
| } |
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.