2019-02-14 04:35:12 +00:00
|
|
|
"""Support for Lutron Caseta shades."""
|
2017-05-13 03:17:11 +00:00
|
|
|
|
|
|
|
from homeassistant.components.cover import (
|
2019-07-31 19:25:30 +00:00
|
|
|
ATTR_POSITION,
|
|
|
|
DOMAIN,
|
2021-12-15 14:17:18 +00:00
|
|
|
CoverDeviceClass,
|
2020-04-25 16:07:15 +00:00
|
|
|
CoverEntity,
|
2022-04-07 16:05:59 +00:00
|
|
|
CoverEntityFeature,
|
2019-07-31 19:25:30 +00:00
|
|
|
)
|
2022-01-03 14:13:18 +00:00
|
|
|
from homeassistant.config_entries import ConfigEntry
|
|
|
|
from homeassistant.core import HomeAssistant
|
|
|
|
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
2019-03-21 05:56:46 +00:00
|
|
|
|
2022-05-18 20:35:35 +00:00
|
|
|
from . import LutronCasetaDeviceUpdatableEntity
|
2021-01-26 22:32:08 +00:00
|
|
|
from .const import BRIDGE_DEVICE, BRIDGE_LEAP, DOMAIN as CASETA_DOMAIN
|
2017-05-13 03:17:11 +00:00
|
|
|
|
|
|
|
|
2022-01-03 14:13:18 +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 cover platform.
|
|
|
|
|
|
|
|
Adds shades from the Caseta bridge associated with the config_entry as
|
|
|
|
cover entities.
|
|
|
|
"""
|
2021-01-26 22:32:08 +00:00
|
|
|
data = hass.data[CASETA_DOMAIN][config_entry.entry_id]
|
|
|
|
bridge = data[BRIDGE_LEAP]
|
|
|
|
bridge_device = data[BRIDGE_DEVICE]
|
2017-09-05 09:30:36 +00:00
|
|
|
cover_devices = bridge.get_devices_by_domain(DOMAIN)
|
2022-05-18 20:35:35 +00:00
|
|
|
async_add_entities(
|
|
|
|
LutronCasetaCover(cover_device, bridge, bridge_device)
|
|
|
|
for cover_device in cover_devices
|
|
|
|
)
|
2017-05-13 03:17:11 +00:00
|
|
|
|
|
|
|
|
2022-05-18 20:35:35 +00:00
|
|
|
class LutronCasetaCover(LutronCasetaDeviceUpdatableEntity, CoverEntity):
|
2017-09-05 09:30:36 +00:00
|
|
|
"""Representation of a Lutron shade."""
|
2017-05-13 03:17:11 +00:00
|
|
|
|
2022-04-07 16:05:59 +00:00
|
|
|
_attr_supported_features = (
|
|
|
|
CoverEntityFeature.OPEN
|
|
|
|
| CoverEntityFeature.CLOSE
|
|
|
|
| CoverEntityFeature.STOP
|
|
|
|
| CoverEntityFeature.SET_POSITION
|
|
|
|
)
|
2022-05-18 20:35:35 +00:00
|
|
|
_attr_device_class = CoverDeviceClass.SHADE
|
2017-05-13 03:17:11 +00:00
|
|
|
|
|
|
|
@property
|
|
|
|
def is_closed(self):
|
|
|
|
"""Return if the cover is closed."""
|
2019-11-26 17:06:14 +00:00
|
|
|
return self._device["current_state"] < 1
|
2017-05-13 03:17:11 +00:00
|
|
|
|
2017-08-09 04:57:32 +00:00
|
|
|
@property
|
|
|
|
def current_cover_position(self):
|
|
|
|
"""Return the current position of cover."""
|
2019-11-26 17:06:14 +00:00
|
|
|
return self._device["current_state"]
|
2017-08-09 04:57:32 +00:00
|
|
|
|
2020-10-03 20:06:23 +00:00
|
|
|
async def async_stop_cover(self, **kwargs):
|
|
|
|
"""Top the cover."""
|
|
|
|
await self._smartbridge.stop_cover(self.device_id)
|
|
|
|
|
2018-06-30 16:10:59 +00:00
|
|
|
async def async_close_cover(self, **kwargs):
|
2017-05-13 03:17:11 +00:00
|
|
|
"""Close the cover."""
|
2020-10-03 20:06:23 +00:00
|
|
|
await self._smartbridge.lower_cover(self.device_id)
|
|
|
|
self.async_update()
|
|
|
|
self.async_write_ha_state()
|
2017-05-13 03:17:11 +00:00
|
|
|
|
2018-06-30 16:10:59 +00:00
|
|
|
async def async_open_cover(self, **kwargs):
|
2017-05-13 03:17:11 +00:00
|
|
|
"""Open the cover."""
|
2020-10-03 20:06:23 +00:00
|
|
|
await self._smartbridge.raise_cover(self.device_id)
|
|
|
|
self.async_update()
|
|
|
|
self.async_write_ha_state()
|
2017-05-13 03:17:11 +00:00
|
|
|
|
2018-06-30 16:10:59 +00:00
|
|
|
async def async_set_cover_position(self, **kwargs):
|
2017-09-05 09:30:36 +00:00
|
|
|
"""Move the shade to a specific position."""
|
|
|
|
if ATTR_POSITION in kwargs:
|
|
|
|
position = kwargs[ATTR_POSITION]
|
2020-10-03 20:06:23 +00:00
|
|
|
await self._smartbridge.set_value(self.device_id, position)
|