Home Assistant Unofficial Reference 2024.12.1
scene.py
Go to the documentation of this file.
1 """Support for scenes provided by WMS WebControl pro."""
2 
3 from __future__ import annotations
4 
5 from typing import Any
6 
7 from wmspro.scene import Scene as WMS_Scene
8 
9 from homeassistant.components.scene import Scene
10 from homeassistant.core import HomeAssistant
11 from homeassistant.helpers.device_registry import DeviceInfo
12 from homeassistant.helpers.entity_platform import AddEntitiesCallback
13 
14 from . import WebControlProConfigEntry
15 from .const import ATTRIBUTION, DOMAIN, MANUFACTURER
16 
17 
19  hass: HomeAssistant,
20  config_entry: WebControlProConfigEntry,
21  async_add_entities: AddEntitiesCallback,
22 ) -> None:
23  """Set up the WMS based scenes from a config entry."""
24  hub = config_entry.runtime_data
25 
27  WebControlProScene(config_entry.entry_id, scene)
28  for scene in hub.scenes.values()
29  )
30 
31 
33  """Representation of a WMS based scene."""
34 
35  _attr_attribution = ATTRIBUTION
36  _attr_has_entity_name = True
37 
38  def __init__(self, config_entry_id: str, scene: WMS_Scene) -> None:
39  """Initialize the entity with the configured scene."""
40  super().__init__()
41 
42  # Scene information
43  self._scene_scene = scene
44  self._attr_name_attr_name = scene.name
45  self._attr_unique_id_attr_unique_id = str(scene.id)
46 
47  # Room information
48  room = scene.room
49  room_name = room.name
50  room_id_str = str(room.id)
51  self._attr_device_info_attr_device_info = DeviceInfo(
52  identifiers={(DOMAIN, room_id_str)},
53  manufacturer=MANUFACTURER,
54  model="Room",
55  name=room_name,
56  serial_number=room_id_str,
57  suggested_area=room_name,
58  via_device=(DOMAIN, config_entry_id),
59  configuration_url=f"http://{scene.host}/control",
60  )
61 
62  async def async_activate(self, **kwargs: Any) -> None:
63  """Activate scene. Try to get entities into requested state."""
64  await self._scene_scene()
None __init__(self, str config_entry_id, WMS_Scene scene)
Definition: scene.py:38
None async_setup_entry(HomeAssistant hass, WebControlProConfigEntry config_entry, AddEntitiesCallback async_add_entities)
Definition: scene.py:22