2019-02-14 15:01:46 +00:00
|
|
|
"""Support for HomematicIP Cloud cover devices."""
|
2019-01-22 08:22:46 +00:00
|
|
|
import logging
|
2019-04-25 22:13:07 +00:00
|
|
|
from typing import Optional
|
2019-01-22 08:22:46 +00:00
|
|
|
|
2019-04-23 23:47:31 +00:00
|
|
|
from homematicip.aio.device import AsyncFullFlushShutter
|
|
|
|
|
2019-02-14 15:01:46 +00:00
|
|
|
from homeassistant.components.cover import ATTR_POSITION, CoverDevice
|
2019-04-25 22:13:07 +00:00
|
|
|
from homeassistant.config_entries import ConfigEntry
|
|
|
|
from homeassistant.core import HomeAssistant
|
2019-03-21 05:56:46 +00:00
|
|
|
|
|
|
|
from . import DOMAIN as HMIPC_DOMAIN, HMIPC_HAPID, HomematicipGenericDevice
|
2019-01-22 08:22:46 +00:00
|
|
|
|
|
|
|
_LOGGER = logging.getLogger(__name__)
|
|
|
|
|
2019-02-11 09:20:00 +00:00
|
|
|
HMIP_COVER_OPEN = 0
|
|
|
|
HMIP_COVER_CLOSED = 1
|
|
|
|
|
2019-01-22 08:22:46 +00:00
|
|
|
|
|
|
|
async def async_setup_platform(
|
|
|
|
hass, config, async_add_entities, discovery_info=None):
|
|
|
|
"""Set up the HomematicIP Cloud cover devices."""
|
|
|
|
pass
|
|
|
|
|
|
|
|
|
2019-04-25 22:13:07 +00:00
|
|
|
async def async_setup_entry(hass: HomeAssistant, config_entry: ConfigEntry,
|
|
|
|
async_add_entities) -> None:
|
2019-01-22 08:22:46 +00:00
|
|
|
"""Set up the HomematicIP cover from a config entry."""
|
|
|
|
home = hass.data[HMIPC_DOMAIN][config_entry.data[HMIPC_HAPID]].home
|
|
|
|
devices = []
|
|
|
|
for device in home.devices:
|
|
|
|
if isinstance(device, AsyncFullFlushShutter):
|
|
|
|
devices.append(HomematicipCoverShutter(home, device))
|
|
|
|
|
|
|
|
if devices:
|
|
|
|
async_add_entities(devices)
|
|
|
|
|
|
|
|
|
|
|
|
class HomematicipCoverShutter(HomematicipGenericDevice, CoverDevice):
|
|
|
|
"""Representation of a HomematicIP Cloud cover device."""
|
|
|
|
|
|
|
|
@property
|
2019-04-25 22:13:07 +00:00
|
|
|
def current_cover_position(self) -> int:
|
2019-01-22 08:22:46 +00:00
|
|
|
"""Return current position of cover."""
|
2019-02-18 14:54:23 +00:00
|
|
|
return int((1 - self._device.shutterLevel) * 100)
|
2019-01-22 08:22:46 +00:00
|
|
|
|
|
|
|
async def async_set_cover_position(self, **kwargs):
|
|
|
|
"""Move the cover to a specific position."""
|
|
|
|
position = kwargs[ATTR_POSITION]
|
2019-02-11 09:20:00 +00:00
|
|
|
# HmIP cover is closed:1 -> open:0
|
|
|
|
level = 1 - position / 100.0
|
2019-01-22 08:22:46 +00:00
|
|
|
await self._device.set_shutter_level(level)
|
|
|
|
|
|
|
|
@property
|
2019-04-25 22:13:07 +00:00
|
|
|
def is_closed(self) -> Optional[bool]:
|
2019-01-22 08:22:46 +00:00
|
|
|
"""Return if the cover is closed."""
|
|
|
|
if self._device.shutterLevel is not None:
|
2019-02-11 09:20:00 +00:00
|
|
|
return self._device.shutterLevel == HMIP_COVER_CLOSED
|
2019-01-22 08:22:46 +00:00
|
|
|
return None
|
|
|
|
|
|
|
|
async def async_open_cover(self, **kwargs):
|
|
|
|
"""Open the cover."""
|
2019-02-11 09:20:00 +00:00
|
|
|
await self._device.set_shutter_level(HMIP_COVER_OPEN)
|
2019-01-22 08:22:46 +00:00
|
|
|
|
|
|
|
async def async_close_cover(self, **kwargs):
|
|
|
|
"""Close the cover."""
|
2019-02-11 09:20:00 +00:00
|
|
|
await self._device.set_shutter_level(HMIP_COVER_CLOSED)
|
2019-01-22 08:22:46 +00:00
|
|
|
|
|
|
|
async def async_stop_cover(self, **kwargs):
|
|
|
|
"""Stop the device if in motion."""
|
|
|
|
await self._device.set_shutter_stop()
|