From df94c909f7db9c7948dc097ad0ee52169cb41bbb Mon Sep 17 00:00:00 2001 From: Michael Auchter Date: Mon, 11 Jan 2016 19:23:24 -0600 Subject: [PATCH] thermostat: add service to control fan mode --- .../components/thermostat/__init__.py | 47 +++++++++++++++++++ .../components/thermostat/services.yaml | 12 +++++ 2 files changed, 59 insertions(+) diff --git a/homeassistant/components/thermostat/__init__.py b/homeassistant/components/thermostat/__init__.py index 17b9a2daca6..d92a71ba1f6 100644 --- a/homeassistant/components/thermostat/__init__.py +++ b/homeassistant/components/thermostat/__init__.py @@ -27,6 +27,7 @@ SCAN_INTERVAL = 60 SERVICE_SET_AWAY_MODE = "set_away_mode" SERVICE_SET_TEMPERATURE = "set_temperature" +SERVICE_SET_FAN_MODE = "set_fan_mode" STATE_HEAT = "heat" STATE_COOL = "cool" @@ -70,6 +71,19 @@ def set_temperature(hass, temperature, entity_id=None): hass.services.call(DOMAIN, SERVICE_SET_TEMPERATURE, data) +def set_fan_mode(hass, fan_mode, entity_id=None): + """ Turn all or specified thermostat fan mode on. """ + data = { + ATTR_FAN: fan_mode + } + + if entity_id: + data[ATTR_ENTITY_ID] = entity_id + + hass.services.call(DOMAIN, SERVICE_SET_FAN_MODE, data) + + +# pylint: disable=too-many-branches def setup(hass, config): """ Setup thermostats. """ component = EntityComponent(_LOGGER, DOMAIN, hass, @@ -126,6 +140,31 @@ def setup(hass, config): DOMAIN, SERVICE_SET_TEMPERATURE, temperature_set_service, descriptions.get(SERVICE_SET_TEMPERATURE)) + def fan_mode_set_service(service): + """ Set fan mode on target thermostats """ + + target_thermostats = component.extract_from_service(service) + + fan_mode = service.data.get(ATTR_FAN) + + if fan_mode is None: + _LOGGER.error( + "Received call to %s without attribute %s", + SERVICE_SET_FAN_MODE, ATTR_FAN) + return + + for thermostat in target_thermostats: + if fan_mode: + thermostat.turn_fan_on() + else: + thermostat.turn_fan_off() + + thermostat.update_ha_state(True) + + hass.services.register( + DOMAIN, SERVICE_SET_FAN_MODE, fan_mode_set_service, + descriptions.get(SERVICE_SET_FAN_MODE)) + return True @@ -237,6 +276,14 @@ class ThermostatDevice(Entity): """ Turns away mode off. """ pass + def turn_fan_on(self): + """ Turns fan on. """ + pass + + def turn_fan_off(self): + """ Turns fan off. """ + pass + @property def min_temp(self): """ Return minimum temperature. """ diff --git a/homeassistant/components/thermostat/services.yaml b/homeassistant/components/thermostat/services.yaml index 0d4f4726204..3592dfce75d 100644 --- a/homeassistant/components/thermostat/services.yaml +++ b/homeassistant/components/thermostat/services.yaml @@ -22,3 +22,15 @@ set_temperature: temperature: description: New target temperature for thermostat example: 25 + +set_fan_mode: + description: Turn fan on/off for a thermostat + + fields: + entity_id: + description: Name(s) of entities to change + example: 'thermostat.nest' + + fan: + description: New value of fan mode + example: true