2019-02-13 21:21:14 +01:00
|
|
|
"""Support for deCONZ covers."""
|
2021-09-29 21:19:21 +02:00
|
|
|
|
|
|
|
from pydeconz.light import Cover
|
|
|
|
|
2018-09-21 19:59:20 +02:00
|
|
|
from homeassistant.components.cover import (
|
2019-07-31 12:25:30 -07:00
|
|
|
ATTR_POSITION,
|
2020-11-24 21:42:11 +01:00
|
|
|
ATTR_TILT_POSITION,
|
2021-02-27 21:09:25 +01:00
|
|
|
DEVICE_CLASS_DAMPER,
|
|
|
|
DEVICE_CLASS_SHADE,
|
2020-09-25 22:49:28 +02:00
|
|
|
DOMAIN,
|
2019-07-31 12:25:30 -07:00
|
|
|
SUPPORT_CLOSE,
|
2020-11-24 21:42:11 +01:00
|
|
|
SUPPORT_CLOSE_TILT,
|
2019-07-31 12:25:30 -07:00
|
|
|
SUPPORT_OPEN,
|
2020-11-24 21:42:11 +01:00
|
|
|
SUPPORT_OPEN_TILT,
|
2019-07-31 12:25:30 -07:00
|
|
|
SUPPORT_SET_POSITION,
|
2020-11-24 21:42:11 +01:00
|
|
|
SUPPORT_SET_TILT_POSITION,
|
2019-12-05 06:17:18 +01:00
|
|
|
SUPPORT_STOP,
|
2020-11-24 21:42:11 +01:00
|
|
|
SUPPORT_STOP_TILT,
|
2020-04-25 18:07:15 +02:00
|
|
|
CoverEntity,
|
2019-07-31 12:25:30 -07:00
|
|
|
)
|
2018-09-21 19:59:20 +02:00
|
|
|
from homeassistant.core import callback
|
|
|
|
from homeassistant.helpers.dispatcher import async_dispatcher_connect
|
|
|
|
|
2019-01-16 08:33:04 +01:00
|
|
|
from .deconz_device import DeconzDevice
|
2019-04-05 02:48:24 +02:00
|
|
|
from .gateway import get_gateway_from_config_entry
|
2019-01-15 19:29:56 +01:00
|
|
|
|
2021-06-23 21:40:34 +02:00
|
|
|
DEVICE_CLASS = {
|
2021-09-29 21:19:21 +02:00
|
|
|
"Level controllable output": DEVICE_CLASS_DAMPER,
|
|
|
|
"Window covering controller": DEVICE_CLASS_SHADE,
|
|
|
|
"Window covering device": DEVICE_CLASS_SHADE,
|
2021-06-23 21:40:34 +02:00
|
|
|
}
|
|
|
|
|
2018-09-21 19:59:20 +02:00
|
|
|
|
|
|
|
async def async_setup_entry(hass, config_entry, async_add_entities):
|
2020-11-23 11:37:11 +01:00
|
|
|
"""Set up covers for deCONZ component."""
|
2019-04-05 02:48:24 +02:00
|
|
|
gateway = get_gateway_from_config_entry(hass, config_entry)
|
2020-09-25 22:49:28 +02:00
|
|
|
gateway.entities[DOMAIN] = set()
|
2018-11-05 16:21:44 +01:00
|
|
|
|
2018-09-21 19:59:20 +02:00
|
|
|
@callback
|
2020-12-02 16:21:27 +01:00
|
|
|
def async_add_cover(lights=gateway.api.lights.values()):
|
2018-09-21 19:59:20 +02:00
|
|
|
"""Add cover from deCONZ."""
|
|
|
|
entities = []
|
2019-04-05 02:48:24 +02:00
|
|
|
|
2018-09-21 19:59:20 +02:00
|
|
|
for light in lights:
|
2020-09-25 22:49:28 +02:00
|
|
|
if (
|
2021-09-29 21:19:21 +02:00
|
|
|
isinstance(light, Cover)
|
2021-09-18 09:05:08 +02:00
|
|
|
and light.unique_id not in gateway.entities[DOMAIN]
|
2020-09-25 22:49:28 +02:00
|
|
|
):
|
2019-08-27 21:06:14 +02:00
|
|
|
entities.append(DeconzCover(light, gateway))
|
2019-04-05 02:48:24 +02:00
|
|
|
|
2020-10-02 11:20:33 +02:00
|
|
|
if entities:
|
2020-10-16 17:14:26 +02:00
|
|
|
async_add_entities(entities)
|
2018-09-21 19:59:20 +02:00
|
|
|
|
2021-04-20 20:20:57 +02:00
|
|
|
config_entry.async_on_unload(
|
2019-07-31 12:25:30 -07:00
|
|
|
async_dispatcher_connect(
|
2021-10-07 12:48:27 +02:00
|
|
|
hass,
|
|
|
|
gateway.signal_new_light,
|
|
|
|
async_add_cover,
|
2019-07-31 12:25:30 -07:00
|
|
|
)
|
|
|
|
)
|
2018-09-21 19:59:20 +02:00
|
|
|
|
2020-12-02 16:21:27 +01:00
|
|
|
async_add_cover()
|
2018-09-21 19:59:20 +02:00
|
|
|
|
|
|
|
|
2020-04-25 18:07:15 +02:00
|
|
|
class DeconzCover(DeconzDevice, CoverEntity):
|
2018-09-21 19:59:20 +02:00
|
|
|
"""Representation of a deCONZ cover."""
|
|
|
|
|
2020-09-25 22:49:28 +02:00
|
|
|
TYPE = DOMAIN
|
|
|
|
|
2019-01-16 08:33:04 +01:00
|
|
|
def __init__(self, device, gateway):
|
2019-02-18 17:43:22 +01:00
|
|
|
"""Set up cover device."""
|
2019-01-16 08:33:04 +01:00
|
|
|
super().__init__(device, gateway)
|
2018-11-05 16:21:44 +01:00
|
|
|
|
2021-06-23 21:40:34 +02:00
|
|
|
self._attr_supported_features = SUPPORT_OPEN
|
|
|
|
self._attr_supported_features |= SUPPORT_CLOSE
|
|
|
|
self._attr_supported_features |= SUPPORT_STOP
|
|
|
|
self._attr_supported_features |= SUPPORT_SET_POSITION
|
2018-09-21 19:59:20 +02:00
|
|
|
|
2020-11-24 21:42:11 +01:00
|
|
|
if self._device.tilt is not None:
|
2021-06-23 21:40:34 +02:00
|
|
|
self._attr_supported_features |= SUPPORT_OPEN_TILT
|
|
|
|
self._attr_supported_features |= SUPPORT_CLOSE_TILT
|
|
|
|
self._attr_supported_features |= SUPPORT_STOP_TILT
|
|
|
|
self._attr_supported_features |= SUPPORT_SET_TILT_POSITION
|
2018-09-21 19:59:20 +02:00
|
|
|
|
2021-06-23 21:40:34 +02:00
|
|
|
self._attr_device_class = DEVICE_CLASS.get(self._device.type)
|
2018-09-21 19:59:20 +02:00
|
|
|
|
|
|
|
@property
|
2020-11-24 21:42:11 +01:00
|
|
|
def current_cover_position(self):
|
|
|
|
"""Return the current position of the cover."""
|
|
|
|
return 100 - self._device.lift
|
|
|
|
|
|
|
|
@property
|
|
|
|
def is_closed(self):
|
|
|
|
"""Return if the cover is closed."""
|
|
|
|
return not self._device.is_open
|
2018-09-21 19:59:20 +02:00
|
|
|
|
|
|
|
async def async_set_cover_position(self, **kwargs):
|
|
|
|
"""Move the cover to a specific position."""
|
2020-11-24 14:47:56 +01:00
|
|
|
position = 100 - kwargs[ATTR_POSITION]
|
2020-11-24 21:42:11 +01:00
|
|
|
await self._device.set_position(lift=position)
|
2018-09-21 19:59:20 +02:00
|
|
|
|
|
|
|
async def async_open_cover(self, **kwargs):
|
|
|
|
"""Open cover."""
|
2020-11-23 11:37:11 +01:00
|
|
|
await self._device.open()
|
2018-09-21 19:59:20 +02:00
|
|
|
|
|
|
|
async def async_close_cover(self, **kwargs):
|
|
|
|
"""Close cover."""
|
2020-11-23 11:37:11 +01:00
|
|
|
await self._device.close()
|
2018-09-21 19:59:20 +02:00
|
|
|
|
2018-10-20 15:13:23 +02:00
|
|
|
async def async_stop_cover(self, **kwargs):
|
|
|
|
"""Stop cover."""
|
2020-11-23 11:37:11 +01:00
|
|
|
await self._device.stop()
|
2020-11-24 21:42:11 +01:00
|
|
|
|
|
|
|
@property
|
|
|
|
def current_cover_tilt_position(self):
|
|
|
|
"""Return the current tilt position of the cover."""
|
|
|
|
if self._device.tilt is not None:
|
|
|
|
return 100 - self._device.tilt
|
2020-11-28 13:11:13 +01:00
|
|
|
return None
|
2020-11-24 21:42:11 +01:00
|
|
|
|
|
|
|
async def async_set_cover_tilt_position(self, **kwargs):
|
|
|
|
"""Tilt the cover to a specific position."""
|
|
|
|
position = 100 - kwargs[ATTR_TILT_POSITION]
|
|
|
|
await self._device.set_position(tilt=position)
|
|
|
|
|
|
|
|
async def async_open_cover_tilt(self, **kwargs):
|
|
|
|
"""Open cover tilt."""
|
|
|
|
await self._device.set_position(tilt=0)
|
|
|
|
|
|
|
|
async def async_close_cover_tilt(self, **kwargs):
|
|
|
|
"""Close cover tilt."""
|
|
|
|
await self._device.set_position(tilt=100)
|
|
|
|
|
|
|
|
async def async_stop_cover_tilt(self, **kwargs):
|
|
|
|
"""Stop cover tilt."""
|
|
|
|
await self._device.stop()
|