1 """Allow users to set and activate scenes."""
3 from __future__
import annotations
8 from typing
import Any, Final, final
10 import voluptuous
as vol
22 DOMAIN: Final =
"scene"
23 DATA_COMPONENT: HassKey[EntityComponent[Scene]] =
HassKey(DOMAIN)
24 STATES: Final =
"states"
28 """Validate platform in config for homeassistant domain."""
29 if CONF_PLATFORM
not in config:
30 config = {CONF_PLATFORM: HOMEASSISTANT_DOMAIN, STATES: config}
36 """Validate it is a valid platform."""
37 platform_name = config[CONF_PLATFORM]
39 platform = importlib.import_module(
40 f
"homeassistant.components.{platform_name}.scene"
43 raise vol.Invalid(
"Invalid platform specified")
from None
45 if not hasattr(platform,
"PLATFORM_SCHEMA"):
48 return platform.PLATFORM_SCHEMA(config)
51 PLATFORM_SCHEMA = vol.Schema(
53 _hass_domain_validator,
54 vol.Schema({vol.Required(CONF_PLATFORM): str}, extra=vol.ALLOW_EXTRA),
57 extra=vol.ALLOW_EXTRA,
63 async
def async_setup(hass: HomeAssistant, config: ConfigType) -> bool:
64 """Set up the scenes."""
65 component = hass.data[DATA_COMPONENT] = EntityComponent[Scene](
66 logging.getLogger(__name__), DOMAIN, hass
69 await component.async_setup(config)
71 hass.async_create_task(
72 component.async_setup_platform(
73 HOMEASSISTANT_DOMAIN, {
"platform": HOMEASSISTANT_DOMAIN, STATES: []}
77 component.async_register_entity_service(
79 {ATTR_TRANSITION: vol.All(vol.Coerce(float), vol.Clamp(min=0, max=6553))},
87 """Set up a config entry."""
92 """Unload a config entry."""
97 """A scene is a group of entities and the states we want them to be."""
99 _attr_should_poll =
False
100 __last_activated: str |
None =
None
105 """Return the state of the scene."""
114 Should not be overridden, handle setting last press timestamp.
121 """Call when the scene is added to hass."""
126 and state.state
is not None
127 and state.state != STATE_UNAVAILABLE
132 """Activate scene. Try to get entities into requested state."""
133 raise NotImplementedError
136 """Activate scene. Try to get entities into requested state."""
137 task = self.
hasshass.async_add_executor_job(ft.partial(self.
activateactivate, **kwargs))
None async_internal_added_to_hass(self)
None activate(self, **Any kwargs)
None _async_activate(self, **Any kwargs)
None async_activate(self, **Any kwargs)
None async_write_ha_state(self)
State|None async_get_last_state(self)
dict[str, Any] _platform_validator(dict[str, Any] config)
bool async_setup_entry(HomeAssistant hass, ConfigEntry entry)
dict[str, Any] _hass_domain_validator(dict[str, Any] config)
bool async_setup(HomeAssistant hass, ConfigType config)
bool async_unload_entry(HomeAssistant hass, ConfigEntry entry)