From 1f7792678b689c7199b169a0a47669a231173e37 Mon Sep 17 00:00:00 2001 From: devdelay Date: Sat, 18 Jun 2016 13:20:39 -0400 Subject: [PATCH] Add service set_hvac_mode (#2303) * set hvac_mode * Update __init__.py * Update __init__.py --- .../components/thermostat/__init__.py | 38 +++++++++++++++++++ 1 file changed, 38 insertions(+) diff --git a/homeassistant/components/thermostat/__init__.py b/homeassistant/components/thermostat/__init__.py index fa90813500d..4c57a23ff9c 100644 --- a/homeassistant/components/thermostat/__init__.py +++ b/homeassistant/components/thermostat/__init__.py @@ -28,6 +28,7 @@ SCAN_INTERVAL = 60 SERVICE_SET_AWAY_MODE = "set_away_mode" SERVICE_SET_TEMPERATURE = "set_temperature" SERVICE_SET_FAN_MODE = "set_fan_mode" +SERVICE_SET_HVAC_MODE = "set_hvac_mode" STATE_HEAT = "heat" STATE_COOL = "cool" @@ -36,6 +37,7 @@ STATE_IDLE = "idle" ATTR_CURRENT_TEMPERATURE = "current_temperature" ATTR_AWAY_MODE = "away_mode" ATTR_FAN = "fan" +ATTR_HVAC_MODE = "hvac_mode" ATTR_MAX_TEMP = "max_temp" ATTR_MIN_TEMP = "min_temp" ATTR_TEMPERATURE_LOW = "target_temp_low" @@ -56,6 +58,10 @@ SET_FAN_MODE_SCHEMA = vol.Schema({ vol.Optional(ATTR_ENTITY_ID): cv.entity_ids, vol.Required(ATTR_FAN): cv.boolean, }) +SET_HVAC_MODE_SCHEMA = vol.Schema({ + vol.Optional(ATTR_ENTITY_ID): cv.entity_ids, + vol.Required(ATTR_HVAC_MODE): cv.string, +}) def set_away_mode(hass, away_mode, entity_id=None): @@ -92,6 +98,18 @@ def set_fan_mode(hass, fan_mode, entity_id=None): hass.services.call(DOMAIN, SERVICE_SET_FAN_MODE, data) +def set_hvac_mode(hass, hvac_mode, entity_id=None): + """Set specified thermostat hvac mode.""" + data = { + ATTR_HVAC_MODE: hvac_mode + } + + if entity_id: + data[ATTR_ENTITY_ID] = entity_id + + hass.services.call(DOMAIN, SERVICE_SET_HVAC_MODE, data) + + # pylint: disable=too-many-branches def setup(hass, config): """Setup thermostats.""" @@ -157,6 +175,22 @@ def setup(hass, config): descriptions.get(SERVICE_SET_FAN_MODE), schema=SET_FAN_MODE_SCHEMA) + def hvac_mode_set_service(service): + """Set hvac mode on target thermostats.""" + target_thermostats = component.extract_from_service(service) + + hvac_mode = service.data[ATTR_HVAC_MODE] + + for thermostat in target_thermostats: + thermostat.set_hvac_mode(hvac_mode) + + thermostat.update_ha_state(True) + + hass.services.register( + DOMAIN, SERVICE_SET_HVAC_MODE, hvac_mode_set_service, + descriptions.get(SERVICE_SET_HVAC_MODE), + schema=SET_HVAC_MODE_SCHEMA) + return True @@ -243,6 +277,10 @@ class ThermostatDevice(Entity): """Set new target temperature.""" pass + def set_hvac_mode(self, hvac_mode): + """Set hvac mode.""" + pass + def turn_away_mode_on(self): """Turn away mode on.""" pass