From e03adfc5945897778d32c7ba94e4810104e4df6b Mon Sep 17 00:00:00 2001 From: blademckain <39549249+blademckain@users.noreply.github.com> Date: Fri, 8 May 2020 11:40:54 +0200 Subject: [PATCH] Update climate.py Edit for support temperature range --- custom_components/climate_group/climate.py | 40 ++++++++++++++++++---- 1 file changed, 33 insertions(+), 7 deletions(-) diff --git a/custom_components/climate_group/climate.py b/custom_components/climate_group/climate.py index ee3943b..ae76426 100644 --- a/custom_components/climate_group/climate.py +++ b/custom_components/climate_group/climate.py @@ -61,8 +61,8 @@ ), } ) - -SUPPORT_FLAGS = SUPPORT_TARGET_TEMPERATURE +#edit the supported_flags +SUPPORT_FLAGS = SUPPORT_TARGET_TEMPERATURE, SUPPORT_TARGET_TEMPERATURE_RANGE # HVAC Action priority @@ -110,6 +110,9 @@ def __init__( self._max_temp = 0 self._current_temp = 0 self._target_temp = 0 + #added the temp_low and temp_high + self._target_temp_high = None + self._target_temp_low = None self._mode = None self._action = None self._mode_list = None @@ -185,6 +188,15 @@ def current_temperature(self): @property def target_temperature(self): return self._target_temp + + #added the target_temperature_low and target_temperature_high + @property + def target_temperature_low(self): + return self._target_temp_low + + @property + def target_temperature_high(self): + return self._target_temp_high @property def temperature_unit(self): @@ -202,9 +214,17 @@ async def async_set_temperature(self, **kwargs): if ATTR_HVAC_MODE in kwargs: hvac_mode = kwargs.get(ATTR_HVAC_MODE) await self.async_set_hvac_mode(hvac_mode) - elif ATTR_TEMPERATURE in kwargs: - temperature = kwargs.get(ATTR_TEMPERATURE) - data[ATTR_TEMPERATURE] = temperature + #start add + elif ATTR_TEMPERATURE in kwargs or ATTR_TARGET_TEMP_LOW in kwargs or ATTR_TARGET_TEMP_HIGH in kwargs: + if ATTR_TEMPERATURE in kwargs: + temperature = kwargs.get(ATTR_TEMPERATURE) + data[ATTR_TEMPERATURE] = temperature + elif ATTR_TARGET_TEMP_LOW in kwargs or ATTR_TARGET_TEMP_HIGH in kwargs: + temperature_low = kwargs.get(ATTR_TARGET_TEMP_LOW) + temperature_high = kwargs.get(ATTR_TARGET_TEMP_HIGH) + data[climate.ATTR_TARGET_TEMP_LOW] = temperature_low + data[climate.ATTR_TARGET_TEMP_HIGH] = temperature_high + #end add await self.hass.services.async_call( climate.DOMAIN, climate.SERVICE_SET_TEMPERATURE, data, blocking=True ) @@ -283,12 +303,18 @@ async def async_update(self): self._preset = Counter(itertools.chain(all_presets)).most_common(1)[0][0] self._target_temp = _reduce_attribute(filtered_states, ATTR_TEMPERATURE) + + #start add + self._target_temp_low = _reduce_attribute(filtered_states, ATTR_TARGET_TEMP_LOW) + self._target_temp_high = _reduce_attribute(filtered_states, ATTR_TARGET_TEMP_HIGH) + #end add + self._current_temp = _reduce_attribute( filtered_states, ATTR_CURRENT_TEMPERATURE ) _LOGGER.debug( - f"Target temp: {self._target_temp}; Current temp: {self._current_temp}" + f"Target temp: {self._target_temp}; Target temp low: {self._target_temp_low}; Target temp high: {self._target_temp_high}; Current temp: {self._current_temp}" ) self._min_temp = _reduce_attribute(states, ATTR_MIN_TEMP, reduce=max) @@ -319,7 +345,7 @@ async def async_update(self): async def async_set_preset_mode(self, preset_mode: str): """Forward the preset_mode to all climate in the climate group.""" data = {ATTR_ENTITY_ID: self._entity_ids, ATTR_PRESET_MODE: preset_mode} - + await self.hass.services.async_call( climate.DOMAIN, climate.SERVICE_SET_PRESET_MODE, data, blocking=True )