2019-02-14 04:35:12 +00:00
|
|
|
"""Support for Lutron Caseta shades."""
|
2017-05-13 03:17:11 +00:00
|
|
|
|
2022-06-24 04:40:26 +00:00
|
|
|
from typing import Any
|
|
|
|
|
2017-05-13 03:17:11 +00:00
|
|
|
from homeassistant.components.cover import (
|
2019-07-31 19:25:30 +00:00
|
|
|
ATTR_POSITION,
|
2024-03-23 17:48:24 +00:00
|
|
|
ATTR_TILT_POSITION,
|
2024-09-09 19:32:33 +00:00
|
|
|
DOMAIN as COVER_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.core import HomeAssistant
|
|
|
|
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
2019-03-21 05:56:46 +00:00
|
|
|
|
2024-09-17 13:39:11 +00:00
|
|
|
from .entity import LutronCasetaUpdatableEntity
|
2024-07-14 21:26:12 +00:00
|
|
|
from .models import LutronCasetaConfigEntry
|
2017-05-13 03:17:11 +00:00
|
|
|
|
|
|
|
|
2024-09-17 13:39:11 +00:00
|
|
|
class LutronCasetaShade(LutronCasetaUpdatableEntity, CoverEntity):
|
2024-03-23 17:48:24 +00:00
|
|
|
"""Representation of a Lutron shade with open/close functionality."""
|
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
|
2022-06-25 09:59:56 +00:00
|
|
|
def is_closed(self) -> bool:
|
2017-05-13 03:17:11 +00:00
|
|
|
"""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
|
2022-06-25 09:59:56 +00:00
|
|
|
def current_cover_position(self) -> int:
|
2017-08-09 04:57:32 +00:00
|
|
|
"""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
|
|
|
|
2022-06-24 04:40:26 +00:00
|
|
|
async def async_close_cover(self, **kwargs: Any) -> None:
|
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)
|
2022-07-04 19:10:26 +00:00
|
|
|
await self.async_update()
|
2020-10-03 20:06:23 +00:00
|
|
|
self.async_write_ha_state()
|
2017-05-13 03:17:11 +00:00
|
|
|
|
2024-03-23 17:48:24 +00:00
|
|
|
async def async_stop_cover(self, **kwargs: Any) -> None:
|
|
|
|
"""Stop the cover."""
|
|
|
|
await self._smartbridge.stop_cover(self.device_id)
|
|
|
|
|
2022-06-24 04:40:26 +00:00
|
|
|
async def async_open_cover(self, **kwargs: Any) -> None:
|
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)
|
2022-07-04 19:10:26 +00:00
|
|
|
await self.async_update()
|
2020-10-03 20:06:23 +00:00
|
|
|
self.async_write_ha_state()
|
2017-05-13 03:17:11 +00:00
|
|
|
|
2022-06-24 04:40:26 +00:00
|
|
|
async def async_set_cover_position(self, **kwargs: Any) -> None:
|
2017-09-05 09:30:36 +00:00
|
|
|
"""Move the shade to a specific position."""
|
2024-03-23 17:48:24 +00:00
|
|
|
await self._smartbridge.set_value(self.device_id, kwargs[ATTR_POSITION])
|
|
|
|
|
|
|
|
|
2024-09-17 13:39:11 +00:00
|
|
|
class LutronCasetaTiltOnlyBlind(LutronCasetaUpdatableEntity, CoverEntity):
|
2024-03-23 17:48:24 +00:00
|
|
|
"""Representation of a Lutron tilt only blind."""
|
|
|
|
|
|
|
|
_attr_supported_features = (
|
|
|
|
CoverEntityFeature.OPEN_TILT
|
|
|
|
| CoverEntityFeature.CLOSE_TILT
|
|
|
|
| CoverEntityFeature.SET_TILT_POSITION
|
|
|
|
| CoverEntityFeature.OPEN_TILT
|
|
|
|
)
|
|
|
|
_attr_device_class = CoverDeviceClass.BLIND
|
|
|
|
|
|
|
|
@property
|
|
|
|
def is_closed(self) -> bool:
|
|
|
|
"""Return if the blind is closed, either at position 0 or 100."""
|
|
|
|
return self._device["tilt"] == 0 or self._device["tilt"] == 100
|
|
|
|
|
|
|
|
@property
|
|
|
|
def current_cover_tilt_position(self) -> int:
|
|
|
|
"""Return the current tilt position of blind."""
|
|
|
|
return self._device["tilt"]
|
|
|
|
|
|
|
|
async def async_close_cover_tilt(self, **kwargs: Any) -> None:
|
|
|
|
"""Close the blind."""
|
|
|
|
await self._smartbridge.set_tilt(self.device_id, 0)
|
|
|
|
await self.async_update()
|
|
|
|
self.async_write_ha_state()
|
|
|
|
|
|
|
|
async def async_open_cover_tilt(self, **kwargs: Any) -> None:
|
|
|
|
"""Open the blind."""
|
|
|
|
await self._smartbridge.set_tilt(self.device_id, 50)
|
|
|
|
await self.async_update()
|
|
|
|
self.async_write_ha_state()
|
|
|
|
|
|
|
|
async def async_set_cover_tilt_position(self, **kwargs: Any) -> None:
|
|
|
|
"""Move the blind to a specific tilt."""
|
2024-05-14 00:05:12 +00:00
|
|
|
await self._smartbridge.set_tilt(self.device_id, kwargs[ATTR_TILT_POSITION])
|
2024-03-23 17:48:24 +00:00
|
|
|
|
|
|
|
|
|
|
|
PYLUTRON_TYPE_TO_CLASSES = {
|
|
|
|
"SerenaTiltOnlyWoodBlind": LutronCasetaTiltOnlyBlind,
|
|
|
|
"SerenaHoneycombShade": LutronCasetaShade,
|
|
|
|
"SerenaRollerShade": LutronCasetaShade,
|
|
|
|
"TriathlonHoneycombShade": LutronCasetaShade,
|
|
|
|
"TriathlonRollerShade": LutronCasetaShade,
|
|
|
|
"QsWirelessShade": LutronCasetaShade,
|
|
|
|
"QsWirelessHorizontalSheerBlind": LutronCasetaShade,
|
|
|
|
"Shade": LutronCasetaShade,
|
|
|
|
"PalladiomWireFreeShade": LutronCasetaShade,
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
async def async_setup_entry(
|
|
|
|
hass: HomeAssistant,
|
2024-07-14 21:26:12 +00:00
|
|
|
config_entry: LutronCasetaConfigEntry,
|
2024-03-23 17:48:24 +00:00
|
|
|
async_add_entities: AddEntitiesCallback,
|
|
|
|
) -> None:
|
|
|
|
"""Set up the Lutron Caseta cover platform.
|
|
|
|
|
|
|
|
Adds shades from the Caseta bridge associated with the config_entry as
|
|
|
|
cover entities.
|
|
|
|
"""
|
2024-07-14 21:26:12 +00:00
|
|
|
data = config_entry.runtime_data
|
2024-03-23 17:48:24 +00:00
|
|
|
bridge = data.bridge
|
2024-09-09 19:32:33 +00:00
|
|
|
cover_devices = bridge.get_devices_by_domain(COVER_DOMAIN)
|
2024-03-23 17:48:24 +00:00
|
|
|
async_add_entities(
|
|
|
|
# default to standard LutronCasetaCover type if the pylutron type is not yet mapped
|
|
|
|
PYLUTRON_TYPE_TO_CLASSES.get(cover_device["type"], LutronCasetaShade)(
|
|
|
|
cover_device, data
|
|
|
|
)
|
|
|
|
for cover_device in cover_devices
|
|
|
|
)
|