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 <marhje52@gmail.com> * Update homeassistant/components/touchline/climate.py Co-authored-by: Martin Hjelmare <marhje52@gmail.com> * Update homeassistant/components/touchline/climate.py Co-authored-by: Martin Hjelmare <marhje52@gmail.com> * All changes needed. * Cleaned up * Clean up Co-authored-by: Martin Hjelmare <marhje52@gmail.com>
This commit is contained in:
parent
572d5a09cd
commit
317bd8ffd2
1 changed files with 47 additions and 12 deletions
|
@ -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:
|
||||
|
|
Loading…
Add table
Reference in a new issue