2019-02-14 04:35:12 +00:00
|
|
|
"""Support for Lutron Caseta scenes."""
|
2020-04-21 01:07:50 +00:00
|
|
|
from typing import Any
|
2017-07-29 16:07:28 +00:00
|
|
|
|
2022-06-13 03:14:19 +00:00
|
|
|
from pylutron_caseta.smartbridge import Smartbridge
|
|
|
|
|
2017-11-04 19:04:05 +00:00
|
|
|
from homeassistant.components.scene import Scene
|
2022-01-03 16:17:44 +00:00
|
|
|
from homeassistant.config_entries import ConfigEntry
|
|
|
|
from homeassistant.core import HomeAssistant
|
2022-06-13 03:14:19 +00:00
|
|
|
from homeassistant.helpers.entity import DeviceInfo
|
2022-01-03 16:17:44 +00:00
|
|
|
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
2017-07-29 16:07:28 +00:00
|
|
|
|
2022-06-15 06:32:38 +00:00
|
|
|
from .const import DOMAIN as CASETA_DOMAIN
|
|
|
|
from .models import LutronCasetaData
|
2022-06-13 03:14:19 +00:00
|
|
|
from .util import serial_to_unique_id
|
2019-03-21 05:56:46 +00:00
|
|
|
|
2017-07-29 16:07:28 +00:00
|
|
|
|
2022-01-03 16:17:44 +00:00
|
|
|
async def async_setup_entry(
|
|
|
|
hass: HomeAssistant,
|
|
|
|
config_entry: ConfigEntry,
|
|
|
|
async_add_entities: AddEntitiesCallback,
|
|
|
|
) -> None:
|
2020-05-11 09:05:13 +00:00
|
|
|
"""Set up the Lutron Caseta scene platform.
|
|
|
|
|
|
|
|
Adds scenes from the Caseta bridge associated with the config_entry as
|
|
|
|
scene entities.
|
|
|
|
"""
|
2022-06-15 06:32:38 +00:00
|
|
|
data: LutronCasetaData = hass.data[CASETA_DOMAIN][config_entry.entry_id]
|
|
|
|
bridge = data.bridge
|
2017-07-29 16:07:28 +00:00
|
|
|
scenes = bridge.get_scenes()
|
2022-10-09 18:39:12 +00:00
|
|
|
async_add_entities(LutronCasetaScene(scenes[scene], data) for scene in scenes)
|
2017-07-29 16:07:28 +00:00
|
|
|
|
|
|
|
|
|
|
|
class LutronCasetaScene(Scene):
|
|
|
|
"""Representation of a Lutron Caseta scene."""
|
|
|
|
|
2022-10-09 18:39:12 +00:00
|
|
|
def __init__(self, scene, data):
|
2017-07-29 16:07:28 +00:00
|
|
|
"""Initialize the Lutron Caseta scene."""
|
2019-07-31 19:25:30 +00:00
|
|
|
self._scene_id = scene["scene_id"]
|
2022-10-09 18:39:12 +00:00
|
|
|
self._bridge: Smartbridge = data.bridge
|
|
|
|
bridge_unique_id = serial_to_unique_id(data.bridge_device["serial"])
|
2022-06-13 03:14:19 +00:00
|
|
|
self._attr_device_info = DeviceInfo(
|
2022-10-09 18:39:12 +00:00
|
|
|
identifiers={(CASETA_DOMAIN, data.bridge_device["serial"])},
|
2022-06-13 03:14:19 +00:00
|
|
|
)
|
2022-10-13 00:26:54 +00:00
|
|
|
self._attr_name = scene["name"]
|
2022-06-13 03:14:19 +00:00
|
|
|
self._attr_unique_id = f"scene_{bridge_unique_id}_{self._scene_id}"
|
2017-07-29 16:07:28 +00:00
|
|
|
|
2020-04-21 01:07:50 +00:00
|
|
|
async def async_activate(self, **kwargs: Any) -> None:
|
2017-07-29 16:07:28 +00:00
|
|
|
"""Activate the scene."""
|
2020-10-03 20:06:23 +00:00
|
|
|
await self._bridge.activate_scene(self._scene_id)
|