From bd3f0750609969a165f421d96b0e88fd7ad21b9c Mon Sep 17 00:00:00 2001 From: Yehuda Davis Date: Tue, 11 Aug 2020 04:31:38 -0400 Subject: [PATCH] Add Ecobee services (#38749) Enable/disable automatic daylight savings time Enable/disable the Alexa mic on the Ecobee 4 Enable/disable Smart Home/Away and follow me modes --- homeassistant/components/ecobee/climate.py | 45 +++++++++++++++++++ homeassistant/components/ecobee/services.yaml | 33 ++++++++++++++ 2 files changed, 78 insertions(+) diff --git a/homeassistant/components/ecobee/climate.py b/homeassistant/components/ecobee/climate.py index 4aeb52b60ff..dcb21ac41b1 100644 --- a/homeassistant/components/ecobee/climate.py +++ b/homeassistant/components/ecobee/climate.py @@ -33,6 +33,7 @@ from homeassistant.const import ( STATE_ON, TEMP_FAHRENHEIT, ) +from homeassistant.helpers import entity_platform import homeassistant.helpers.config_validation as cv from homeassistant.util.temperature import convert @@ -49,6 +50,10 @@ ATTR_RESUME_ALL = "resume_all" ATTR_START_DATE = "start_date" ATTR_START_TIME = "start_time" ATTR_VACATION_NAME = "vacation_name" +ATTR_DST_ENABLED = "dst_enabled" +ATTR_MIC_ENABLED = "mic_enabled" +ATTR_AUTO_AWAY = "auto_away" +ATTR_FOLLOW_ME = "follow_me" DEFAULT_RESUME_ALL = False PRESET_TEMPERATURE = "temp" @@ -98,6 +103,9 @@ SERVICE_CREATE_VACATION = "create_vacation" SERVICE_DELETE_VACATION = "delete_vacation" SERVICE_RESUME_PROGRAM = "resume_program" SERVICE_SET_FAN_MIN_ON_TIME = "set_fan_min_on_time" +SERVICE_SET_DST_MODE = "set_dst_mode" +SERVICE_SET_MIC_MODE = "set_mic_mode" +SERVICE_SET_OCCUPANCY_MODES = "set_occupancy_modes" DTGROUP_INCLUSIVE_MSG = ( f"{ATTR_START_DATE}, {ATTR_START_TIME}, {ATTR_END_DATE}, " @@ -165,6 +173,8 @@ async def async_setup_entry(hass, config_entry, async_add_entities): async_add_entities(devices, True) + platform = entity_platform.current_platform.get() + def create_vacation_service(service): """Create a vacation on the target thermostat.""" entity_id = service.data[ATTR_ENTITY_ID] @@ -248,6 +258,27 @@ async def async_setup_entry(hass, config_entry, async_add_entities): schema=RESUME_PROGRAM_SCHEMA, ) + platform.async_register_entity_service( + SERVICE_SET_DST_MODE, + {vol.Required(ATTR_DST_ENABLED): cv.boolean}, + "set_dst_mode", + ) + + platform.async_register_entity_service( + SERVICE_SET_MIC_MODE, + {vol.Required(ATTR_MIC_ENABLED): cv.boolean}, + "set_mic_mode", + ) + + platform.async_register_entity_service( + SERVICE_SET_OCCUPANCY_MODES, + { + vol.Optional(ATTR_AUTO_AWAY): cv.boolean, + vol.Optional(ATTR_FOLLOW_ME): cv.boolean, + }, + "set_occupancy_modes", + ) + class Thermostat(ClimateEntity): """A thermostat class for Ecobee.""" @@ -720,3 +751,17 @@ class Thermostat(ClimateEntity): self._last_active_hvac_mode, ) self.set_hvac_mode(self._last_active_hvac_mode) + + def set_dst_mode(self, dst_enabled): + """Enable/disable automatic daylight savings time.""" + self.data.ecobee.set_dst_mode(self.thermostat_index, dst_enabled) + + def set_mic_mode(self, mic_enabled): + """Enable/disable Alexa mic (only for Ecobee 4).""" + self.data.ecobee.set_mic_mode(self.thermostat_index, mic_enabled) + + def set_occupancy_modes(self, auto_away=None, follow_me=None): + """Enable/disable Smart Home/Away and Follow Me modes.""" + self.data.ecobee.set_occupancy_modes( + self.thermostat_index, auto_away, follow_me + ) diff --git a/homeassistant/components/ecobee/services.yaml b/homeassistant/components/ecobee/services.yaml index 88137bd9530..dd848d09d56 100644 --- a/homeassistant/components/ecobee/services.yaml +++ b/homeassistant/components/ecobee/services.yaml @@ -69,3 +69,36 @@ set_fan_min_on_time: fan_min_on_time: description: New value of fan min on time. example: 5 + +set_dst_mode: + description: Enable/disable automatic daylight savings time. + fields: + entity_id: + description: Name(s) of entities to change. + example: "climate.kitchen" + dst_enabled: + description: Enable automatic daylight savings time. + example: "true" + +set_mic_mode: + description: Enable/disable Alexa mic (only for Ecobee 4). + fields: + entity_id: + description: Name(s) of entities to change. + example: "climate.kitchen" + mic_enabled: + description: Enable Alexa mic. + example: "true" + +set_occupancy_modes: + description: Enable/disable Smart Home/Away and Follow Me modes. + fields: + entity_id: + description: Name(s) of entities to change. + example: "climate.kitchen" + auto_away: + description: Enable Smart Home/Away mode. + example: "true" + follow_me: + description: Enable Follow Me mode. + example: "true"