Home Assistant Unofficial Reference 2024.12.1
scene.py
Go to the documentation of this file.
1 """Support for deCONZ scenes."""
2 
3 from __future__ import annotations
4 
5 from typing import Any
6 
7 from pydeconz.models.event import EventType
8 
9 from homeassistant.components.scene import DOMAIN as SCENE_DOMAIN, Scene
10 from homeassistant.config_entries import ConfigEntry
11 from homeassistant.core import HomeAssistant, callback
12 from homeassistant.helpers.entity_platform import AddEntitiesCallback
13 
14 from .entity import DeconzSceneMixin
15 from .hub import DeconzHub
16 
17 
19  hass: HomeAssistant,
20  config_entry: ConfigEntry,
21  async_add_entities: AddEntitiesCallback,
22 ) -> None:
23  """Set up scenes for deCONZ integration."""
24  hub = DeconzHub.get_hub(hass, config_entry)
25  hub.entities[SCENE_DOMAIN] = set()
26 
27  @callback
28  def async_add_scene(_: EventType, scene_id: str) -> None:
29  """Add scene from deCONZ."""
30  scene = hub.api.scenes[scene_id]
31  async_add_entities([DeconzScene(scene, hub)])
32 
33  hub.register_platform_add_device_callback(
34  async_add_scene,
35  hub.api.scenes,
36  )
37 
38 
40  """Representation of a deCONZ scene."""
41 
42  TYPE = SCENE_DOMAIN
43 
44  async def async_activate(self, **kwargs: Any) -> None:
45  """Activate the scene."""
46  await self.hub.api.scenes.recall(
47  self._device.group_id,
48  self._device.id,
49  )
None async_activate(self, **Any kwargs)
Definition: scene.py:44
None async_setup_entry(HomeAssistant hass, ConfigEntry config_entry, AddEntitiesCallback async_add_entities)
Definition: scene.py:22