Add transition support to scenes, cleanup blocking parameter (#34434)
This commit is contained in:
1 parent
19be31d13a
commit
bc5a2da7b7
66 files changed
+547
-229
No files matched your search
@@ -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
|
||||
Reference in new issue
Block a user