Skip to content

Commit

Permalink
Add target to services.yaml (#46410)
Browse files Browse the repository at this point in the history
Co-authored-by: Franck Nijhof <git@frenck.dev>
  • Loading branch information
bramkragten and frenck committed Feb 16, 2021
1 parent 20d93b4 commit 6986fa4
Show file tree
Hide file tree
Showing 4 changed files with 57 additions and 7 deletions.
20 changes: 17 additions & 3 deletions homeassistant/components/light/services.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,19 @@

turn_on:
description: Turn a light on.
target:
fields:
entity_id:
description: Name(s) of entities to turn on
example: "light.kitchen"
transition:
name: Transition
description: Duration in seconds it takes to get to next state
example: 60
selector:
number:
min: 0
max: 300
step: 1
unit_of_measurement: seconds
mode: slider
rgb_color:
description: Color for the light in RGB-format.
example: "[255, 100, 100]"
Expand All @@ -34,8 +40,16 @@ turn_on:
description: Number between 0..255 indicating brightness, where 0 turns the light off, 1 is the minimum brightness and 255 is the maximum brightness supported by the light.
example: 120
brightness_pct:
name: Brightness
description: Number between 0..100 indicating percentage of full brightness, where 0 turns the light off, 1 is the minimum brightness and 100 is the maximum brightness supported by the light.
example: 47
selector:
number:
min: 0
max: 100
step: 1
unit_of_measurement: "%"
mode: slider
brightness_step:
description: Change brightness by an amount. Should be between -255..255.
example: -25.5
Expand Down
28 changes: 27 additions & 1 deletion homeassistant/components/sonos/services.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@ join:
master:
description: Entity ID of the player that should become the coordinator of the group.
example: "media_player.living_room_sonos"
selector:
entity:
integration: sonos
domain: media_player
entity_id:
description: Name(s) of entities that will join the master.
example: "media_player.living_room_sonos"
Expand Down Expand Up @@ -64,7 +68,13 @@ set_sleep_timer:
sleep_time:
description: Number of seconds to set the timer.
example: "900"

selector:
number:
min: 0
max: 3600
step: 1
unit_of_measurement: seconds
mode: slider
clear_sleep_timer:
description: Clear a Sonos timer.
fields:
Expand All @@ -89,12 +99,18 @@ set_option:
night_sound:
description: Enable Night Sound mode
example: "true"
selector:
boolean:
speech_enhance:
description: Enable Speech Enhancement mode
example: "true"
selector:
boolean:
status_light:
description: Enable Status (LED) Light
example: "true"
selector:
boolean:

play_queue:
description: Starts playing the queue from the first item.
Expand All @@ -109,6 +125,11 @@ play_queue:
queue_position:
description: Position of the song in the queue to start playing from.
example: "0"
selector:
number:
min: 0
max: 100000000
mode: box

remove_from_queue:
description: Removes an item from the queue.
Expand All @@ -123,6 +144,11 @@ remove_from_queue:
queue_position:
description: Position in the queue to remove.
example: "0"
selector:
number:
min: 0
max: 100000000
mode: box

update_alarm:
description: Updates an alarm with new time and volume settings.
Expand Down
8 changes: 6 additions & 2 deletions homeassistant/helpers/service.py
Original file line number Diff line number Diff line change
Expand Up @@ -448,12 +448,16 @@ async def async_get_all_descriptions(
# Don't warn for missing services, because it triggers false
# positives for things like scripts, that register as a service

description = descriptions_cache[cache_key] = {
description = {
"description": yaml_description.get("description", ""),
"target": yaml_description.get("target"),
"fields": yaml_description.get("fields", {}),
}

if "target" in yaml_description:
description["target"] = yaml_description["target"]

descriptions_cache[cache_key] = description

descriptions[domain][service] = description

return descriptions
Expand Down
8 changes: 7 additions & 1 deletion script/hassfest/services.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ def exists(value):
FIELD_SCHEMA = vol.Schema(
{
vol.Required("description"): str,
vol.Optional("name"): str,
vol.Optional("example"): exists,
vol.Optional("default"): exists,
vol.Optional("values"): exists,
Expand All @@ -35,6 +36,9 @@ def exists(value):
SERVICE_SCHEMA = vol.Schema(
{
vol.Required("description"): str,
vol.Optional("target"): vol.Any(
selector.TargetSelector.CONFIG_SCHEMA, None # pylint: disable=no-member
),
vol.Optional("fields"): vol.Schema({str: FIELD_SCHEMA}),
}
)
Expand All @@ -60,7 +64,9 @@ def validate_services(integration: Integration):
"""Validate services."""
# Find if integration uses services
has_services = grep_dir(
integration.path, "**/*.py", r"hass\.services\.(register|async_register)"
integration.path,
"**/*.py",
r"(hass\.services\.(register|async_register))|async_register_entity_service",
)

if not has_services:
Expand Down

0 comments on commit 6986fa4

Please sign in to comment.