Home Assistant Unofficial Reference 2024.12.1
hitachi_dhw.py
Go to the documentation of this file.
1 """Support for Hitachi DHW."""
2 
3 from __future__ import annotations
4 
5 from typing import Any
6 
7 from pyoverkiz.enums import OverkizCommand, OverkizCommandParam, OverkizState
8 
10  STATE_HIGH_DEMAND,
11  WaterHeaterEntity,
12  WaterHeaterEntityFeature,
13 )
14 from homeassistant.const import (
15  ATTR_TEMPERATURE,
16  PRECISION_WHOLE,
17  STATE_OFF,
18  STATE_ON,
19  UnitOfTemperature,
20 )
21 
22 from ..entity import OverkizEntity
23 
24 OVERKIZ_TO_OPERATION_MODE: dict[str, str] = {
25  OverkizCommandParam.STANDARD: STATE_ON,
26  OverkizCommandParam.HIGH_DEMAND: STATE_HIGH_DEMAND,
27  OverkizCommandParam.STOP: STATE_OFF,
28 }
29 
30 OPERATION_MODE_TO_OVERKIZ = {v: k for k, v in OVERKIZ_TO_OPERATION_MODE.items()}
31 
32 
34  """Representation of Hitachi DHW."""
35 
36  _attr_min_temp = 30.0
37  _attr_max_temp = 70.0
38  _attr_precision = PRECISION_WHOLE
39 
40  _attr_temperature_unit = UnitOfTemperature.CELSIUS
41  _attr_supported_features = (
42  WaterHeaterEntityFeature.TARGET_TEMPERATURE
43  | WaterHeaterEntityFeature.OPERATION_MODE
44  )
45  _attr_operation_list = [*OPERATION_MODE_TO_OVERKIZ]
46 
47  @property
48  def current_temperature(self) -> float | None:
49  """Return the current temperature."""
50  current_temperature = self.devicedevice.states[OverkizState.CORE_DHW_TEMPERATURE]
51  if current_temperature:
52  return current_temperature.value_as_float
53  return None
54 
55  @property
56  def target_temperature(self) -> float | None:
57  """Return the temperature we try to reach."""
58  target_temperature = self.devicedevice.states[
59  OverkizState.MODBUS_CONTROL_DHW_SETTING_TEMPERATURE
60  ]
61  if target_temperature:
62  return target_temperature.value_as_float
63  return None
64 
65  async def async_set_temperature(self, **kwargs: Any) -> None:
66  """Set new target temperature."""
67 
68  await self.executorexecutor.async_execute_command(
69  OverkizCommand.SET_CONTROL_DHW_SETTING_TEMPERATURE,
70  int(kwargs[ATTR_TEMPERATURE]),
71  )
72 
73  @property
74  def current_operation(self) -> str | None:
75  """Return current operation ie. eco, electric, performance, ..."""
76  modbus_control = self.devicedevice.states[OverkizState.MODBUS_CONTROL_DHW]
77  if modbus_control and modbus_control.value_as_str == OverkizCommandParam.STOP:
78  return STATE_OFF
79 
80  current_mode = self.devicedevice.states[OverkizState.MODBUS_DHW_MODE]
81  if current_mode and current_mode.value_as_str in OVERKIZ_TO_OPERATION_MODE:
82  return OVERKIZ_TO_OPERATION_MODE[current_mode.value_as_str]
83 
84  return None
85 
86  async def async_set_operation_mode(self, operation_mode: str) -> None:
87  """Set new target operation mode."""
88  # Turn water heater off
89  if operation_mode == OverkizCommandParam.OFF:
90  await self.executorexecutor.async_execute_command(
91  OverkizCommand.SET_CONTROL_DHW, OverkizCommandParam.STOP
92  )
93  return
94 
95  # Turn water heater on, when off
96  if self.current_operationcurrent_operationcurrent_operationcurrent_operation == OverkizCommandParam.OFF:
97  await self.executorexecutor.async_execute_command(
98  OverkizCommand.SET_CONTROL_DHW, OverkizCommandParam.ON
99  )
100 
101  # Change operation mode
102  await self.executorexecutor.async_execute_command(
103  OverkizCommand.SET_DHW_MODE, OPERATION_MODE_TO_OVERKIZ[operation_mode]
104  )