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
|
|
|
|
2024-01-07 17:48:23 +01:00
|
|
|
from pylutron import Button, Led, Lutron
|
|
|
|
|
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
|
|
|
|
2024-01-05 22:04:10 +01:00
|
|
|
from . import DOMAIN, LutronData
|
2024-01-05 20:38:02 +01:00
|
|
|
from .entity import LutronDevice
|
2019-03-20 22:56:46 -07:00
|
|
|
|
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.
|
|
|
|
"""
|
2024-01-05 22:04:10 +01:00
|
|
|
entry_data: LutronData = hass.data[DOMAIN][config_entry.entry_id]
|
|
|
|
|
|
|
|
async_add_entities(
|
|
|
|
[
|
|
|
|
LutronScene(area_name, keypad_name, device, led, entry_data.client)
|
|
|
|
for area_name, keypad_name, device, led in entry_data.scenes
|
|
|
|
],
|
|
|
|
True,
|
|
|
|
)
|
2018-12-25 00:33:03 -08:00
|
|
|
|
|
|
|
|
|
|
|
class LutronScene(LutronDevice, Scene):
|
|
|
|
"""Representation of a Lutron Scene."""
|
|
|
|
|
2024-01-07 17:48:23 +01:00
|
|
|
_lutron_device: Button
|
|
|
|
|
|
|
|
def __init__(
|
|
|
|
self,
|
|
|
|
area_name: str,
|
|
|
|
keypad_name: str,
|
|
|
|
lutron_device: Button,
|
|
|
|
lutron_led: Led,
|
|
|
|
controller: Lutron,
|
|
|
|
) -> None:
|
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}"
|