1
0
mirror of https://github.com/home-assistant/core.git synced 2026-05-08 09:38:58 +01:00
Files
core/homeassistant/components/melcloud/water_heater.py
T
divers33 58ef925a07 Refactor MELCloud integration to use DataUpdateCoordinator (#160131)
Co-authored-by: divers33 <divers33@users.noreply.github.com>
Co-authored-by: Claude Opus 4.5 <noreply@anthropic.com>
Co-authored-by: Joostlek <joostlek@outlook.com>
2026-01-13 18:52:37 +01:00

126 lines
4.0 KiB
Python

"""Platform for water_heater integration."""
from __future__ import annotations
from typing import Any
from pymelcloud import DEVICE_TYPE_ATW, AtwDevice
from pymelcloud.atw_device import (
PROPERTY_OPERATION_MODE,
PROPERTY_TARGET_TANK_TEMPERATURE,
)
from pymelcloud.device import PROPERTY_POWER
from homeassistant.components.water_heater import (
DEFAULT_MAX_TEMP,
DEFAULT_MIN_TEMP,
WaterHeaterEntity,
WaterHeaterEntityFeature,
)
from homeassistant.const import UnitOfTemperature
from homeassistant.core import HomeAssistant
from homeassistant.helpers.entity_platform import AddConfigEntryEntitiesCallback
from .const import ATTR_STATUS
from .coordinator import MelCloudConfigEntry, MelCloudDeviceUpdateCoordinator
from .entity import MelCloudEntity
async def async_setup_entry(
_hass: HomeAssistant,
entry: MelCloudConfigEntry,
async_add_entities: AddConfigEntryEntitiesCallback,
) -> None:
"""Set up MelCloud device climate based on config_entry."""
coordinators = entry.runtime_data
async_add_entities(
[
AtwWaterHeater(coordinator, coordinator.device)
for coordinator in coordinators.get(DEVICE_TYPE_ATW, [])
]
)
class AtwWaterHeater(MelCloudEntity, WaterHeaterEntity):
"""Air-to-Water water heater."""
_attr_supported_features = (
WaterHeaterEntityFeature.TARGET_TEMPERATURE
| WaterHeaterEntityFeature.ON_OFF
| WaterHeaterEntityFeature.OPERATION_MODE
)
_attr_name = None
def __init__(
self,
coordinator: MelCloudDeviceUpdateCoordinator,
device: AtwDevice,
) -> None:
"""Initialize water heater device."""
super().__init__(coordinator)
self._device = device
self._attr_unique_id = coordinator.device.serial
self._attr_device_info = coordinator.device_info
async def async_turn_on(self, **_kwargs: Any) -> None:
"""Turn the entity on."""
await self.coordinator.async_set({PROPERTY_POWER: True})
async def async_turn_off(self, **_kwargs: Any) -> None:
"""Turn the entity off."""
await self.coordinator.async_set({PROPERTY_POWER: False})
@property
def extra_state_attributes(self) -> dict[str, Any] | None:
"""Return the optional state attributes with device specific additions."""
return {ATTR_STATUS: self._device.status}
@property
def temperature_unit(self) -> str:
"""Return the unit of measurement used by the platform."""
return UnitOfTemperature.CELSIUS
@property
def current_operation(self) -> str | None:
"""Return current operation as reported by pymelcloud."""
return self._device.operation_mode
@property
def operation_list(self) -> list[str]:
"""Return the list of available operation modes as reported by pymelcloud."""
return self._device.operation_modes
@property
def current_temperature(self) -> float | None:
"""Return the current temperature."""
return self._device.tank_temperature
@property
def target_temperature(self) -> float | None:
"""Return the temperature we try to reach."""
return self._device.target_tank_temperature
async def async_set_temperature(self, **kwargs: Any) -> None:
"""Set new target temperature."""
await self.coordinator.async_set(
{
PROPERTY_TARGET_TANK_TEMPERATURE: kwargs.get(
"temperature", self.target_temperature
)
}
)
async def async_set_operation_mode(self, operation_mode: str) -> None:
"""Set new target operation mode."""
await self.coordinator.async_set({PROPERTY_OPERATION_MODE: operation_mode})
@property
def min_temp(self) -> float:
"""Return the minimum temperature."""
return self._device.target_tank_temperature_min or DEFAULT_MIN_TEMP
@property
def max_temp(self) -> float:
"""Return the maximum temperature."""
return self._device.target_tank_temperature_max or DEFAULT_MAX_TEMP