2019-02-14 04:35:12 +00:00
|
|
|
"""Support for Lutron shades."""
|
2022-01-04 10:30:13 +00:00
|
|
|
from __future__ import annotations
|
|
|
|
|
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
|
|
|
|
|
|
|
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
|
|
|
)
|
2022-01-04 10:30:13 +00:00
|
|
|
from homeassistant.core import HomeAssistant
|
|
|
|
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
|
|
|
from homeassistant.helpers.typing import ConfigType, DiscoveryInfoType
|
2019-03-21 05:56:46 +00:00
|
|
|
|
|
|
|
from . import LUTRON_CONTROLLER, LUTRON_DEVICES, LutronDevice
|
2018-01-13 18:11:20 +00:00
|
|
|
|
|
|
|
_LOGGER = logging.getLogger(__name__)
|
|
|
|
|
|
|
|
|
2022-01-04 10:30:13 +00:00
|
|
|
def setup_platform(
|
|
|
|
hass: HomeAssistant,
|
|
|
|
config: ConfigType,
|
|
|
|
add_entities: AddEntitiesCallback,
|
|
|
|
discovery_info: DiscoveryInfoType | None = None,
|
|
|
|
) -> None:
|
2018-01-13 18:11:20 +00:00
|
|
|
"""Set up the Lutron shades."""
|
|
|
|
devs = []
|
2019-07-31 19:25:30 +00:00
|
|
|
for (area_name, device) in hass.data[LUTRON_DEVICES]["cover"]:
|
2018-01-13 18:11:20 +00:00
|
|
|
dev = LutronCover(area_name, device, hass.data[LUTRON_CONTROLLER])
|
|
|
|
devs.append(dev)
|
|
|
|
|
2018-08-24 14:37:30 +00:00
|
|
|
add_entities(devs, 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
|
|
|
|
)
|
2018-01-13 18:11:20 +00:00
|
|
|
|
|
|
|
@property
|
2022-06-25 09:59:56 +00:00
|
|
|
def is_closed(self) -> bool:
|
2018-01-13 18:11:20 +00:00
|
|
|
"""Return if the cover is closed."""
|
|
|
|
return self._lutron_device.last_level() < 1
|
|
|
|
|
|
|
|
@property
|
2022-06-25 09:59:56 +00:00
|
|
|
def current_cover_position(self) -> int:
|
2018-01-13 18:11:20 +00:00
|
|
|
"""Return the current position of cover."""
|
|
|
|
return self._lutron_device.last_level()
|
|
|
|
|
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
|
|
|
|
|
2022-06-27 22:48:56 +00:00
|
|
|
def update(self) -> None:
|
2018-01-13 18:11:20 +00:00
|
|
|
"""Call when forcing a refresh of the device."""
|
2018-01-29 22:37:19 +00:00
|
|
|
# Reading the property (rather than last_level()) fetches value
|
2018-01-13 18:11:20 +00:00
|
|
|
level = self._lutron_device.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
|
2022-06-25 09:59:56 +00:00
|
|
|
def extra_state_attributes(self) -> dict[str, Any]:
|
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}
|