diff --git a/homeassistant/components/ecobee.py b/homeassistant/components/ecobee.py index 11c49fd44eb..a1986f8e6eb 100644 --- a/homeassistant/components/ecobee.py +++ b/homeassistant/components/ecobee.py @@ -22,7 +22,7 @@ HOLD_TEMP = 'hold_temp' REQUIREMENTS = [ 'https://github.com/nkgilley/python-ecobee-api/archive/' - '4a884bc146a93991b4210f868f3d6aecf0a181e6.zip#python-ecobee==0.0.5'] + '4856a704670c53afe1882178a89c209b5f98533d.zip#python-ecobee==0.0.6'] _LOGGER = logging.getLogger(__name__) diff --git a/homeassistant/components/thermostat/ecobee.py b/homeassistant/components/thermostat/ecobee.py index abeda6be736..f07ef47269d 100644 --- a/homeassistant/components/thermostat/ecobee.py +++ b/homeassistant/components/thermostat/ecobee.py @@ -5,17 +5,29 @@ For more details about this platform, please refer to the documentation at https://home-assistant.io/components/thermostat.ecobee/ """ import logging +from os import path +import voluptuous as vol from homeassistant.components import ecobee from homeassistant.components.thermostat import ( - STATE_COOL, STATE_HEAT, STATE_IDLE, ThermostatDevice) -from homeassistant.const import STATE_OFF, STATE_ON, TEMP_FAHRENHEIT + DOMAIN, STATE_COOL, STATE_HEAT, STATE_IDLE, ThermostatDevice) +from homeassistant.const import ( + ATTR_ENTITY_ID, STATE_OFF, STATE_ON, TEMP_FAHRENHEIT) +from homeassistant.config import load_yaml_config_file +import homeassistant.helpers.config_validation as cv DEPENDENCIES = ['ecobee'] _LOGGER = logging.getLogger(__name__) ECOBEE_CONFIG_FILE = 'ecobee.conf' _CONFIGURING = {} +ATTR_FAN_MIN_ON_TIME = "fan_min_on_time" +SERVICE_SET_FAN_MIN_ON_TIME = "ecobee_set_fan_min_on_time" +SET_FAN_MIN_ON_TIME_SCHEMA = vol.Schema({ + vol.Optional(ATTR_ENTITY_ID): cv.entity_ids, + vol.Required(ATTR_FAN_MIN_ON_TIME): vol.Coerce(int), +}) + def setup_platform(hass, config, add_devices, discovery_info=None): """Setup the Ecobee Thermostat Platform.""" @@ -26,10 +38,37 @@ def setup_platform(hass, config, add_devices, discovery_info=None): _LOGGER.info( "Loading ecobee thermostat component with hold_temp set to %s", hold_temp) - add_devices(Thermostat(data, index, hold_temp) - for index in range(len(data.ecobee.thermostats))) + devices = [Thermostat(data, index, hold_temp) + for index in range(len(data.ecobee.thermostats))] + add_devices(devices) + + def fan_min_on_time_set_service(service): + """Set the minimum fan on time on the target thermostats.""" + entity_id = service.data.get('entity_id') + + if entity_id: + target_thermostats = [device for device in devices + if device.entity_id == entity_id] + else: + target_thermostats = devices + + fan_min_on_time = service.data[ATTR_FAN_MIN_ON_TIME] + + for thermostat in target_thermostats: + thermostat.set_fan_min_on_time(str(fan_min_on_time)) + + thermostat.update_ha_state(True) + + descriptions = load_yaml_config_file( + path.join(path.dirname(__file__), 'services.yaml')) + + hass.services.register( + DOMAIN, SERVICE_SET_FAN_MIN_ON_TIME, fan_min_on_time_set_service, + descriptions.get(SERVICE_SET_FAN_MIN_ON_TIME), + schema=SET_FAN_MIN_ON_TIME_SCHEMA) +# pylint: disable=too-many-public-methods class Thermostat(ThermostatDevice): """A thermostat class for Ecobee.""" @@ -127,6 +166,11 @@ class Thermostat(ThermostatDevice): """Return current hvac mode ie. auto, auxHeatOnly, cool, heat, off.""" return self.thermostat['settings']['hvacMode'] + @property + def fan_min_on_time(self): + """Return current fan minimum on time.""" + return self.thermostat['settings']['fanMinOnTime'] + @property def device_state_attributes(self): """Return device specific state attributes.""" @@ -135,7 +179,8 @@ class Thermostat(ThermostatDevice): "humidity": self.humidity, "fan": self.fan, "mode": self.mode, - "hvac_mode": self.hvac_mode + "hvac_mode": self.hvac_mode, + "fan_min_on_time": self.fan_min_on_time } @property @@ -177,6 +222,11 @@ class Thermostat(ThermostatDevice): """Set HVAC mode (auto, auxHeatOnly, cool, heat, off).""" self.data.ecobee.set_hvac_mode(self.thermostat_index, mode) + def set_fan_min_on_time(self, fan_min_on_time): + """Set the minimum fan on time.""" + self.data.ecobee.set_fan_min_on_time(self.thermostat_index, + fan_min_on_time) + # Home and Sleep mode aren't used in UI yet: # def turn_home_mode_on(self): diff --git a/homeassistant/components/thermostat/services.yaml b/homeassistant/components/thermostat/services.yaml index 3592dfce75d..9ce1ab704e6 100644 --- a/homeassistant/components/thermostat/services.yaml +++ b/homeassistant/components/thermostat/services.yaml @@ -34,3 +34,15 @@ set_fan_mode: fan: description: New value of fan mode example: true + +ecobee_set_fan_min_on_time: + description: Set the minimum time, in minutes, to run the fan each hour + + fields: + entity_id: + descriptions: Name(s) of entities to change + example: 'thermostat.ecobee' + + fan_min_on_time: + description: New value of fan minimum on time + example: 5 diff --git a/homeassistant/helpers/state.py b/homeassistant/helpers/state.py index 078bbb27b20..7000ea97b43 100644 --- a/homeassistant/helpers/state.py +++ b/homeassistant/helpers/state.py @@ -15,6 +15,8 @@ from homeassistant.components.sun import ( from homeassistant.components.thermostat import ( ATTR_AWAY_MODE, ATTR_FAN, SERVICE_SET_AWAY_MODE, SERVICE_SET_FAN_MODE, SERVICE_SET_TEMPERATURE) +from homeassistant.components.thermostat.ecobee import ( + ATTR_FAN_MIN_ON_TIME, SERVICE_SET_FAN_MIN_ON_TIME) from homeassistant.components.hvac import ( ATTR_HUMIDITY, ATTR_SWING_MODE, ATTR_OPERATION_MODE, ATTR_AUX_HEAT, SERVICE_SET_HUMIDITY, SERVICE_SET_SWING_MODE, @@ -46,6 +48,7 @@ SERVICE_ATTRIBUTES = { SERVICE_NOTIFY: [ATTR_MESSAGE], SERVICE_SET_AWAY_MODE: [ATTR_AWAY_MODE], SERVICE_SET_FAN_MODE: [ATTR_FAN], + SERVICE_SET_FAN_MIN_ON_TIME: [ATTR_FAN_MIN_ON_TIME], SERVICE_SET_TEMPERATURE: [ATTR_TEMPERATURE], SERVICE_SET_HUMIDITY: [ATTR_HUMIDITY], SERVICE_SET_SWING_MODE: [ATTR_SWING_MODE], diff --git a/requirements_all.txt b/requirements_all.txt index 07db2ad3a48..c5c58bd7cfa 100644 --- a/requirements_all.txt +++ b/requirements_all.txt @@ -130,7 +130,7 @@ https://github.com/jamespcole/home-assistant-nzb-clients/archive/616cad591540925 https://github.com/kellerza/pyqwikswitch/archive/v0.4.zip#pyqwikswitch==0.4 # homeassistant.components.ecobee -https://github.com/nkgilley/python-ecobee-api/archive/4a884bc146a93991b4210f868f3d6aecf0a181e6.zip#python-ecobee==0.0.5 +https://github.com/nkgilley/python-ecobee-api/archive/4856a704670c53afe1882178a89c209b5f98533d.zip#python-ecobee==0.0.6 # homeassistant.components.switch.edimax https://github.com/rkabadi/pyedimax/archive/365301ce3ff26129a7910c501ead09ea625f3700.zip#pyedimax==0.1