Add scene.apply service (#27298)
* Add scene.apply service * Use return value entity ID validator" * Require entities field in service call * Simplify scene service
This commit is contained in:
1 parent
a51e0d7a5f
commit
f5bd0f29b4
4 files changed
+93
-54
No files matched your search
@@ -1,5 +1,4 @@
|
||||
"""Allow users to set and activate scenes."""
|
||||
import asyncio
|
||||
import importlib
|
||||
import logging
|
||||
|
||||
@@ -7,7 +6,6 @@ import voluptuous as vol
|
||||
|
||||
from homeassistant.core import DOMAIN as HA_DOMAIN
|
||||
from homeassistant.const import CONF_PLATFORM, SERVICE_TURN_ON
|
||||
from homeassistant.helpers.config_validation import ENTITY_SERVICE_SCHEMA
|
||||
from homeassistant.helpers.entity import Entity
|
||||
from homeassistant.helpers.entity_component import EntityComponent
|
||||
from homeassistant.helpers.state import HASS_DOMAIN
|
||||
@@ -69,20 +67,7 @@ async def async_setup(hass, config):
|
||||
HA_DOMAIN, {"platform": "homeasistant", STATES: []}
|
||||
)
|
||||
|
||||
async def async_handle_scene_service(service):
|
||||
"""Handle calls to the switch services."""
|
||||
target_scenes = await component.async_extract_from_service(service)
|
||||
|
||||
tasks = [scene.async_activate() for scene in target_scenes]
|
||||
if tasks:
|
||||
await asyncio.wait(tasks)
|
||||
|
||||
hass.services.async_register(
|
||||
DOMAIN,
|
||||
SERVICE_TURN_ON,
|
||||
async_handle_scene_service,
|
||||
schema=ENTITY_SERVICE_SCHEMA,
|
||||
)
|
||||
component.async_register_entity_service(SERVICE_TURN_ON, {}, "async_activate")
|
||||
|
||||
return True
|
||||
|
||||
|
||||
@@ -5,4 +5,18 @@ turn_on:
|
||||
fields:
|
||||
entity_id:
|
||||
description: Name(s) of scenes to turn on
|
||||
example: 'scene.romantic'
|
||||
example: "scene.romantic"
|
||||
|
||||
reload:
|
||||
description: Reload the scene configuration
|
||||
|
||||
apply:
|
||||
description: Activate a scene. Takes same data as the entities field from a single scene in the config.
|
||||
fields:
|
||||
entities:
|
||||
description: The entities and the state that they need to be.
|
||||
example:
|
||||
light.kitchen: "on"
|
||||
light.ceiling:
|
||||
state: "on"
|
||||
brightness: 80
|
||||
Reference in new issue
Block a user