Home Assistant Unofficial Reference 2024.12.1
water_heater.py
Go to the documentation of this file.
1 """Platform for water_heater integration."""
2 
3 from __future__ import annotations
4 
5 from typing import Any
6 
7 from pymelcloud import DEVICE_TYPE_ATW, AtwDevice
8 from pymelcloud.atw_device import (
9  PROPERTY_OPERATION_MODE,
10  PROPERTY_TARGET_TANK_TEMPERATURE,
11 )
12 from pymelcloud.device import PROPERTY_POWER
13 
15  DEFAULT_MAX_TEMP,
16  DEFAULT_MIN_TEMP,
17  WaterHeaterEntity,
18  WaterHeaterEntityFeature,
19 )
20 from homeassistant.config_entries import ConfigEntry
21 from homeassistant.const import UnitOfTemperature
22 from homeassistant.core import HomeAssistant
23 from homeassistant.helpers.entity_platform import AddEntitiesCallback
24 
25 from . import DOMAIN, MelCloudDevice
26 from .const import ATTR_STATUS
27 
28 
30  hass: HomeAssistant, entry: ConfigEntry, async_add_entities: AddEntitiesCallback
31 ) -> None:
32  """Set up MelCloud device climate based on config_entry."""
33  mel_devices = hass.data[DOMAIN][entry.entry_id]
35  [
36  AtwWaterHeater(mel_device, mel_device.device)
37  for mel_device in mel_devices[DEVICE_TYPE_ATW]
38  ],
39  True,
40  )
41 
42 
44  """Air-to-Water water heater."""
45 
46  _attr_supported_features = (
47  WaterHeaterEntityFeature.TARGET_TEMPERATURE
48  | WaterHeaterEntityFeature.ON_OFF
49  | WaterHeaterEntityFeature.OPERATION_MODE
50  )
51  _attr_has_entity_name = True
52  _attr_name = None
53 
54  def __init__(self, api: MelCloudDevice, device: AtwDevice) -> None:
55  """Initialize water heater device."""
56  self._api_api = api
57  self._device_device = device
58  self._attr_unique_id_attr_unique_id = api.device.serial
59  self._attr_device_info_attr_device_info = api.device_info
60 
61  async def async_update(self) -> None:
62  """Update state from MELCloud."""
63  await self._api_api.async_update()
64 
65  async def async_turn_on(self, **kwargs: Any) -> None:
66  """Turn the entity on."""
67  await self._device_device.set({PROPERTY_POWER: True})
68 
69  async def async_turn_off(self, **kwargs: Any) -> None:
70  """Turn the entity off."""
71  await self._device_device.set({PROPERTY_POWER: False})
72 
73  @property
74  def extra_state_attributes(self) -> dict[str, Any] | None:
75  """Return the optional state attributes with device specific additions."""
76  return {ATTR_STATUS: self._device_device.status}
77 
78  @property
79  def temperature_unit(self) -> str:
80  """Return the unit of measurement used by the platform."""
81  return UnitOfTemperature.CELSIUS
82 
83  @property
84  def current_operation(self) -> str | None:
85  """Return current operation as reported by pymelcloud."""
86  return self._device_device.operation_mode
87 
88  @property
89  def operation_list(self) -> list[str]:
90  """Return the list of available operation modes as reported by pymelcloud."""
91  return self._device_device.operation_modes
92 
93  @property
94  def current_temperature(self) -> float | None:
95  """Return the current temperature."""
96  return self._device_device.tank_temperature
97 
98  @property
99  def target_temperature(self) -> float | None:
100  """Return the temperature we try to reach."""
101  return self._device_device.target_tank_temperature
102 
103  async def async_set_temperature(self, **kwargs: Any) -> None:
104  """Set new target temperature."""
105  await self._device_device.set(
106  {
107  PROPERTY_TARGET_TANK_TEMPERATURE: kwargs.get(
108  "temperature", self.target_temperaturetarget_temperaturetarget_temperature
109  )
110  }
111  )
112 
113  async def async_set_operation_mode(self, operation_mode: str) -> None:
114  """Set new target operation mode."""
115  await self._device_device.set({PROPERTY_OPERATION_MODE: operation_mode})
116 
117  @property
118  def min_temp(self) -> float:
119  """Return the minimum temperature."""
120  return self._device_device.target_tank_temperature_min or DEFAULT_MIN_TEMP
121 
122  @property
123  def max_temp(self) -> float:
124  """Return the maximum temperature."""
125  return self._device_device.target_tank_temperature_max or DEFAULT_MAX_TEMP
None __init__(self, MelCloudDevice api, AtwDevice device)
Definition: water_heater.py:54
None async_setup_entry(HomeAssistant hass, ConfigEntry entry, AddEntitiesCallback async_add_entities)
Definition: water_heater.py:31