2019-02-13 20:21:14 +00:00
|
|
|
"""Support for Powerview scenes from a Powerview hub."""
|
2022-01-03 16:17:44 +00:00
|
|
|
from __future__ import annotations
|
|
|
|
|
2020-04-21 01:07:50 +00:00
|
|
|
from typing import Any
|
2016-03-06 14:42:11 +00:00
|
|
|
|
2019-12-04 13:15:39 +00:00
|
|
|
from aiopvapi.resources.scene import Scene as PvScene
|
2017-05-26 20:19:19 +00:00
|
|
|
|
2020-04-29 21:24:57 +00:00
|
|
|
from homeassistant.components.scene import Scene
|
2022-03-08 02:13:00 +00:00
|
|
|
from homeassistant.config_entries import ConfigEntry
|
2022-01-03 16:17:44 +00:00
|
|
|
from homeassistant.core import HomeAssistant
|
|
|
|
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
2020-04-29 21:24:57 +00:00
|
|
|
|
2022-06-21 16:12:11 +00:00
|
|
|
from .const import DOMAIN, ROOM_NAME_UNICODE, STATE_ATTRIBUTE_ROOM_NAME
|
2024-01-08 09:08:52 +00:00
|
|
|
from .coordinator import PowerviewShadeUpdateCoordinator
|
2020-04-29 21:24:57 +00:00
|
|
|
from .entity import HDEntity
|
2024-01-08 09:08:52 +00:00
|
|
|
from .model import PowerviewDeviceInfo, PowerviewEntryData
|
2016-03-06 14:42:11 +00:00
|
|
|
|
|
|
|
|
2022-01-03 16:17:44 +00:00
|
|
|
async def async_setup_entry(
|
|
|
|
hass: HomeAssistant, entry: ConfigEntry, async_add_entities: AddEntitiesCallback
|
|
|
|
) -> None:
|
2020-04-29 21:24:57 +00:00
|
|
|
"""Set up powerview scene entries."""
|
2019-01-04 21:19:06 +00:00
|
|
|
|
2022-06-21 16:12:11 +00:00
|
|
|
pv_entry: PowerviewEntryData = hass.data[DOMAIN][entry.entry_id]
|
2016-03-06 14:42:11 +00:00
|
|
|
|
2024-01-08 09:08:52 +00:00
|
|
|
pvscenes: list[PowerViewScene] = []
|
2022-06-21 16:12:11 +00:00
|
|
|
for raw_scene in pv_entry.scene_data.values():
|
|
|
|
scene = PvScene(raw_scene, pv_entry.api)
|
|
|
|
room_name = pv_entry.room_data.get(scene.room_id, {}).get(ROOM_NAME_UNICODE, "")
|
|
|
|
pvscenes.append(
|
|
|
|
PowerViewScene(pv_entry.coordinator, pv_entry.device_info, room_name, scene)
|
|
|
|
)
|
2018-08-24 14:37:30 +00:00
|
|
|
async_add_entities(pvscenes)
|
2016-03-06 14:42:11 +00:00
|
|
|
|
|
|
|
|
2020-04-29 21:24:57 +00:00
|
|
|
class PowerViewScene(HDEntity, Scene):
|
2016-03-09 10:15:04 +00:00
|
|
|
"""Representation of a Powerview scene."""
|
2016-03-06 14:42:11 +00:00
|
|
|
|
2023-09-02 09:55:19 +00:00
|
|
|
_attr_icon = "mdi:blinds"
|
|
|
|
|
2024-01-08 09:08:52 +00:00
|
|
|
def __init__(
|
|
|
|
self,
|
|
|
|
coordinator: PowerviewShadeUpdateCoordinator,
|
|
|
|
device_info: PowerviewDeviceInfo,
|
|
|
|
room_name: str,
|
|
|
|
scene: PvScene,
|
|
|
|
) -> None:
|
2016-03-09 10:15:04 +00:00
|
|
|
"""Initialize the scene."""
|
2021-02-20 06:17:00 +00:00
|
|
|
super().__init__(coordinator, device_info, room_name, scene.id)
|
2017-10-23 06:34:50 +00:00
|
|
|
self._scene = scene
|
2023-09-02 09:55:19 +00:00
|
|
|
self._attr_name = scene.name
|
|
|
|
self._attr_extra_state_attributes = {STATE_ATTRIBUTE_ROOM_NAME: room_name}
|
2017-01-10 12:21:15 +00:00
|
|
|
|
2020-04-21 01:07:50 +00:00
|
|
|
async def async_activate(self, **kwargs: Any) -> None:
|
2017-05-26 20:19:19 +00:00
|
|
|
"""Activate scene. Try to get entities into requested state."""
|
2019-01-04 21:19:06 +00:00
|
|
|
await self._scene.activate()
|