2019-02-13 20:21:14 +00:00
|
|
|
"""Support for Velbus covers."""
|
2017-07-26 12:03:29 +00:00
|
|
|
import logging
|
|
|
|
|
2019-07-30 10:56:40 +00:00
|
|
|
from velbus.util import VelbusException
|
|
|
|
|
2017-07-26 12:03:29 +00:00
|
|
|
from homeassistant.components.cover import (
|
2019-06-30 20:02:07 +00:00
|
|
|
CoverDevice, SUPPORT_CLOSE, SUPPORT_OPEN, SUPPORT_STOP)
|
2017-07-26 12:03:29 +00:00
|
|
|
|
2019-07-29 07:21:26 +00:00
|
|
|
from .const import DOMAIN
|
|
|
|
from . import VelbusEntity
|
2019-03-21 05:56:46 +00:00
|
|
|
|
2017-07-26 12:03:29 +00:00
|
|
|
_LOGGER = logging.getLogger(__name__)
|
|
|
|
|
|
|
|
|
2019-06-30 20:02:07 +00:00
|
|
|
async def async_setup_platform(
|
|
|
|
hass, config, async_add_entities, discovery_info=None):
|
2019-07-29 07:21:26 +00:00
|
|
|
"""Set up Velbus covers."""
|
|
|
|
pass
|
|
|
|
|
|
|
|
|
|
|
|
async def async_setup_entry(hass, entry, async_add_entities):
|
|
|
|
"""Set up Velbus cover based on config_entry."""
|
|
|
|
cntrl = hass.data[DOMAIN][entry.entry_id]['cntrl']
|
|
|
|
modules_data = hass.data[DOMAIN][entry.entry_id]['cover']
|
|
|
|
entities = []
|
|
|
|
for address, channel in modules_data:
|
|
|
|
module = cntrl.get_module(address)
|
|
|
|
entities.append(
|
|
|
|
VelbusCover(module, channel))
|
|
|
|
async_add_entities(entities)
|
2017-07-26 12:03:29 +00:00
|
|
|
|
|
|
|
|
2019-06-30 20:02:07 +00:00
|
|
|
class VelbusCover(VelbusEntity, CoverDevice):
|
2017-07-26 12:03:29 +00:00
|
|
|
"""Representation a Velbus cover."""
|
|
|
|
|
|
|
|
@property
|
|
|
|
def supported_features(self):
|
|
|
|
"""Flag supported features."""
|
|
|
|
return SUPPORT_OPEN | SUPPORT_CLOSE | SUPPORT_STOP
|
|
|
|
|
|
|
|
@property
|
|
|
|
def is_closed(self):
|
|
|
|
"""Return if the cover is closed."""
|
2019-06-30 20:02:07 +00:00
|
|
|
return self._module.is_closed(self._channel)
|
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
|
2017-07-26 12:03:29 +00:00
|
|
|
"""
|
2019-06-30 20:02:07 +00:00
|
|
|
if self._module.is_closed(self._channel):
|
|
|
|
return 0
|
|
|
|
if self._module.is_open(self._channel):
|
|
|
|
return 100
|
2017-07-26 12:03:29 +00:00
|
|
|
return None
|
|
|
|
|
|
|
|
def open_cover(self, **kwargs):
|
|
|
|
"""Open the cover."""
|
2019-07-30 10:56:40 +00:00
|
|
|
try:
|
|
|
|
self._module.open(self._channel)
|
|
|
|
except VelbusException as err:
|
|
|
|
_LOGGER.error('A Velbus error occurred: %s', err)
|
2017-07-26 12:03:29 +00:00
|
|
|
|
|
|
|
def close_cover(self, **kwargs):
|
|
|
|
"""Close the cover."""
|
2019-07-30 10:56:40 +00:00
|
|
|
try:
|
|
|
|
self._module.close(self._channel)
|
|
|
|
except VelbusException as err:
|
|
|
|
_LOGGER.error('A Velbus error occurred: %s', err)
|
2017-07-26 12:03:29 +00:00
|
|
|
|
|
|
|
def stop_cover(self, **kwargs):
|
|
|
|
"""Stop the cover."""
|
2019-07-30 10:56:40 +00:00
|
|
|
try:
|
|
|
|
self._module.stop(self._channel)
|
|
|
|
except VelbusException as err:
|
|
|
|
_LOGGER.error('A Velbus error occurred: %s', err)
|