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