mirror of
https://github.com/home-assistant/core.git
synced 2026-05-30 20:24:21 +01:00
d766aae436
Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> Co-authored-by: frenck <195327+frenck@users.noreply.github.com>
56 lines
1.6 KiB
Python
56 lines
1.6 KiB
Python
"""Support for Vera scenes."""
|
|
|
|
from typing import Any
|
|
|
|
import pyvera as veraApi
|
|
|
|
from homeassistant.components.scene import Scene
|
|
from homeassistant.core import HomeAssistant
|
|
from homeassistant.helpers.entity_platform import AddConfigEntryEntitiesCallback
|
|
from homeassistant.util import slugify
|
|
|
|
from .common import ControllerData, VeraConfigEntry
|
|
from .const import VERA_ID_FORMAT
|
|
|
|
|
|
async def async_setup_entry(
|
|
hass: HomeAssistant,
|
|
entry: VeraConfigEntry,
|
|
async_add_entities: AddConfigEntryEntitiesCallback,
|
|
) -> None:
|
|
"""Set up the sensor config entry."""
|
|
controller_data = entry.runtime_data
|
|
async_add_entities(
|
|
[VeraScene(device, controller_data) for device in controller_data.scenes], True
|
|
)
|
|
|
|
|
|
class VeraScene(Scene):
|
|
"""Representation of a Vera scene entity."""
|
|
|
|
def __init__(
|
|
self, vera_scene: veraApi.VeraScene, controller_data: ControllerData
|
|
) -> None:
|
|
"""Initialize the scene."""
|
|
self.vera_scene = vera_scene
|
|
self.controller = controller_data.controller
|
|
|
|
self._attr_name = self.vera_scene.name
|
|
# Append device id to prevent name clashes in HA.
|
|
self.vera_id = VERA_ID_FORMAT.format(
|
|
slugify(vera_scene.name), vera_scene.scene_id
|
|
)
|
|
|
|
def update(self) -> None:
|
|
"""Update the scene status."""
|
|
self.vera_scene.refresh()
|
|
|
|
def activate(self, **kwargs: Any) -> None:
|
|
"""Activate the scene."""
|
|
self.vera_scene.activate()
|
|
|
|
@property
|
|
def extra_state_attributes(self) -> dict[str, Any] | None:
|
|
"""Return the state attributes of the scene."""
|
|
return {"vera_scene_id": self.vera_scene.vera_scene_id}
|