2019-02-13 20:21:14 +00:00
|
|
|
"""Support for Velbus covers."""
|
2017-07-26 12:03:29 +00:00
|
|
|
import logging
|
|
|
|
|
|
|
|
from homeassistant.components.cover import (
|
2020-01-26 13:36:29 +00:00
|
|
|
ATTR_POSITION,
|
2019-07-31 19:25:30 +00:00
|
|
|
SUPPORT_CLOSE,
|
|
|
|
SUPPORT_OPEN,
|
2020-01-26 13:36:29 +00:00
|
|
|
SUPPORT_SET_POSITION,
|
2019-07-31 19:25:30 +00:00
|
|
|
SUPPORT_STOP,
|
2020-04-25 16:07:15 +00:00
|
|
|
CoverEntity,
|
2019-07-31 19:25:30 +00:00
|
|
|
)
|
2017-07-26 12:03:29 +00:00
|
|
|
|
2019-07-29 07:21:26 +00:00
|
|
|
from . import VelbusEntity
|
2019-12-09 08:36:42 +00:00
|
|
|
from .const import DOMAIN
|
2019-03-21 05:56:46 +00:00
|
|
|
|
2017-07-26 12:03:29 +00:00
|
|
|
_LOGGER = logging.getLogger(__name__)
|
|
|
|
|
|
|
|
|
2019-07-29 07:21:26 +00:00
|
|
|
async def async_setup_entry(hass, entry, async_add_entities):
|
2021-09-13 06:22:46 +00:00
|
|
|
"""Set up Velbus switch based on config_entry."""
|
|
|
|
await hass.data[DOMAIN][entry.entry_id]["tsk"]
|
2019-07-31 19:25:30 +00:00
|
|
|
cntrl = hass.data[DOMAIN][entry.entry_id]["cntrl"]
|
2019-07-29 07:21:26 +00:00
|
|
|
entities = []
|
2021-09-13 06:22:46 +00:00
|
|
|
for channel in cntrl.get_all("cover"):
|
|
|
|
entities.append(VelbusCover(channel))
|
2019-07-29 07:21:26 +00:00
|
|
|
async_add_entities(entities)
|
2017-07-26 12:03:29 +00:00
|
|
|
|
|
|
|
|
2020-04-25 16:07:15 +00:00
|
|
|
class VelbusCover(VelbusEntity, CoverEntity):
|
2017-07-26 12:03:29 +00:00
|
|
|
"""Representation a Velbus cover."""
|
|
|
|
|
|
|
|
@property
|
|
|
|
def supported_features(self):
|
|
|
|
"""Flag supported features."""
|
2021-09-13 06:22:46 +00:00
|
|
|
if self._channel.support_position():
|
2020-01-26 13:36:29 +00:00
|
|
|
return SUPPORT_OPEN | SUPPORT_CLOSE | SUPPORT_STOP | SUPPORT_SET_POSITION
|
2017-07-26 12:03:29 +00:00
|
|
|
return SUPPORT_OPEN | SUPPORT_CLOSE | SUPPORT_STOP
|
|
|
|
|
|
|
|
@property
|
|
|
|
def is_closed(self):
|
|
|
|
"""Return if the cover is closed."""
|
2021-09-13 06:22:46 +00:00
|
|
|
return self._channel.is_closed()
|
2017-07-26 12:03:29 +00:00
|
|
|
|
|
|
|
@property
|
|
|
|
def current_cover_position(self):
|
|
|
|
"""Return current position of cover.
|
|
|
|
|
2019-06-30 20:02:07 +00:00
|
|
|
None is unknown, 0 is closed, 100 is fully open
|
2020-01-26 13:36:29 +00:00
|
|
|
Velbus: 100 = closed, 0 = open
|
2017-07-26 12:03:29 +00:00
|
|
|
"""
|
2021-09-13 06:22:46 +00:00
|
|
|
pos = self._channel.get_position()
|
2020-01-26 13:36:29 +00:00
|
|
|
return 100 - pos
|
2017-07-26 12:03:29 +00:00
|
|
|
|
2021-09-13 06:22:46 +00:00
|
|
|
async def async_open_cover(self, **kwargs):
|
2017-07-26 12:03:29 +00:00
|
|
|
"""Open the cover."""
|
2021-09-13 06:22:46 +00:00
|
|
|
await self._channel.open()
|
2017-07-26 12:03:29 +00:00
|
|
|
|
2021-09-13 06:22:46 +00:00
|
|
|
async def async_close_cover(self, **kwargs):
|
2017-07-26 12:03:29 +00:00
|
|
|
"""Close the cover."""
|
2021-09-13 06:22:46 +00:00
|
|
|
await self._channel.close()
|
2017-07-26 12:03:29 +00:00
|
|
|
|
2021-09-13 06:22:46 +00:00
|
|
|
async def async_stop_cover(self, **kwargs):
|
2017-07-26 12:03:29 +00:00
|
|
|
"""Stop the cover."""
|
2021-09-13 06:22:46 +00:00
|
|
|
await self._channel.stop()
|
2020-01-26 13:36:29 +00:00
|
|
|
|
2021-09-13 06:22:46 +00:00
|
|
|
async def async_set_cover_position(self, **kwargs):
|
2020-01-26 13:36:29 +00:00
|
|
|
"""Move the cover to a specific position."""
|
2021-09-13 06:22:46 +00:00
|
|
|
self._channel.set_position(100 - kwargs[ATTR_POSITION])
|