From 317bd8ffd21a28c9d0a9a0c162309d60228433f2 Mon Sep 17 00:00:00 2001 From: Mikkel Pilehave Jensen Date: Wed, 8 Jul 2020 21:33:27 +0200 Subject: [PATCH] Add preset modes to Touchline (#36054) * Added preset modes. * Flake8 passed. * New and cleaner version. * isort fixed? * OrderedDict removed, constant OPERATION_LIST removed. * ClimateDevice changed to ClimateEntity * Two methods replaced with constants. * Update homeassistant/components/touchline/climate.py Co-authored-by: Martin Hjelmare * Update homeassistant/components/touchline/climate.py Co-authored-by: Martin Hjelmare * Update homeassistant/components/touchline/climate.py Co-authored-by: Martin Hjelmare * All changes needed. * Cleaned up * Clean up Co-authored-by: Martin Hjelmare --- homeassistant/components/touchline/climate.py | 59 +++++++++++++++---- 1 file changed, 47 insertions(+), 12 deletions(-) diff --git a/homeassistant/components/touchline/climate.py b/homeassistant/components/touchline/climate.py index 218a6a420ff..16709793ec1 100644 --- a/homeassistant/components/touchline/climate.py +++ b/homeassistant/components/touchline/climate.py @@ -1,6 +1,5 @@ -"""Platform for Roth Touchline heat pump controller.""" +"""Platform for Roth Touchline floor heating controller.""" import logging -from typing import List from pytouchline import PyTouchline import voluptuous as vol @@ -8,6 +7,7 @@ import voluptuous as vol from homeassistant.components.climate import PLATFORM_SCHEMA, ClimateEntity from homeassistant.components.climate.const import ( HVAC_MODE_HEAT, + SUPPORT_PRESET_MODE, SUPPORT_TARGET_TEMPERATURE, ) from homeassistant.const import ATTR_TEMPERATURE, CONF_HOST, TEMP_CELSIUS @@ -15,7 +15,21 @@ import homeassistant.helpers.config_validation as cv _LOGGER = logging.getLogger(__name__) -SUPPORT_FLAGS = SUPPORT_TARGET_TEMPERATURE +PRESET_MODES = { + "Normal": {"mode": 0, "program": 0}, + "Night": {"mode": 1, "program": 0}, + "Holiday": {"mode": 2, "program": 0}, + "Pro 1": {"mode": 0, "program": 1}, + "Pro 2": {"mode": 0, "program": 2}, + "Pro 3": {"mode": 0, "program": 3}, +} + +TOUCHLINE_HA_PRESETS = { + (settings["mode"], settings["program"]): preset + for preset, settings in PRESET_MODES.items() +} + +SUPPORT_FLAGS = SUPPORT_TARGET_TEMPERATURE | SUPPORT_PRESET_MODE PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend({vol.Required(CONF_HOST): cv.string}) @@ -36,11 +50,13 @@ class Touchline(ClimateEntity): """Representation of a Touchline device.""" def __init__(self, touchline_thermostat): - """Initialize the climate device.""" + """Initialize the Touchline device.""" self.unit = touchline_thermostat self._name = None self._current_temperature = None self._target_temperature = None + self._current_operation_mode = None + self._preset_mode = None @property def supported_features(self): @@ -48,26 +64,26 @@ class Touchline(ClimateEntity): return SUPPORT_FLAGS def update(self): - """Update unit attributes.""" + """Update thermostat attributes.""" self.unit.update() self._name = self.unit.get_name() self._current_temperature = self.unit.get_current_temperature() self._target_temperature = self.unit.get_target_temperature() + self._preset_mode = TOUCHLINE_HA_PRESETS.get( + (self.unit.get_operation_mode(), self.unit.get_week_program()) + ) @property - def hvac_mode(self) -> str: - """Return hvac operation ie. heat, cool mode. + def hvac_mode(self): + """Return current HVAC mode. Need to be one of HVAC_MODE_*. """ return HVAC_MODE_HEAT @property - def hvac_modes(self) -> List[str]: - """Return the list of available hvac operation modes. - - Need to be a subset of HVAC_MODES. - """ + def hvac_modes(self): + """Return list of possible operation modes.""" return [HVAC_MODE_HEAT] @property @@ -95,6 +111,25 @@ class Touchline(ClimateEntity): """Return the temperature we try to reach.""" return self._target_temperature + @property + def preset_mode(self): + """Return the current preset mode.""" + return self._preset_mode + + @property + def preset_modes(self): + """Return available preset modes.""" + return list(PRESET_MODES) + + def set_preset_mode(self, preset_mode): + """Set new target preset mode.""" + self.unit.set_operation_mode(PRESET_MODES[preset_mode]["mode"]) + self.unit.set_week_program(PRESET_MODES[preset_mode]["program"]) + + def set_hvac_mode(self, hvac_mode): + """Set new target hvac mode.""" + self._current_operation_mode = HVAC_MODE_HEAT + def set_temperature(self, **kwargs): """Set new target temperature.""" if kwargs.get(ATTR_TEMPERATURE) is not None: