Add transition support to scenes, cleanup blocking parameter (#34434)

This commit is contained in:
Franck Nijhof authored and GitHub committed 2020-04-20 18:07:50 -07:00
1 parent 19be31d13a
commit bc5a2da7b7
66 files changed
+547 -229

No files matched your search

+16 -6
View File
@@ -1,9 +1,12 @@
"""Allow users to set and activate scenes."""
import functools as ft
import importlib
import logging
from typing import Any, Optional
import voluptuous as vol
from homeassistant.components.light import ATTR_TRANSITION
from homeassistant.const import CONF_PLATFORM, SERVICE_TURN_ON
from homeassistant.core import DOMAIN as HA_DOMAIN
from homeassistant.helpers.entity import Entity
@@ -62,7 +65,11 @@ async def async_setup(hass, config):
await component.async_setup(config)
# Ensure Home Assistant platform always loaded.
await component.async_setup_platform(HA_DOMAIN, {"platform": HA_DOMAIN, STATES: []})
component.async_register_entity_service(SERVICE_TURN_ON, {}, "async_activate")
component.async_register_entity_service(
SERVICE_TURN_ON,
{ATTR_TRANSITION: vol.All(vol.Coerce(float), vol.Clamp(min=0, max=6553))},
"async_activate",
)
return True
@@ -81,19 +88,22 @@ class Scene(Entity):
"""A scene is a group of entities and the states we want them to be."""
@property
def should_poll(self):
def should_poll(self) -> bool:
"""No polling needed."""
return False
@property
def state(self):
def state(self) -> Optional[str]:
"""Return the state of the scene."""
return STATE
def activate(self):
def activate(self, **kwargs: Any) -> None:
"""Activate scene. Try to get entities into requested state."""
raise NotImplementedError()
async def async_activate(self):
async def async_activate(self, **kwargs: Any) -> None:
"""Activate scene. Try to get entities into requested state."""
await self.hass.async_add_job(self.activate)
assert self.hass
task = self.hass.async_add_job(ft.partial(self.activate, **kwargs))
if task:
await task
+13 -1
View File
@@ -3,6 +3,11 @@
turn_on:
description: Activate a scene.
fields:
transition:
description:
Transition duration in seconds it takes to bring devices to the state
defined in the scene.
example: 2.5
entity_id:
description: Name(s) of scenes to turn on
example: "scene.romantic"
@@ -11,8 +16,15 @@ 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.
description:
Activate a scene. Takes same data as the entities field from a single scene
in the config.
fields:
transition:
description:
Transition duration in seconds it takes to bring devices to the state
defined in the scene.
example: 2.5
entities:
description: The entities and the state that they need to be.
example: