2019-02-14 04:35:12 +00:00
|
|
|
"""Support for Lutron shades."""
|
2022-01-04 10:30:13 +00:00
|
|
|
from __future__ import annotations
|
|
|
|
|
2024-01-05 15:39:14 +00:00
|
|
|
from collections.abc import Mapping
|
2018-01-13 18:11:20 +00:00
|
|
|
import logging
|
2022-06-24 04:40:26 +00:00
|
|
|
from typing import Any
|
2018-01-13 18:11:20 +00:00
|
|
|
|
2024-01-07 16:48:23 +00:00
|
|
|
from pylutron import Output
|
|
|
|
|
2018-01-13 18:11:20 +00:00
|
|
|
from homeassistant.components.cover import (
|
2019-07-31 19:25:30 +00:00
|
|
|
ATTR_POSITION,
|
2020-04-25 16:07:15 +00:00
|
|
|
CoverEntity,
|
2022-04-07 07:34:58 +00:00
|
|
|
CoverEntityFeature,
|
2019-07-31 19:25:30 +00:00
|
|
|
)
|
2024-01-05 15:39:14 +00:00
|
|
|
from homeassistant.config_entries import ConfigEntry
|
2022-01-04 10:30:13 +00:00
|
|
|
from homeassistant.core import HomeAssistant
|
|
|
|
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
2019-03-21 05:56:46 +00:00
|
|
|
|
2024-01-05 21:04:10 +00:00
|
|
|
from . import DOMAIN, LutronData
|
2024-01-05 19:38:02 +00:00
|
|
|
from .entity import LutronDevice
|
2018-01-13 18:11:20 +00:00
|
|
|
|
|
|
|
_LOGGER = logging.getLogger(__name__)
|
|
|
|
|
|
|
|
|
2024-01-05 15:39:14 +00:00
|
|
|
async def async_setup_entry(
|
2022-01-04 10:30:13 +00:00
|
|
|
hass: HomeAssistant,
|
2024-01-05 15:39:14 +00:00
|
|
|
config_entry: ConfigEntry,
|
|
|
|
async_add_entities: AddEntitiesCallback,
|
2022-01-04 10:30:13 +00:00
|
|
|
) -> None:
|
2024-01-05 15:39:14 +00:00
|
|
|
"""Set up the Lutron cover platform.
|
2018-01-13 18:11:20 +00:00
|
|
|
|
2024-01-05 15:39:14 +00:00
|
|
|
Adds shades from the Main Repeater associated with the config_entry as
|
|
|
|
cover entities.
|
|
|
|
"""
|
2024-01-05 21:04:10 +00:00
|
|
|
entry_data: LutronData = hass.data[DOMAIN][config_entry.entry_id]
|
|
|
|
async_add_entities(
|
|
|
|
[
|
2024-01-07 16:48:23 +00:00
|
|
|
LutronCover(area_name, device, entry_data.client)
|
2024-01-05 21:04:10 +00:00
|
|
|
for area_name, device in entry_data.covers
|
|
|
|
],
|
|
|
|
True,
|
|
|
|
)
|
2018-01-13 18:11:20 +00:00
|
|
|
|
|
|
|
|
2020-04-25 16:07:15 +00:00
|
|
|
class LutronCover(LutronDevice, CoverEntity):
|
2018-01-13 18:11:20 +00:00
|
|
|
"""Representation of a Lutron shade."""
|
|
|
|
|
2022-04-07 07:34:58 +00:00
|
|
|
_attr_supported_features = (
|
|
|
|
CoverEntityFeature.OPEN
|
|
|
|
| CoverEntityFeature.CLOSE
|
|
|
|
| CoverEntityFeature.SET_POSITION
|
|
|
|
)
|
2024-01-07 16:48:23 +00:00
|
|
|
_lutron_device: Output
|
2024-01-22 14:52:59 +00:00
|
|
|
_attr_name = None
|
2018-01-13 18:11:20 +00:00
|
|
|
|
2022-06-24 04:40:26 +00:00
|
|
|
def close_cover(self, **kwargs: Any) -> None:
|
2018-01-13 18:11:20 +00:00
|
|
|
"""Close the cover."""
|
|
|
|
self._lutron_device.level = 0
|
|
|
|
|
2022-06-24 04:40:26 +00:00
|
|
|
def open_cover(self, **kwargs: Any) -> None:
|
2018-01-13 18:11:20 +00:00
|
|
|
"""Open the cover."""
|
|
|
|
self._lutron_device.level = 100
|
|
|
|
|
2022-06-24 04:40:26 +00:00
|
|
|
def set_cover_position(self, **kwargs: Any) -> None:
|
2018-01-13 18:11:20 +00:00
|
|
|
"""Move the shade to a specific position."""
|
|
|
|
if ATTR_POSITION in kwargs:
|
|
|
|
position = kwargs[ATTR_POSITION]
|
|
|
|
self._lutron_device.level = position
|
|
|
|
|
2024-01-25 11:54:31 +00:00
|
|
|
def _request_state(self) -> None:
|
|
|
|
"""Request the state from the device."""
|
|
|
|
self._lutron_device.level # pylint: disable=pointless-statement
|
|
|
|
|
|
|
|
def _update_attrs(self) -> None:
|
|
|
|
"""Update the state attributes."""
|
|
|
|
level = self._lutron_device.last_level()
|
|
|
|
self._attr_is_closed = level < 1
|
|
|
|
self._attr_current_cover_position = level
|
2019-07-31 19:25:30 +00:00
|
|
|
_LOGGER.debug("Lutron ID: %d updated to %f", self._lutron_device.id, level)
|
2018-01-13 18:11:20 +00:00
|
|
|
|
|
|
|
@property
|
2024-01-05 15:39:14 +00:00
|
|
|
def extra_state_attributes(self) -> Mapping[str, Any] | None:
|
2018-01-13 18:11:20 +00:00
|
|
|
"""Return the state attributes."""
|
2021-01-13 17:59:57 +00:00
|
|
|
return {"lutron_integration_id": self._lutron_device.id}
|