From 7dedf173ad1cade6f8e64fa7629cd1c0ee90d11e Mon Sep 17 00:00:00 2001 From: Paulus Schoutsen Date: Mon, 15 Jul 2019 11:31:53 -0700 Subject: [PATCH] Allow area ID in service call schemas (#25121) * Allow area ID in service call schemas * Remove ATTR_ENTITY_ID from service light turn off schcema --- homeassistant/components/light/__init__.py | 8 +++----- homeassistant/components/switch/__init__.py | 16 +++++----------- homeassistant/helpers/config_validation.py | 8 +++++++- 3 files changed, 15 insertions(+), 17 deletions(-) diff --git a/homeassistant/components/light/__init__.py b/homeassistant/components/light/__init__.py index d5fc087888e..680ccb76f17 100644 --- a/homeassistant/components/light/__init__.py +++ b/homeassistant/components/light/__init__.py @@ -16,7 +16,7 @@ from homeassistant.const import ( from homeassistant.exceptions import UnknownUser, Unauthorized import homeassistant.helpers.config_validation as cv from homeassistant.helpers.config_validation import ( # noqa - PLATFORM_SCHEMA, PLATFORM_SCHEMA_BASE) + PLATFORM_SCHEMA, PLATFORM_SCHEMA_BASE, ENTITY_SERVICE_SCHEMA) from homeassistant.helpers.entity import ToggleEntity from homeassistant.helpers.entity_component import EntityComponent from homeassistant.helpers import intent @@ -84,8 +84,7 @@ VALID_TRANSITION = vol.All(vol.Coerce(float), vol.Clamp(min=0, max=6553)) VALID_BRIGHTNESS = vol.All(vol.Coerce(int), vol.Clamp(min=0, max=255)) VALID_BRIGHTNESS_PCT = vol.All(vol.Coerce(float), vol.Range(min=0, max=100)) -LIGHT_TURN_ON_SCHEMA = vol.Schema({ - ATTR_ENTITY_ID: cv.comp_entity_ids, +LIGHT_TURN_ON_SCHEMA = ENTITY_SERVICE_SCHEMA.extend({ vol.Exclusive(ATTR_PROFILE, COLOR_GROUP): cv.string, ATTR_TRANSITION: VALID_TRANSITION, ATTR_BRIGHTNESS: VALID_BRIGHTNESS, @@ -111,8 +110,7 @@ LIGHT_TURN_ON_SCHEMA = vol.Schema({ ATTR_EFFECT: cv.string, }) -LIGHT_TURN_OFF_SCHEMA = vol.Schema({ - ATTR_ENTITY_ID: cv.comp_entity_ids, +LIGHT_TURN_OFF_SCHEMA = ENTITY_SERVICE_SCHEMA.extend({ ATTR_TRANSITION: VALID_TRANSITION, ATTR_FLASH: vol.In([FLASH_SHORT, FLASH_LONG]), }) diff --git a/homeassistant/components/switch/__init__.py b/homeassistant/components/switch/__init__.py index e3f756abf53..db178c9fe7e 100644 --- a/homeassistant/components/switch/__init__.py +++ b/homeassistant/components/switch/__init__.py @@ -8,11 +8,9 @@ from homeassistant.loader import bind_hass from homeassistant.helpers.entity_component import EntityComponent from homeassistant.helpers.entity import ToggleEntity from homeassistant.helpers.config_validation import ( # noqa - PLATFORM_SCHEMA, PLATFORM_SCHEMA_BASE) -import homeassistant.helpers.config_validation as cv + PLATFORM_SCHEMA, PLATFORM_SCHEMA_BASE, ENTITY_SERVICE_SCHEMA) from homeassistant.const import ( - STATE_ON, SERVICE_TURN_ON, SERVICE_TURN_OFF, SERVICE_TOGGLE, - ATTR_ENTITY_ID) + STATE_ON, SERVICE_TURN_ON, SERVICE_TURN_OFF, SERVICE_TOGGLE) from homeassistant.components import group DOMAIN = 'switch' @@ -43,10 +41,6 @@ DEVICE_CLASSES = [ DEVICE_CLASSES_SCHEMA = vol.All(vol.Lower, vol.In(DEVICE_CLASSES)) -SWITCH_SERVICE_SCHEMA = vol.Schema({ - vol.Optional(ATTR_ENTITY_ID): cv.comp_entity_ids, -}) - _LOGGER = logging.getLogger(__name__) @@ -67,17 +61,17 @@ async def async_setup(hass, config): await component.async_setup(config) component.async_register_entity_service( - SERVICE_TURN_OFF, SWITCH_SERVICE_SCHEMA, + SERVICE_TURN_OFF, ENTITY_SERVICE_SCHEMA, 'async_turn_off' ) component.async_register_entity_service( - SERVICE_TURN_ON, SWITCH_SERVICE_SCHEMA, + SERVICE_TURN_ON, ENTITY_SERVICE_SCHEMA, 'async_turn_on' ) component.async_register_entity_service( - SERVICE_TOGGLE, SWITCH_SERVICE_SCHEMA, + SERVICE_TOGGLE, ENTITY_SERVICE_SCHEMA, 'async_toggle' ) diff --git a/homeassistant/helpers/config_validation.py b/homeassistant/helpers/config_validation.py index 40b06447a2f..60457a9963c 100644 --- a/homeassistant/helpers/config_validation.py +++ b/homeassistant/helpers/config_validation.py @@ -20,7 +20,8 @@ from homeassistant.const import ( CONF_ENTITY_NAMESPACE, CONF_PLATFORM, CONF_SCAN_INTERVAL, CONF_UNIT_SYSTEM_IMPERIAL, CONF_UNIT_SYSTEM_METRIC, CONF_VALUE_TEMPLATE, CONF_TIMEOUT, ENTITY_MATCH_ALL, SUN_EVENT_SUNRISE, SUN_EVENT_SUNSET, - TEMP_CELSIUS, TEMP_FAHRENHEIT, WEEKDAYS, __version__) + TEMP_CELSIUS, TEMP_FAHRENHEIT, WEEKDAYS, __version__, ATTR_AREA_ID, + ATTR_ENTITY_ID) from homeassistant.core import valid_entity_id, split_entity_id from homeassistant.exceptions import TemplateError from homeassistant.helpers.logging import KeywordStyleAdapter @@ -642,6 +643,11 @@ PLATFORM_SCHEMA = vol.Schema({ PLATFORM_SCHEMA_BASE = PLATFORM_SCHEMA.extend({ }, extra=vol.ALLOW_EXTRA) +ENTITY_SERVICE_SCHEMA = vol.Schema({ + vol.Optional(ATTR_ENTITY_ID): comp_entity_ids, + vol.Optional(ATTR_AREA_ID): vol.All(ensure_list, [str]), +}) + EVENT_SCHEMA = vol.Schema({ vol.Optional(CONF_ALIAS): string, vol.Required('event'): string,