2019-07-12 19:29:45 +00:00
|
|
|
"""Support for WaterHeater devices of (EMEA/EU) Honeywell TCC systems."""
|
|
|
|
import logging
|
|
|
|
from typing import List
|
|
|
|
|
|
|
|
from homeassistant.components.water_heater import (
|
2019-07-31 19:25:30 +00:00
|
|
|
SUPPORT_OPERATION_MODE,
|
|
|
|
WaterHeaterDevice,
|
|
|
|
)
|
2019-07-12 19:29:45 +00:00
|
|
|
from homeassistant.const import PRECISION_WHOLE, STATE_OFF, STATE_ON
|
|
|
|
from homeassistant.util.dt import parse_datetime
|
|
|
|
|
2019-09-01 10:45:41 +00:00
|
|
|
from . import EvoDevice
|
2019-07-12 19:29:45 +00:00
|
|
|
from .const import DOMAIN, EVO_STRFTIME, EVO_FOLLOW, EVO_TEMPOVER, EVO_PERMOVER
|
|
|
|
|
|
|
|
_LOGGER = logging.getLogger(__name__)
|
|
|
|
|
2019-07-31 19:25:30 +00:00
|
|
|
HA_STATE_TO_EVO = {STATE_ON: "On", STATE_OFF: "Off"}
|
2019-07-12 19:29:45 +00:00
|
|
|
EVO_STATE_TO_HA = {v: k for k, v in HA_STATE_TO_EVO.items()}
|
|
|
|
|
|
|
|
HA_OPMODE_TO_DHW = {STATE_ON: EVO_FOLLOW, STATE_OFF: EVO_PERMOVER}
|
|
|
|
|
|
|
|
|
2019-09-01 10:45:41 +00:00
|
|
|
async def async_setup_platform(
|
|
|
|
hass, config, async_add_entities, discovery_info=None
|
|
|
|
) -> None:
|
2019-07-12 19:29:45 +00:00
|
|
|
"""Create the DHW controller."""
|
2019-09-01 10:45:41 +00:00
|
|
|
if discovery_info is None:
|
|
|
|
return
|
|
|
|
|
2019-07-31 19:25:30 +00:00
|
|
|
broker = hass.data[DOMAIN]["broker"]
|
2019-07-12 19:29:45 +00:00
|
|
|
|
|
|
|
_LOGGER.debug(
|
2019-07-31 19:25:30 +00:00
|
|
|
"Found %s, id: %s", broker.tcs.hotwater.zone_type, broker.tcs.hotwater.zoneId
|
|
|
|
)
|
2019-07-12 19:29:45 +00:00
|
|
|
|
|
|
|
evo_dhw = EvoDHW(broker, broker.tcs.hotwater)
|
|
|
|
|
2019-09-01 10:45:41 +00:00
|
|
|
async_add_entities([evo_dhw], update_before_add=True)
|
2019-07-12 19:29:45 +00:00
|
|
|
|
|
|
|
|
|
|
|
class EvoDHW(EvoDevice, WaterHeaterDevice):
|
|
|
|
"""Base for a Honeywell evohome DHW controller (aka boiler)."""
|
|
|
|
|
|
|
|
def __init__(self, evo_broker, evo_device) -> None:
|
|
|
|
"""Initialize the evohome DHW controller."""
|
|
|
|
super().__init__(evo_broker, evo_device)
|
|
|
|
|
2019-07-31 19:25:30 +00:00
|
|
|
self._name = "DHW controller"
|
|
|
|
self._icon = "mdi:thermometer-lines"
|
2019-07-12 19:29:45 +00:00
|
|
|
|
|
|
|
self._precision = PRECISION_WHOLE
|
|
|
|
self._state_attributes = [
|
2019-07-31 19:25:30 +00:00
|
|
|
"dhwId",
|
|
|
|
"activeFaults",
|
|
|
|
"stateStatus",
|
|
|
|
"temperatureStatus",
|
|
|
|
"setpoints",
|
|
|
|
]
|
2019-07-12 19:29:45 +00:00
|
|
|
|
|
|
|
self._supported_features = SUPPORT_OPERATION_MODE
|
|
|
|
self._operation_list = list(HA_OPMODE_TO_DHW)
|
|
|
|
|
2019-09-01 10:45:41 +00:00
|
|
|
@property
|
|
|
|
def available(self) -> bool:
|
|
|
|
"""Return True if entity is available."""
|
|
|
|
return self._evo_device.temperatureStatus.get("isAvailable", False)
|
|
|
|
|
2019-07-12 19:29:45 +00:00
|
|
|
@property
|
|
|
|
def current_operation(self) -> str:
|
|
|
|
"""Return the current operating mode (On, or Off)."""
|
2019-07-31 19:25:30 +00:00
|
|
|
return EVO_STATE_TO_HA[self._evo_device.stateStatus["state"]]
|
2019-07-12 19:29:45 +00:00
|
|
|
|
|
|
|
@property
|
|
|
|
def operation_list(self) -> List[str]:
|
|
|
|
"""Return the list of available operations."""
|
|
|
|
return self._operation_list
|
|
|
|
|
|
|
|
@property
|
|
|
|
def current_temperature(self) -> float:
|
|
|
|
"""Return the current temperature."""
|
2019-07-31 19:25:30 +00:00
|
|
|
return self._evo_device.temperatureStatus["temperature"]
|
2019-07-12 19:29:45 +00:00
|
|
|
|
2019-09-01 10:45:41 +00:00
|
|
|
async def async_set_operation_mode(self, operation_mode: str) -> None:
|
2019-07-12 19:29:45 +00:00
|
|
|
"""Set new operation mode for a DHW controller."""
|
|
|
|
op_mode = HA_OPMODE_TO_DHW[operation_mode]
|
|
|
|
|
2019-07-31 19:25:30 +00:00
|
|
|
state = "" if op_mode == EVO_FOLLOW else HA_STATE_TO_EVO[STATE_OFF]
|
2019-07-12 19:29:45 +00:00
|
|
|
until = None # EVO_FOLLOW, EVO_PERMOVER
|
|
|
|
|
2019-07-31 19:25:30 +00:00
|
|
|
if op_mode == EVO_TEMPOVER and self._schedule["DailySchedules"]:
|
2019-09-01 10:45:41 +00:00
|
|
|
await self._update_schedule()
|
2019-07-31 19:25:30 +00:00
|
|
|
if self._schedule["DailySchedules"]:
|
|
|
|
until = parse_datetime(self.setpoints["next"]["from"])
|
2019-07-12 19:29:45 +00:00
|
|
|
until = until.strftime(EVO_STRFTIME)
|
|
|
|
|
2019-07-31 19:25:30 +00:00
|
|
|
data = {"Mode": op_mode, "State": state, "UntilTime": until}
|
2019-07-12 19:29:45 +00:00
|
|
|
|
2019-09-01 10:45:41 +00:00
|
|
|
await self._call_client_api(
|
2019-07-12 19:29:45 +00:00
|
|
|
self._evo_device._set_dhw(data) # pylint: disable=protected-access
|
2019-09-01 10:45:41 +00:00
|
|
|
)
|