2019-02-14 05:35:12 +01:00
|
|
|
"""Support for Lutron scenes."""
|
2022-01-03 17:17:44 +01:00
|
|
|
from __future__ import annotations
|
|
|
|
|
2020-04-21 03:07:50 +02:00
|
|
|
from typing import Any
|
2018-12-25 00:33:03 -08:00
|
|
|
|
|
|
|
from homeassistant.components.scene import Scene
|
2024-01-05 09:39:14 -06: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
|
2018-12-25 00:33:03 -08:00
|
|
|
|
2019-03-20 22:56:46 -07:00
|
|
|
from . import LUTRON_CONTROLLER, LUTRON_DEVICES, LutronDevice
|
|
|
|
|
2018-12-25 00:33:03 -08:00
|
|
|
|
2024-01-05 09:39:14 -06:00
|
|
|
async def async_setup_entry(
|
2022-01-03 17:17:44 +01:00
|
|
|
hass: HomeAssistant,
|
2024-01-05 09:39:14 -06:00
|
|
|
config_entry: ConfigEntry,
|
|
|
|
async_add_entities: AddEntitiesCallback,
|
2022-01-03 17:17:44 +01:00
|
|
|
) -> None:
|
2024-01-05 09:39:14 -06:00
|
|
|
"""Set up the Lutron scene platform.
|
|
|
|
|
|
|
|
Adds scenes from the Main Repeater associated with the config_entry as
|
|
|
|
scene entities.
|
|
|
|
"""
|
|
|
|
entities = []
|
2019-07-31 12:25:30 -07:00
|
|
|
for scene_data in hass.data[LUTRON_DEVICES]["scene"]:
|
2018-12-25 00:33:03 -08:00
|
|
|
(area_name, keypad_name, device, led) = scene_data
|
2024-01-05 09:39:14 -06:00
|
|
|
entity = LutronScene(
|
2019-07-31 12:25:30 -07:00
|
|
|
area_name, keypad_name, device, led, hass.data[LUTRON_CONTROLLER]
|
|
|
|
)
|
2024-01-05 09:39:14 -06:00
|
|
|
entities.append(entity)
|
|
|
|
async_add_entities(entities, True)
|
2018-12-25 00:33:03 -08:00
|
|
|
|
|
|
|
|
|
|
|
class LutronScene(LutronDevice, Scene):
|
|
|
|
"""Representation of a Lutron Scene."""
|
|
|
|
|
2019-07-31 12:25:30 -07:00
|
|
|
def __init__(self, area_name, keypad_name, lutron_device, lutron_led, controller):
|
2018-12-25 00:33:03 -08:00
|
|
|
"""Initialize the scene/button."""
|
|
|
|
super().__init__(area_name, lutron_device, controller)
|
|
|
|
self._keypad_name = keypad_name
|
|
|
|
self._led = lutron_led
|
|
|
|
|
2020-04-21 03:07:50 +02:00
|
|
|
def activate(self, **kwargs: Any) -> None:
|
2018-12-25 00:33:03 -08:00
|
|
|
"""Activate the scene."""
|
|
|
|
self._lutron_device.press()
|
|
|
|
|
|
|
|
@property
|
2022-09-01 14:14:31 +02:00
|
|
|
def name(self) -> str:
|
2018-12-25 00:33:03 -08:00
|
|
|
"""Return the name of the device."""
|
2020-02-28 12:39:29 +01:00
|
|
|
return f"{self._area_name} {self._keypad_name}: {self._lutron_device.name}"
|