2019-02-13 21:21:14 +01:00
|
|
|
"""Support for Powerview scenes from a Powerview hub."""
|
2022-01-03 17:17:44 +01:00
|
|
|
from __future__ import annotations
|
|
|
|
|
2020-04-21 03:07:50 +02:00
|
|
|
from typing import Any
|
2016-03-06 15:42:11 +01:00
|
|
|
|
2019-12-04 14:15:39 +01:00
|
|
|
from aiopvapi.resources.scene import Scene as PvScene
|
2017-05-26 22:19:19 +02:00
|
|
|
|
2020-04-29 16:24:57 -05:00
|
|
|
from homeassistant.components.scene import Scene
|
2022-03-08 03:13:00 +01:00
|
|
|
from homeassistant.config_entries import ConfigEntry
|
2022-01-03 17:17:44 +01:00
|
|
|
from homeassistant.core import HomeAssistant
|
|
|
|
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
2020-04-29 16:24:57 -05:00
|
|
|
|
2022-06-22 02:12:11 +10:00
|
|
|
from .const import DOMAIN, ROOM_NAME_UNICODE, STATE_ATTRIBUTE_ROOM_NAME
|
2020-04-29 16:24:57 -05:00
|
|
|
from .entity import HDEntity
|
2022-06-22 02:12:11 +10:00
|
|
|
from .model import PowerviewEntryData
|
2016-03-06 15:42:11 +01:00
|
|
|
|
|
|
|
|
2022-01-03 17:17:44 +01:00
|
|
|
async def async_setup_entry(
|
|
|
|
hass: HomeAssistant, entry: ConfigEntry, async_add_entities: AddEntitiesCallback
|
|
|
|
) -> None:
|
2020-04-29 16:24:57 -05:00
|
|
|
"""Set up powerview scene entries."""
|
2019-01-04 22:19:06 +01:00
|
|
|
|
2022-06-22 02:12:11 +10:00
|
|
|
pv_entry: PowerviewEntryData = hass.data[DOMAIN][entry.entry_id]
|
2016-03-06 15:42:11 +01:00
|
|
|
|
2021-02-19 20:17:00 -10:00
|
|
|
pvscenes = []
|
2022-06-22 02:12:11 +10: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 16:37:30 +02:00
|
|
|
async_add_entities(pvscenes)
|
2016-03-06 15:42:11 +01:00
|
|
|
|
|
|
|
|
2020-04-29 16:24:57 -05:00
|
|
|
class PowerViewScene(HDEntity, Scene):
|
2016-03-09 11:15:04 +01:00
|
|
|
"""Representation of a Powerview scene."""
|
2016-03-06 15:42:11 +01:00
|
|
|
|
2021-02-19 20:17:00 -10:00
|
|
|
def __init__(self, coordinator, device_info, room_name, scene):
|
2016-03-09 11:15:04 +01:00
|
|
|
"""Initialize the scene."""
|
2021-02-19 20:17:00 -10:00
|
|
|
super().__init__(coordinator, device_info, room_name, scene.id)
|
2017-10-23 08:34:50 +02:00
|
|
|
self._scene = scene
|
2016-03-06 15:42:11 +01:00
|
|
|
|
|
|
|
@property
|
|
|
|
def name(self):
|
2016-03-09 11:15:04 +01:00
|
|
|
"""Return the name of the scene."""
|
2017-10-23 08:34:50 +02:00
|
|
|
return self._scene.name
|
2016-03-06 15:42:11 +01:00
|
|
|
|
|
|
|
@property
|
2021-03-11 16:57:47 +01:00
|
|
|
def extra_state_attributes(self):
|
2016-03-09 11:15:04 +01:00
|
|
|
"""Return the state attributes."""
|
2017-05-26 22:19:19 +02:00
|
|
|
return {STATE_ATTRIBUTE_ROOM_NAME: self._room_name}
|
2016-03-06 15:42:11 +01:00
|
|
|
|
2017-01-10 13:21:15 +01:00
|
|
|
@property
|
|
|
|
def icon(self):
|
|
|
|
"""Icon to use in the frontend."""
|
2019-07-31 12:25:30 -07:00
|
|
|
return "mdi:blinds"
|
2017-01-10 13:21:15 +01:00
|
|
|
|
2020-04-21 03:07:50 +02:00
|
|
|
async def async_activate(self, **kwargs: Any) -> None:
|
2017-05-26 22:19:19 +02:00
|
|
|
"""Activate scene. Try to get entities into requested state."""
|
2019-01-04 22:19:06 +01:00
|
|
|
await self._scene.activate()
|