2019-02-14 04:35:12 +00:00
|
|
|
"""Support for Lutron Caseta shades."""
|
2017-05-13 03:17:11 +00:00
|
|
|
import logging
|
|
|
|
|
|
|
|
from homeassistant.components.cover import (
|
2019-07-31 19:25:30 +00:00
|
|
|
ATTR_POSITION,
|
|
|
|
DOMAIN,
|
|
|
|
SUPPORT_CLOSE,
|
|
|
|
SUPPORT_OPEN,
|
|
|
|
SUPPORT_SET_POSITION,
|
2020-04-25 16:07:15 +00:00
|
|
|
CoverEntity,
|
2019-07-31 19:25:30 +00:00
|
|
|
)
|
2019-03-21 05:56:46 +00:00
|
|
|
|
2020-05-11 09:05:13 +00:00
|
|
|
from . import DOMAIN as CASETA_DOMAIN, LutronCasetaDevice
|
2017-05-13 03:17:11 +00:00
|
|
|
|
|
|
|
_LOGGER = logging.getLogger(__name__)
|
|
|
|
|
|
|
|
|
2020-05-11 09:05:13 +00:00
|
|
|
async def async_setup_entry(hass, config_entry, async_add_entities):
|
|
|
|
"""Set up the Lutron Caseta cover platform.
|
|
|
|
|
|
|
|
Adds shades from the Caseta bridge associated with the config_entry as
|
|
|
|
cover entities.
|
|
|
|
"""
|
|
|
|
|
2020-03-22 16:35:01 +00:00
|
|
|
entities = []
|
2020-05-11 09:05:13 +00:00
|
|
|
bridge = hass.data[CASETA_DOMAIN][config_entry.entry_id]
|
2017-09-05 09:30:36 +00:00
|
|
|
cover_devices = bridge.get_devices_by_domain(DOMAIN)
|
2020-05-11 09:05:13 +00:00
|
|
|
|
2017-05-13 03:17:11 +00:00
|
|
|
for cover_device in cover_devices:
|
2020-03-22 16:35:01 +00:00
|
|
|
entity = LutronCasetaCover(cover_device, bridge)
|
|
|
|
entities.append(entity)
|
2017-05-13 03:17:11 +00:00
|
|
|
|
2020-03-22 16:35:01 +00:00
|
|
|
async_add_entities(entities, True)
|
2017-05-13 03:17:11 +00:00
|
|
|
|
|
|
|
|
2020-04-25 16:07:15 +00:00
|
|
|
class LutronCasetaCover(LutronCasetaDevice, CoverEntity):
|
2017-09-05 09:30:36 +00:00
|
|
|
"""Representation of a Lutron shade."""
|
2017-05-13 03:17:11 +00:00
|
|
|
|
|
|
|
@property
|
|
|
|
def supported_features(self):
|
|
|
|
"""Flag supported features."""
|
2017-08-09 04:57:32 +00:00
|
|
|
return SUPPORT_OPEN | SUPPORT_CLOSE | SUPPORT_SET_POSITION
|
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
|
|
|
|
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."""
|
2019-11-26 17:06:14 +00:00
|
|
|
self._smartbridge.set_value(self.device_id, 0)
|
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."""
|
2019-11-26 17:06:14 +00:00
|
|
|
self._smartbridge.set_value(self.device_id, 100)
|
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]
|
2019-11-26 17:06:14 +00:00
|
|
|
self._smartbridge.set_value(self.device_id, position)
|
2017-05-13 03:17:11 +00:00
|
|
|
|
2018-06-30 16:10:59 +00:00
|
|
|
async def async_update(self):
|
2017-05-13 03:17:11 +00:00
|
|
|
"""Call when forcing a refresh of the device."""
|
2019-11-26 17:06:14 +00:00
|
|
|
self._device = self._smartbridge.get_device_by_id(self.device_id)
|
|
|
|
_LOGGER.debug(self._device)
|