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
|
2020-04-29 21:24:57 +00:00
|
|
|
from .entity import HDEntity
|
2022-06-21 16:12:11 +00:00
|
|
|
from .model import 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
|
|
|
|
2021-02-20 06:17:00 +00:00
|
|
|
pvscenes = []
|
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
|
|
|
|
2021-02-20 06:17:00 +00:00
|
|
|
def __init__(self, coordinator, device_info, room_name, scene):
|
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
|
2016-03-06 14:42:11 +00:00
|
|
|
|
|
|
|
@property
|
|
|
|
def name(self):
|
2016-03-09 10:15:04 +00:00
|
|
|
"""Return the name of the scene."""
|
2017-10-23 06:34:50 +00:00
|
|
|
return self._scene.name
|
2016-03-06 14:42:11 +00:00
|
|
|
|
|
|
|
@property
|
2021-03-11 15:57:47 +00:00
|
|
|
def extra_state_attributes(self):
|
2016-03-09 10:15:04 +00:00
|
|
|
"""Return the state attributes."""
|
2017-05-26 20:19:19 +00:00
|
|
|
return {STATE_ATTRIBUTE_ROOM_NAME: self._room_name}
|
2016-03-06 14:42:11 +00:00
|
|
|
|
2017-01-10 12:21:15 +00:00
|
|
|
@property
|
|
|
|
def icon(self):
|
|
|
|
"""Icon to use in the frontend."""
|
2019-07-31 19:25:30 +00:00
|
|
|
return "mdi:blinds"
|
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()
|