From b2354f45beb09b918b73613d7a7d892604648e84 Mon Sep 17 00:00:00 2001 From: John Arild Berentsen Date: Wed, 5 Oct 2016 08:48:25 +0200 Subject: [PATCH] Add possibility to set temperature to a given operation_mode (#3646) * Add possibility to set temperature to a given operation_mode * Correctly break * Review changes --- homeassistant/components/climate/__init__.py | 6 +++++- homeassistant/components/climate/services.yaml | 12 ++++++++++++ homeassistant/components/climate/zwave.py | 13 ++++++++++++- 3 files changed, 29 insertions(+), 2 deletions(-) diff --git a/homeassistant/components/climate/__init__.py b/homeassistant/components/climate/__init__.py index 93330603828..e8047093cc8 100644 --- a/homeassistant/components/climate/__init__.py +++ b/homeassistant/components/climate/__init__.py @@ -79,6 +79,7 @@ SET_TEMPERATURE_SCHEMA = vol.Schema({ vol.Inclusive(ATTR_TARGET_TEMP_HIGH, 'temperature'): vol.Coerce(float), vol.Inclusive(ATTR_TARGET_TEMP_LOW, 'temperature'): vol.Coerce(float), vol.Optional(ATTR_ENTITY_ID): cv.entity_ids, + vol.Optional(ATTR_OPERATION_MODE): cv.string, }) SET_FAN_MODE_SCHEMA = vol.Schema({ vol.Optional(ATTR_ENTITY_ID): cv.entity_ids, @@ -122,8 +123,10 @@ def set_aux_heat(hass, aux_heat, entity_id=None): hass.services.call(DOMAIN, SERVICE_SET_AUX_HEAT, data) +# pylint: disable=too-many-arguments def set_temperature(hass, temperature=None, entity_id=None, - target_temp_high=None, target_temp_low=None): + target_temp_high=None, target_temp_low=None, + operation_mode=None): """Set new target temperature.""" kwargs = { key: value for key, value in [ @@ -131,6 +134,7 @@ def set_temperature(hass, temperature=None, entity_id=None, (ATTR_TARGET_TEMP_HIGH, target_temp_high), (ATTR_TARGET_TEMP_LOW, target_temp_low), (ATTR_ENTITY_ID, entity_id), + (ATTR_OPERATION_MODE, operation_mode) ] if value is not None } _LOGGER.debug("set_temperature start data=%s", kwargs) diff --git a/homeassistant/components/climate/services.yaml b/homeassistant/components/climate/services.yaml index 3a037d2a48b..d28e8c4dd88 100644 --- a/homeassistant/components/climate/services.yaml +++ b/homeassistant/components/climate/services.yaml @@ -34,6 +34,18 @@ set_temperature: description: New target temperature for hvac example: 25 + target_temp_high: + description: New target high tempereature for hvac + example: 26 + + target_temp_low: + description: New target low temperature for hvac + example: 20 + + operation_mode: + description: Operation mode to set temperature to. This defaults to current_operation mode if not set, or set incorrectly. + example: 'Heat' + set_humidity: description: Set target humidity of climate device diff --git a/homeassistant/components/climate/zwave.py b/homeassistant/components/climate/zwave.py index d744f9a1391..767bed6ff94 100755 --- a/homeassistant/components/climate/zwave.py +++ b/homeassistant/components/climate/zwave.py @@ -8,7 +8,8 @@ https://home-assistant.io/components/climate.zwave/ # pylint: disable=import-error import logging from homeassistant.components.climate import DOMAIN -from homeassistant.components.climate import ClimateDevice +from homeassistant.components.climate import ( + ClimateDevice, ATTR_OPERATION_MODE) from homeassistant.components.zwave import ZWaveDeviceEntity from homeassistant.components import zwave from homeassistant.const import ( @@ -243,10 +244,20 @@ class ZWaveClimate(ZWaveDeviceEntity, ClimateDevice): temperature = kwargs.get(ATTR_TEMPERATURE) else: return + operation_mode = kwargs.get(ATTR_OPERATION_MODE) + _LOGGER.debug("set_temperature operation_mode=%s", operation_mode) for value in (self._node.get_values( class_id=zwave.const.COMMAND_CLASS_THERMOSTAT_SETPOINT) .values()): + if operation_mode is not None: + setpoint_mode = SET_TEMP_TO_INDEX.get(operation_mode) + if value.index != setpoint_mode: + continue + _LOGGER.debug("setpoint_mode=%s", setpoint_mode) + value.data = temperature + break + if self.current_operation is not None: if self._hrt4_zw and self.current_operation == 'Off': # HRT4-ZW can change setpoint when off.