diff --git a/homeassistant/components/climate/ecobee.py b/homeassistant/components/climate/ecobee.py index 84d8c32f9ff..bfb11f703d1 100644 --- a/homeassistant/components/climate/ecobee.py +++ b/homeassistant/components/climate/ecobee.py @@ -22,16 +22,25 @@ _CONFIGURING = {} _LOGGER = logging.getLogger(__name__) ATTR_FAN_MIN_ON_TIME = 'fan_min_on_time' +ATTR_RESUME_ALL = 'resume_all' + +DEFAULT_RESUME_ALL = False DEPENDENCIES = ['ecobee'] SERVICE_SET_FAN_MIN_ON_TIME = 'ecobee_set_fan_min_on_time' +SERVICE_RESUME_PROGRAM = 'ecobee_resume_program' 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), }) +RESUME_PROGRAM_SCHEMA = vol.Schema({ + vol.Optional(ATTR_ENTITY_ID): cv.entity_ids, + vol.Optional(ATTR_RESUME_ALL, default=DEFAULT_RESUME_ALL): cv.boolean, +}) + def setup_platform(hass, config, add_devices, discovery_info=None): """Setup the Ecobee Thermostat Platform.""" @@ -48,21 +57,36 @@ def setup_platform(hass, config, add_devices, discovery_info=None): 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') + entity_id = service.data.get(ATTR_ENTITY_ID) + fan_min_on_time = service.data[ATTR_FAN_MIN_ON_TIME] if entity_id: target_thermostats = [device for device in devices - if device.entity_id == entity_id] + if device.entity_id in 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) + def resume_program_set_service(service): + """Resume the program on the target thermostats.""" + entity_id = service.data.get(ATTR_ENTITY_ID) + resume_all = service.data.get(ATTR_RESUME_ALL) + + if entity_id: + target_thermostats = [device for device in devices + if device.entity_id in entity_id] + else: + target_thermostats = devices + + for thermostat in target_thermostats: + thermostat.resume_program(resume_all) + + thermostat.update_ha_state(True) + descriptions = load_yaml_config_file( path.join(path.dirname(__file__), 'services.yaml')) @@ -71,6 +95,11 @@ def setup_platform(hass, config, add_devices, discovery_info=None): descriptions.get(SERVICE_SET_FAN_MIN_ON_TIME), schema=SET_FAN_MIN_ON_TIME_SCHEMA) + hass.services.register( + DOMAIN, SERVICE_RESUME_PROGRAM, resume_program_set_service, + descriptions.get(SERVICE_RESUME_PROGRAM), + schema=RESUME_PROGRAM_SCHEMA) + class Thermostat(ClimateDevice): """A thermostat class for Ecobee.""" @@ -249,6 +278,12 @@ class Thermostat(ClimateDevice): fan_min_on_time) self.update_without_throttle = True + def resume_program(self, resume_all): + """Resume the thermostat schedule program.""" + self.data.ecobee.resume_program(self.thermostat_index, + str(resume_all).lower()) + self.update_without_throttle = True + # Home and Sleep mode aren't used in UI yet: # def turn_home_mode_on(self): diff --git a/homeassistant/components/climate/services.yaml b/homeassistant/components/climate/services.yaml index d28e8c4dd88..ac8e2ab1dea 100644 --- a/homeassistant/components/climate/services.yaml +++ b/homeassistant/components/climate/services.yaml @@ -94,3 +94,27 @@ set_swing_mode: swing_mode: description: New value of swing mode example: 1 + +ecobee_set_fan_min_on_time: + description: Set the minimum fan on time + + fields: + entity_id: + description: Name(s) of entities to change + example: 'climate.kitchen' + + fan_min_on_time: + description: New value of fan min on time + example: 5 + +ecobee_resume_program: + description: Resume the programmed schedule + + fields: + entity_id: + description: Name(s) of entities to change + example: 'climate.kitchen' + + resume_all: + description: Resume all events and return to the scheduled program. This default to false which removes only the top event. + example: true diff --git a/homeassistant/helpers/state.py b/homeassistant/helpers/state.py index 536975c100e..3be344e7d9d 100644 --- a/homeassistant/helpers/state.py +++ b/homeassistant/helpers/state.py @@ -22,7 +22,8 @@ from homeassistant.components.climate import ( SERVICE_SET_HUMIDITY, SERVICE_SET_OPERATION_MODE, SERVICE_SET_SWING_MODE, SERVICE_SET_TEMPERATURE) from homeassistant.components.climate.ecobee import ( - ATTR_FAN_MIN_ON_TIME, SERVICE_SET_FAN_MIN_ON_TIME) + ATTR_FAN_MIN_ON_TIME, SERVICE_SET_FAN_MIN_ON_TIME, + ATTR_RESUME_ALL, SERVICE_RESUME_PROGRAM) from homeassistant.const import ( ATTR_ENTITY_ID, ATTR_TEMPERATURE, SERVICE_ALARM_ARM_AWAY, SERVICE_ALARM_ARM_HOME, SERVICE_ALARM_DISARM, SERVICE_ALARM_TRIGGER, @@ -52,6 +53,7 @@ SERVICE_ATTRIBUTES = { SERVICE_SET_AWAY_MODE: [ATTR_AWAY_MODE], SERVICE_SET_FAN_MODE: [ATTR_FAN_MODE], SERVICE_SET_FAN_MIN_ON_TIME: [ATTR_FAN_MIN_ON_TIME], + SERVICE_RESUME_PROGRAM: [ATTR_RESUME_ALL], SERVICE_SET_TEMPERATURE: [ATTR_TEMPERATURE], SERVICE_SET_HUMIDITY: [ATTR_HUMIDITY], SERVICE_SET_SWING_MODE: [ATTR_SWING_MODE],