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
pull/25205/head
Paulus Schoutsen 2019-07-15 11:31:53 -07:00
parent 65593e36b1
commit 7dedf173ad
3 changed files with 15 additions and 17 deletions

View File

@ -16,7 +16,7 @@ from homeassistant.const import (
from homeassistant.exceptions import UnknownUser, Unauthorized from homeassistant.exceptions import UnknownUser, Unauthorized
import homeassistant.helpers.config_validation as cv import homeassistant.helpers.config_validation as cv
from homeassistant.helpers.config_validation import ( # noqa 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 import ToggleEntity
from homeassistant.helpers.entity_component import EntityComponent from homeassistant.helpers.entity_component import EntityComponent
from homeassistant.helpers import intent 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 = 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)) VALID_BRIGHTNESS_PCT = vol.All(vol.Coerce(float), vol.Range(min=0, max=100))
LIGHT_TURN_ON_SCHEMA = vol.Schema({ LIGHT_TURN_ON_SCHEMA = ENTITY_SERVICE_SCHEMA.extend({
ATTR_ENTITY_ID: cv.comp_entity_ids,
vol.Exclusive(ATTR_PROFILE, COLOR_GROUP): cv.string, vol.Exclusive(ATTR_PROFILE, COLOR_GROUP): cv.string,
ATTR_TRANSITION: VALID_TRANSITION, ATTR_TRANSITION: VALID_TRANSITION,
ATTR_BRIGHTNESS: VALID_BRIGHTNESS, ATTR_BRIGHTNESS: VALID_BRIGHTNESS,
@ -111,8 +110,7 @@ LIGHT_TURN_ON_SCHEMA = vol.Schema({
ATTR_EFFECT: cv.string, ATTR_EFFECT: cv.string,
}) })
LIGHT_TURN_OFF_SCHEMA = vol.Schema({ LIGHT_TURN_OFF_SCHEMA = ENTITY_SERVICE_SCHEMA.extend({
ATTR_ENTITY_ID: cv.comp_entity_ids,
ATTR_TRANSITION: VALID_TRANSITION, ATTR_TRANSITION: VALID_TRANSITION,
ATTR_FLASH: vol.In([FLASH_SHORT, FLASH_LONG]), ATTR_FLASH: vol.In([FLASH_SHORT, FLASH_LONG]),
}) })

View File

@ -8,11 +8,9 @@ from homeassistant.loader import bind_hass
from homeassistant.helpers.entity_component import EntityComponent from homeassistant.helpers.entity_component import EntityComponent
from homeassistant.helpers.entity import ToggleEntity from homeassistant.helpers.entity import ToggleEntity
from homeassistant.helpers.config_validation import ( # noqa from homeassistant.helpers.config_validation import ( # noqa
PLATFORM_SCHEMA, PLATFORM_SCHEMA_BASE) PLATFORM_SCHEMA, PLATFORM_SCHEMA_BASE, ENTITY_SERVICE_SCHEMA)
import homeassistant.helpers.config_validation as cv
from homeassistant.const import ( from homeassistant.const import (
STATE_ON, SERVICE_TURN_ON, SERVICE_TURN_OFF, SERVICE_TOGGLE, STATE_ON, SERVICE_TURN_ON, SERVICE_TURN_OFF, SERVICE_TOGGLE)
ATTR_ENTITY_ID)
from homeassistant.components import group from homeassistant.components import group
DOMAIN = 'switch' DOMAIN = 'switch'
@ -43,10 +41,6 @@ DEVICE_CLASSES = [
DEVICE_CLASSES_SCHEMA = vol.All(vol.Lower, vol.In(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__) _LOGGER = logging.getLogger(__name__)
@ -67,17 +61,17 @@ async def async_setup(hass, config):
await component.async_setup(config) await component.async_setup(config)
component.async_register_entity_service( component.async_register_entity_service(
SERVICE_TURN_OFF, SWITCH_SERVICE_SCHEMA, SERVICE_TURN_OFF, ENTITY_SERVICE_SCHEMA,
'async_turn_off' 'async_turn_off'
) )
component.async_register_entity_service( component.async_register_entity_service(
SERVICE_TURN_ON, SWITCH_SERVICE_SCHEMA, SERVICE_TURN_ON, ENTITY_SERVICE_SCHEMA,
'async_turn_on' 'async_turn_on'
) )
component.async_register_entity_service( component.async_register_entity_service(
SERVICE_TOGGLE, SWITCH_SERVICE_SCHEMA, SERVICE_TOGGLE, ENTITY_SERVICE_SCHEMA,
'async_toggle' 'async_toggle'
) )

View File

@ -20,7 +20,8 @@ from homeassistant.const import (
CONF_ENTITY_NAMESPACE, CONF_PLATFORM, CONF_SCAN_INTERVAL, CONF_ENTITY_NAMESPACE, CONF_PLATFORM, CONF_SCAN_INTERVAL,
CONF_UNIT_SYSTEM_IMPERIAL, CONF_UNIT_SYSTEM_METRIC, CONF_VALUE_TEMPLATE, CONF_UNIT_SYSTEM_IMPERIAL, CONF_UNIT_SYSTEM_METRIC, CONF_VALUE_TEMPLATE,
CONF_TIMEOUT, ENTITY_MATCH_ALL, SUN_EVENT_SUNRISE, SUN_EVENT_SUNSET, 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.core import valid_entity_id, split_entity_id
from homeassistant.exceptions import TemplateError from homeassistant.exceptions import TemplateError
from homeassistant.helpers.logging import KeywordStyleAdapter from homeassistant.helpers.logging import KeywordStyleAdapter
@ -642,6 +643,11 @@ PLATFORM_SCHEMA = vol.Schema({
PLATFORM_SCHEMA_BASE = PLATFORM_SCHEMA.extend({ PLATFORM_SCHEMA_BASE = PLATFORM_SCHEMA.extend({
}, extra=vol.ALLOW_EXTRA) }, 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({ EVENT_SCHEMA = vol.Schema({
vol.Optional(CONF_ALIAS): string, vol.Optional(CONF_ALIAS): string,
vol.Required('event'): string, vol.Required('event'): string,