From 0f827defefcf52dec944b12371f16a03913a2b95 Mon Sep 17 00:00:00 2001 From: Vincent Le Bourlot Date: Tue, 19 May 2020 07:22:11 +0200 Subject: [PATCH] added a few configuration parameters. --- custom_components/tahoma_extended/climate.py | 81 +++++++++++++++----- 1 file changed, 60 insertions(+), 21 deletions(-) diff --git a/custom_components/tahoma_extended/climate.py b/custom_components/tahoma_extended/climate.py index 19eaf6e..065080e 100755 --- a/custom_components/tahoma_extended/climate.py +++ b/custom_components/tahoma_extended/climate.py @@ -33,10 +33,18 @@ from homeassistant.helpers.event import async_track_state_change from . import DOMAIN as TAHOMA_DOMAIN, TahomaDevice +DEFAULT_TOLERANCE = 0.3 + +CONF_MIN_TEMP = "min_temp" +CONF_MAX_TEMP = "max_temp" +CONF_TARGET_TEMP = "target_temp" CONF_AWAY_TEMP = "away_temp" CONF_ECO_TEMP = "eco_temp" CONF_COMFORT_TEMP = "comfort_temp" CONF_ANTI_FREEZE_TEMP = "anti_freeze_temp" +CONF_COLD_TOLERANCE = "cold_tolerance" +CONF_HOT_TOLERANCE = "hot_tolerance" +CONF_INITIAL_HVAC_MODE = "initial_hvac_mode" SUPPORT_AWAY_TEMP = 1 SUPPORT_ECO_TEMP = 2 @@ -49,10 +57,18 @@ { vol.Required(CONF_NAME): cv.string, vol.Required(CONF_ENTITY_ID): cv.entity_domain("sensor"), - vol.Optional(CONF_AWAY_TEMP): vol.Coerce(float), + vol.Optional(CONF_MIN_TEMP): vol.Coerce(float), + vol.Optional(CONF_MAX_TEMP): vol.Coerce(float), + vol.Optional(CONF_COLD_TOLERANCE, default=DEFAULT_TOLERANCE): vol.Coerce(float), + vol.Optional(CONF_HOT_TOLERANCE, default=DEFAULT_TOLERANCE): vol.Coerce(float), + vol.Optional(CONF_INITIAL_HVAC_MODE): vol.In( + [HVAC_MODE_HEAT, HVAC_MODE_OFF] + ), + vol.Optional(CONF_TARGET_TEMP): vol.Coerce(float), vol.Optional(CONF_ECO_TEMP): vol.Coerce(float), vol.Optional(CONF_COMFORT_TEMP): vol.Coerce(float), vol.Optional(CONF_ANTI_FREEZE_TEMP): vol.Coerce(float), + vol.Optional(CONF_AWAY_TEMP): vol.Coerce(float), } ) @@ -77,10 +93,16 @@ async def async_setup_platform(hass, config, async_add_entities, discovery_info= for sensor in config["sensors"]: if sensor[CONF_NAME] == name: device_sensor = sensor[CONF_ENTITY_ID] + min_temp = config.get(CONF_MIN_TEMP) + max_temp = config.get(CONF_MAX_TEMP) + cold_tolerance = config.get(CONF_COLD_TOLERANCE) + hot_tolerance = config.get(CONF_HOT_TOLERANCE) + target_temp = config.get(CONF_TARGET_TEMP) away_temp = sensor.get(CONF_AWAY_TEMP) eco_temp = sensor.get(CONF_ECO_TEMP) comfort_temp = sensor.get(CONF_COMFORT_TEMP) anti_freeze_temp = sensor.get(CONF_ANTI_FREEZE_TEMP) + initial_hvac_mode = config.get(CONF_INITIAL_HVAC_MODE) if device_sensor is None: _LOGGER.error("Could not find a sensor for thermostat " + name) @@ -91,6 +113,12 @@ async def async_setup_platform(hass, config, async_add_entities, discovery_info= device, controller, device_sensor, + min_temp, + max_temp, + cold_tolerance, + hot_tolerance, + initial_hvac_mode, + target_temp, away_temp, eco_temp, comfort_temp, @@ -109,6 +137,12 @@ def __init__( tahoma_device, controller, sensor_entity_id, + min_temp, + max_temp, + cold_tolerance, + hot_tolerance, + initial_hvac_mode, + target_temp, away_temp, eco_temp, comfort_temp, @@ -118,22 +152,12 @@ def __init__( super().__init__(tahoma_device, controller) if self.tahoma_device.type == "io:AtlanticElectricalHeaterIOComponent": self._type = "io" - if self.tahoma_device.active_states["core:OnOffState"] == "on": - self._hvac_mode = HVAC_MODE_HEAT - else: - self._hvac_mode = HVAC_MODE_OFF if ( self.tahoma_device.type == "somfythermostat:SomfyThermostatThermostatComponent" ): self._type = "thermostat" - if ( - self.tahoma_device.active_states["core:DerogationActivationState"] - == "active" - ): - self._hvac_mode = HVAC_MODE_HEAT - else: - self._hvac_mode = HVAC_MODE_OFF + self._hvac_mode = initial_hvac_mode self._cur_temp = None self._unit = TEMP_CELSIUS self.sensor_entity_id = sensor_entity_id @@ -142,6 +166,11 @@ def __init__( self._hvac_list = [HVAC_MODE_HEAT, HVAC_MODE_OFF] self._preset_mode = None self._somfy_modes = 0 + self._cold_tolerance = cold_tolerance + self._hot_tolerance = hot_tolerance + self._min_temp = min_temp + self._max_temp = max_temp + self._target_temp = target_temp self._away_temp = away_temp self._eco_temp = eco_temp self._comfort_temp = comfort_temp @@ -164,17 +193,13 @@ def __init__( if away_temp or eco_temp or comfort_temp or anti_freeze_temp or self._somfy_modes: self._support_flags = SUPPORT_FLAGS | SUPPORT_PRESET_MODE self._preset_mode = PRESET_NONE - self._target_temp = 21 - self._saved_target_temp = self._target_temp + self._saved_target_temp = target_temp or comfort_temp or away_temp or eco_temp or anti_freeze_temp self._temp_lock = asyncio.Lock() self._active = False - self._cold_tolerance = 0.3 - self._hot_tolerance = 0.3 self._update_caller = "none" def update(self): """Update method.""" - from time import sleep self.controller.get_states([self.tahoma_device]) sensor_state = self.hass.states.get(self.sensor_entity_id) if sensor_state and sensor_state.state != STATE_UNKNOWN: @@ -186,10 +211,6 @@ def update(self): else: self._current_hvac_mode = CURRENT_HVAC_HEAT if self._type == "thermostat": - # if self.tahoma_device.active_states["somfythermostat:HeatingModeState"] == "freezeMode": - # self._target_temp = self.tahoma_device.active_states["somfythermostat:FreezeModeTargetTemperatureState"] - # else: - # self._target_temp = self.tahoma_device.active_states["core:TargetTemperatureState"] state = self.tahoma_device.active_states["somfythermostat:DerogationHeatingModeState"] _LOGGER.debug("caller: %s, target: %s, saved: %s", self._update_caller, self._target_temp, self._saved_target_temp) @@ -327,6 +348,24 @@ def _is_device_active(self): state = self.tahoma_device.active_states["core:OnOffState"] return state == "on" + @property + def min_temp(self): + """Return the minimum temperature.""" + if self._min_temp is not None: + return self._min_temp + + # get default temp from super class + return super().min_temp + + @property + def max_temp(self): + """Return the maximum temperature.""" + if self._max_temp is not None: + return self._max_temp + + # Get default temp from super class + return super().max_temp + def _apply_action(self, target_temperature): if target_temperature < 16: target_temperature = 16