Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions homeassistant/components/homeassistant/scene.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,8 @@ def _convert_states(states):
return result


CONF_SCENE_ID = "scene_id"

STATES_SCHEMA = vol.All(dict, _convert_states)

PLATFORM_SCHEMA = vol.Schema(
Expand All @@ -72,7 +74,12 @@ def _convert_states(states):
extra=vol.ALLOW_EXTRA,
)

CREATE_SCENE_SCHEMA = vol.Schema(
{vol.Required(CONF_SCENE_ID): cv.slug, vol.Required(CONF_ENTITIES): STATES_SCHEMA}
)

SERVICE_APPLY = "apply"
SERVICE_CREATE = "create"
SCENECONFIG = namedtuple("SceneConfig", [CONF_NAME, STATES])
_LOGGER = logging.getLogger(__name__)

Expand Down Expand Up @@ -129,6 +136,18 @@ async def apply_service(call):
vol.Schema({vol.Required(CONF_ENTITIES): STATES_SCHEMA}),
)

async def create_service(call):
"""Create a scene."""
async_add_entities(
Comment thread
Santobert marked this conversation as resolved.
Outdated
HomeAssistantScene(
hass, SCENECONFIG(call.data[CONF_SCENE_ID], call.data[CONF_ENTITIES])
)
)

hass.services.async_register(
SCENE_DOMAIN, SERVICE_CREATE, create_service, CREATE_SCENE_SCHEMA
)


def _process_scenes_config(hass, async_add_entities, config):
"""Process multiple scenes and add them."""
Expand Down
14 changes: 14 additions & 0 deletions homeassistant/components/scene/services.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -20,3 +20,17 @@ apply:
light.ceiling:
state: "on"
brightness: 80

create:
description: Creates a new scene.
fields:
scene_id:
description: The entity_id of the new scene.
example: all_lights
entities:
description: The entities to control with the scene.
example:
Comment thread
Santobert marked this conversation as resolved.
light.tv_back_light: "on"
light.ceiling:
state: "on"
brightness: 200
6 changes: 6 additions & 0 deletions tests/components/homeassistant/test_scene.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,3 +51,9 @@ async def test_apply_service(hass):
state = hass.states.get("light.bed_light")
assert state.state == "on"
assert state.attributes["brightness"] == 50


async def test_create_service(hass):
"""Test the create service."""
# TODO
pass