Skip to content

Commit

Permalink
Add support for DomesticHotWaterProduction (#353)
Browse files Browse the repository at this point in the history
  • Loading branch information
iMicknl authored Jan 27, 2021
1 parent 9f7a880 commit c5fff0d
Show file tree
Hide file tree
Showing 3 changed files with 162 additions and 0 deletions.
2 changes: 2 additions & 0 deletions custom_components/tahoma/const.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
from homeassistant.components.lock import DOMAIN as LOCK
from homeassistant.components.sensor import DOMAIN as SENSOR
from homeassistant.components.switch import DOMAIN as SWITCH
from homeassistant.components.water_heater import DOMAIN as WATER_HEATER

CONF_HUB = "hub"
DOMAIN = "tahoma"
Expand Down Expand Up @@ -44,6 +45,7 @@
"ContactSensor": BINARY_SENSOR,
"Curtain": COVER,
"DimmerExteriorHeating": CLIMATE, # widgetName, uiClass is ExteriorHeatingSystem (not supported)
"DomesticHotWaterProduction": WATER_HEATER, # widgetName, uiClass is WaterHeatingSystem (not supported)
"DomesticHotWaterTank": SWITCH, # widgetName, uiClass is WaterHeatingSystem (not supported)
"DoorLock": LOCK,
"ElectricitySensor": SENSOR,
Expand Down
26 changes: 26 additions & 0 deletions custom_components/tahoma/water_heater.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
"""Support for TaHoma water heater devices."""
from homeassistant.components.water_heater import DOMAIN as WATER_HEATER

from .const import DOMAIN
from .water_heater_devices.domestic_hot_water_production import (
DomesticHotWaterProduction,
)

TYPE = {
"DomesticHotWaterProduction": DomesticHotWaterProduction,
}


async def async_setup_entry(hass, entry, async_add_entities):
"""Set up the TaHoma water heater from a config entry."""
data = hass.data[DOMAIN][entry.entry_id]
coordinator = data["coordinator"]

water_heater_devices = [device for device in data["entities"].get(WATER_HEATER)]

entities = [
TYPE[device.widget](device.deviceurl, coordinator)
for device in water_heater_devices
if device.widget in TYPE
]
async_add_entities(entities)
Original file line number Diff line number Diff line change
@@ -0,0 +1,134 @@
"""Support for DomesticHotWaterProduction."""
from homeassistant.components.climate.const import SUPPORT_TARGET_TEMPERATURE
from homeassistant.components.water_heater import (
STATE_ECO,
SUPPORT_AWAY_MODE,
SUPPORT_OPERATION_MODE,
WaterHeaterEntity,
)
from homeassistant.const import ATTR_TEMPERATURE, STATE_OFF, STATE_ON, TEMP_CELSIUS

from ..tahoma_device import TahomaDevice

CORE_MAXIMAL_TEMPERATURE_MANUAL_MODE_STATE = "core:MaximalTemperatureManualModeState"
CORE_MINIMAL_TEMPERATURE_MANUAL_MODE_STATE = "core:MinimalTemperatureManualModeState"
CORE_TARGET_TEMPERATURE_STATE = "core:TargetTemperatureState"
CORE_OPERATING_MODE_STATE = "core:OperatingModeState"

IO_DHW_MODE_STATE = "io:DHWModeState"
IO_MIDDLE_WATER_TEMPERATURE_STATE = "io:MiddleWaterTemperatureState"

STATE_MANUAL = "manual"
STATE_AUTO = "auto"
STATE_ABSENCE = "absence"
STATE_RELAUNCH = "relaunch"

COMMAND_SET_TARGET_TEMPERATURE = "setTargetTemperature"
COMMAND_SET_DHW_MODE = "setDHWMode"
COMMAND_SET_CURRENT_OPERATING_MODE = "setCurrentOperatingMode"

MODE_AUTO = "autoMode"
MODE_MANUAL_ECO_ACTIVE = "manualEcoActive"
MODE_MANUAL_ECO_INACTIVE = "manualEcoInactive"

MAP_OPERATION_MODES = {
MODE_MANUAL_ECO_ACTIVE: STATE_ECO,
MODE_MANUAL_ECO_INACTIVE: STATE_MANUAL,
MODE_AUTO: STATE_AUTO,
}

MAP_REVERSE_OPERATION_MODES = {v: k for k, v in MAP_OPERATION_MODES.items()}


class DomesticHotWaterProduction(TahomaDevice, WaterHeaterEntity):
"""Representation of a DomesticHotWaterProduction Water Heater."""

@property
def temperature_unit(self) -> str:
"""Return the unit of measurement used by the platform."""
return TEMP_CELSIUS

@property
def min_temp(self):
"""Return the minimum temperature."""
return self.select_state(CORE_MINIMAL_TEMPERATURE_MANUAL_MODE_STATE)

@property
def max_temp(self):
"""Return the maximum temperature."""
return self.select_state(CORE_MAXIMAL_TEMPERATURE_MANUAL_MODE_STATE)

@property
def current_operation(self):
"""Return current operation ie. eco, electric, performance, ..."""
return MAP_OPERATION_MODES[self.select_state(IO_DHW_MODE_STATE)]

@property
def operation_list(self):
"""Return the list of available operation modes."""
return [*MAP_REVERSE_OPERATION_MODES]

@property
def current_temperature(self):
"""Return the current temperature."""
return self.select_state(IO_MIDDLE_WATER_TEMPERATURE_STATE)

@property
def target_temperature(self):
"""Return the temperature we try to reach."""
return self.select_state(CORE_TARGET_TEMPERATURE_STATE)

@property
def target_temperature_high(self):
"""Return the highbound target temperature we try to reach."""
return self.select_state(CORE_MAXIMAL_TEMPERATURE_MANUAL_MODE_STATE)

@property
def target_temperature_low(self):
"""Return the lowbound target temperature we try to reach."""
return self.select_state(CORE_MINIMAL_TEMPERATURE_MANUAL_MODE_STATE)

async def async_set_temperature(self, **kwargs):
"""Set new target temperature."""
target_temperature = kwargs.get(ATTR_TEMPERATURE)
await self.async_execute_command(
COMMAND_SET_TARGET_TEMPERATURE, target_temperature
)

async def async_set_operation_mode(self, operation_mode):
"""Set new target operation mode."""
await self.async_execute_command(
COMMAND_SET_DHW_MODE, MAP_REVERSE_OPERATION_MODES[operation_mode]
)

@property
def supported_features(self):
"""Return the list of supported features."""
return SUPPORT_OPERATION_MODE | SUPPORT_AWAY_MODE | SUPPORT_TARGET_TEMPERATURE

@property
def is_away_mode_on(self):
"""Return true if away mode is on."""
return (
self.select_state(CORE_OPERATING_MODE_STATE).get(STATE_ABSENCE) == STATE_ON
)

async def async_turn_away_mode_on(self):
"""Turn away mode on."""
await self.async_execute_command(
COMMAND_SET_CURRENT_OPERATING_MODE,
{
STATE_RELAUNCH: STATE_OFF,
STATE_ABSENCE: STATE_ON,
},
)

async def async_turn_away_mode_off(self):
"""Turn away mode off."""
await self.async_execute_command(
COMMAND_SET_CURRENT_OPERATING_MODE,
{
STATE_RELAUNCH: STATE_OFF,
STATE_ABSENCE: STATE_OFF,
},
)

0 comments on commit c5fff0d

Please sign in to comment.