diff --git a/homeassistant/components/ecobee/climate.py b/homeassistant/components/ecobee/climate.py index 700464c3ce19..809cb64fca90 100644 --- a/homeassistant/components/ecobee/climate.py +++ b/homeassistant/components/ecobee/climate.py @@ -3,8 +3,6 @@ import collections from typing import Any, override -import probatio - from homeassistant.components.climate import ( ATTR_TARGET_TEMP_HIGH, ATTR_TARGET_TEMP_LOW, @@ -29,11 +27,7 @@ from homeassistant.const import ( ) from homeassistant.core import HomeAssistant, callback from homeassistant.exceptions import ServiceValidationError -from homeassistant.helpers import ( - config_validation as cv, - device_registry as dr, - entity_platform, -) +from homeassistant.helpers import device_registry as dr from homeassistant.helpers.device_registry import DeviceInfo from homeassistant.helpers.entity_platform import AddConfigEntryEntitiesCallback from homeassistant.util.unit_conversion import TemperatureConverter @@ -62,13 +56,6 @@ from .services import ( ) from .util import is_indefinite_hold -ATTR_DST_ENABLED = "dst_enabled" -ATTR_MIC_ENABLED = "mic_enabled" -ATTR_AUTO_AWAY = "auto_away" -ATTR_FOLLOW_ME = "follow_me" -ATTR_SENSOR_LIST = "device_ids" -ATTR_PRESET_MODE = "preset_mode" - PRESET_AWAY_INDEFINITELY = "away_indefinitely" PRESET_TEMPERATURE = "temp" PRESET_VACATION = "vacation" @@ -127,12 +114,6 @@ PRESET_TO_ECOBEE_HOLD = { PRESET_HOLD_INDEFINITE: "indefinite", } -SERVICE_SET_DST_MODE = "set_dst_mode" -SERVICE_SET_MIC_MODE = "set_mic_mode" -SERVICE_SET_OCCUPANCY_MODES = "set_occupancy_modes" -SERVICE_SET_SENSORS_USED_IN_CLIMATE = "set_sensors_used_in_climate" - - SUPPORT_FLAGS = ( ClimateEntityFeature.TARGET_TEMPERATURE | ClimateEntityFeature.PRESET_MODE @@ -181,38 +162,6 @@ async def async_setup_entry( config_entry.async_on_unload(_remove_thermostats) - platform = entity_platform.async_get_current_platform() - - platform.async_register_entity_service( - SERVICE_SET_DST_MODE, - {probatio.Required(ATTR_DST_ENABLED): cv.boolean}, - "set_dst_mode", - ) - - platform.async_register_entity_service( - SERVICE_SET_MIC_MODE, - {probatio.Required(ATTR_MIC_ENABLED): cv.boolean}, - "set_mic_mode", - ) - - platform.async_register_entity_service( - SERVICE_SET_OCCUPANCY_MODES, - { - probatio.Optional(ATTR_AUTO_AWAY): cv.boolean, - probatio.Optional(ATTR_FOLLOW_ME): cv.boolean, - }, - "set_occupancy_modes", - ) - - platform.async_register_entity_service( - SERVICE_SET_SENSORS_USED_IN_CLIMATE, - { - probatio.Optional(ATTR_PRESET_MODE): cv.string, - probatio.Required(ATTR_SENSOR_LIST): probatio.EnsureList(), - }, - "set_sensors_used_in_climate", - ) - class Thermostat(ClimateEntity): """A thermostat class for Ecobee.""" diff --git a/homeassistant/components/ecobee/services.py b/homeassistant/components/ecobee/services.py index bd413ee76f46..7bfb1baec582 100644 --- a/homeassistant/components/ecobee/services.py +++ b/homeassistant/components/ecobee/services.py @@ -4,9 +4,11 @@ from typing import TYPE_CHECKING import probatio +from homeassistant.components.climate import DOMAIN as CLIMATE_DOMAIN from homeassistant.const import ATTR_ENTITY_ID from homeassistant.core import HomeAssistant, ServiceCall, callback from homeassistant.helpers import config_validation as cv +from homeassistant.helpers.service import async_register_platform_entity_service from .const import DOMAIN from .util import ecobee_date, ecobee_time @@ -14,13 +16,19 @@ from .util import ecobee_date, ecobee_time if TYPE_CHECKING: from .climate import Thermostat +ATTR_AUTO_AWAY = "auto_away" ATTR_COOL_TEMP = "cool_temp" +ATTR_DST_ENABLED = "dst_enabled" ATTR_END_DATE = "end_date" ATTR_END_TIME = "end_time" ATTR_FAN_MIN_ON_TIME = "fan_min_on_time" ATTR_FAN_MODE = "fan_mode" +ATTR_FOLLOW_ME = "follow_me" ATTR_HEAT_TEMP = "heat_temp" +ATTR_MIC_ENABLED = "mic_enabled" +ATTR_PRESET_MODE = "preset_mode" ATTR_RESUME_ALL = "resume_all" +ATTR_SENSOR_LIST = "device_ids" ATTR_START_DATE = "start_date" ATTR_START_TIME = "start_time" ATTR_VACATION_NAME = "vacation_name" @@ -32,7 +40,11 @@ DATA_THERMOSTATS = "thermostats" SERVICE_CREATE_VACATION = "create_vacation" SERVICE_DELETE_VACATION = "delete_vacation" SERVICE_RESUME_PROGRAM = "resume_program" +SERVICE_SET_DST_MODE = "set_dst_mode" SERVICE_SET_FAN_MIN_ON_TIME = "set_fan_min_on_time" +SERVICE_SET_MIC_MODE = "set_mic_mode" +SERVICE_SET_OCCUPANCY_MODES = "set_occupancy_modes" +SERVICE_SET_SENSORS_USED_IN_CLIMATE = "set_sensors_used_in_climate" DTGROUP_START_INCLUSIVE_MSG = ( f"{ATTR_START_DATE} and {ATTR_START_TIME} must be specified together" @@ -180,3 +192,41 @@ def async_setup_services(hass: HomeAssistant) -> None: _resume_program_set_service, schema=RESUME_PROGRAM_SCHEMA, ) + async_register_platform_entity_service( + hass, + DOMAIN, + SERVICE_SET_DST_MODE, + entity_domain=CLIMATE_DOMAIN, + func="set_dst_mode", + schema={probatio.Required(ATTR_DST_ENABLED): cv.boolean}, + ) + async_register_platform_entity_service( + hass, + DOMAIN, + SERVICE_SET_MIC_MODE, + entity_domain=CLIMATE_DOMAIN, + func="set_mic_mode", + schema={probatio.Required(ATTR_MIC_ENABLED): cv.boolean}, + ) + async_register_platform_entity_service( + hass, + DOMAIN, + SERVICE_SET_OCCUPANCY_MODES, + entity_domain=CLIMATE_DOMAIN, + func="set_occupancy_modes", + schema={ + probatio.Optional(ATTR_AUTO_AWAY): cv.boolean, + probatio.Optional(ATTR_FOLLOW_ME): cv.boolean, + }, + ) + async_register_platform_entity_service( + hass, + DOMAIN, + SERVICE_SET_SENSORS_USED_IN_CLIMATE, + entity_domain=CLIMATE_DOMAIN, + func="set_sensors_used_in_climate", + schema={ + probatio.Optional(ATTR_PRESET_MODE): cv.string, + probatio.Required(ATTR_SENSOR_LIST): probatio.EnsureList(), + }, + ) diff --git a/tests/components/ecobee/test_climate.py b/tests/components/ecobee/test_climate.py index 3ae859aafaa2..cd71ac6ae5f6 100644 --- a/tests/components/ecobee/test_climate.py +++ b/tests/components/ecobee/test_climate.py @@ -9,14 +9,13 @@ import pytest from homeassistant import const from homeassistant.components.climate import ClimateEntityFeature -from homeassistant.components.ecobee.climate import ( +from homeassistant.components.ecobee.climate import PRESET_AWAY_INDEFINITELY, Thermostat +from homeassistant.components.ecobee.const import DOMAIN +from homeassistant.components.ecobee.services import ( ATTR_PRESET_MODE, ATTR_SENSOR_LIST, - PRESET_AWAY_INDEFINITELY, - Thermostat, + _async_get_thermostats, ) -from homeassistant.components.ecobee.const import DOMAIN -from homeassistant.components.ecobee.services import _async_get_thermostats from homeassistant.const import ATTR_ENTITY_ID, ATTR_SUPPORTED_FEATURES, STATE_OFF from homeassistant.core import HomeAssistant from homeassistant.exceptions import ServiceValidationError