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-12-28 15:29:14 +00:00
|
|
|
from homematicip.aio.device import (
|
|
|
|
AsyncFullFlushBlind,
|
|
|
|
AsyncFullFlushShutter,
|
|
|
|
AsyncGarageDoorModuleTormatic,
|
2020-06-10 09:34:14 +00:00
|
|
|
AsyncHoermannDrivesModule,
|
2019-12-28 15:29:14 +00:00
|
|
|
)
|
2020-02-19 09:59:49 +00:00
|
|
|
from homematicip.aio.group import AsyncExtendedLinkedShutterGroup
|
2019-12-28 15:29:14 +00:00
|
|
|
from homematicip.base.enums import DoorCommand, DoorState
|
2019-04-23 23:47:31 +00:00
|
|
|
|
2019-07-17 01:05:58 +00:00
|
|
|
from homeassistant.components.cover import (
|
2019-07-31 19:25:30 +00:00
|
|
|
ATTR_POSITION,
|
|
|
|
ATTR_TILT_POSITION,
|
2020-04-25 16:07:15 +00:00
|
|
|
CoverEntity,
|
2019-07-31 19:25:30 +00:00
|
|
|
)
|
2019-04-25 22:13:07 +00:00
|
|
|
from homeassistant.config_entries import ConfigEntry
|
2019-10-23 16:21:49 +00:00
|
|
|
from homeassistant.helpers.typing import HomeAssistantType
|
2019-03-21 05:56:46 +00:00
|
|
|
|
2020-08-25 23:55:55 +00:00
|
|
|
from . import DOMAIN as HMIPC_DOMAIN, HomematicipGenericEntity
|
2020-02-19 09:59:49 +00:00
|
|
|
from .hap import HomematicipHAP
|
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-07-17 01:05:58 +00:00
|
|
|
HMIP_SLATS_OPEN = 0
|
|
|
|
HMIP_SLATS_CLOSED = 1
|
2019-02-11 09:20:00 +00:00
|
|
|
|
2019-01-22 08:22:46 +00:00
|
|
|
|
2019-07-31 19:25:30 +00:00
|
|
|
async def async_setup_entry(
|
2019-10-23 16:21:49 +00:00
|
|
|
hass: HomeAssistantType, config_entry: ConfigEntry, async_add_entities
|
2019-07-31 19:25:30 +00:00
|
|
|
) -> None:
|
2019-01-22 08:22:46 +00:00
|
|
|
"""Set up the HomematicIP cover from a config entry."""
|
2020-01-26 13:54:33 +00:00
|
|
|
hap = hass.data[HMIPC_DOMAIN][config_entry.unique_id]
|
2019-11-25 13:17:14 +00:00
|
|
|
entities = []
|
2019-10-11 14:36:46 +00:00
|
|
|
for device in hap.home.devices:
|
2019-07-17 01:05:58 +00:00
|
|
|
if isinstance(device, AsyncFullFlushBlind):
|
2019-11-25 13:17:14 +00:00
|
|
|
entities.append(HomematicipCoverSlats(hap, device))
|
2019-07-17 01:05:58 +00:00
|
|
|
elif isinstance(device, AsyncFullFlushShutter):
|
2019-11-25 13:17:14 +00:00
|
|
|
entities.append(HomematicipCoverShutter(hap, device))
|
2020-06-10 09:34:14 +00:00
|
|
|
elif isinstance(
|
|
|
|
device, (AsyncHoermannDrivesModule, AsyncGarageDoorModuleTormatic)
|
|
|
|
):
|
|
|
|
entities.append(HomematicipGarageDoorModule(hap, device))
|
2019-01-22 08:22:46 +00:00
|
|
|
|
2020-02-19 09:59:49 +00:00
|
|
|
for group in hap.home.groups:
|
|
|
|
if isinstance(group, AsyncExtendedLinkedShutterGroup):
|
|
|
|
entities.append(HomematicipCoverShutterGroup(hap, group))
|
|
|
|
|
2019-11-25 13:17:14 +00:00
|
|
|
if entities:
|
|
|
|
async_add_entities(entities)
|
2019-01-22 08:22:46 +00:00
|
|
|
|
|
|
|
|
2020-08-25 23:55:55 +00:00
|
|
|
class HomematicipCoverShutter(HomematicipGenericEntity, CoverEntity):
|
|
|
|
"""Representation of the HomematicIP cover shutter."""
|
2019-01-22 08:22:46 +00:00
|
|
|
|
|
|
|
@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."""
|
2020-01-12 04:01:13 +00:00
|
|
|
if self._device.shutterLevel is not None:
|
|
|
|
return int((1 - self._device.shutterLevel) * 100)
|
|
|
|
return None
|
2019-01-22 08:22:46 +00:00
|
|
|
|
2019-11-25 13:17:14 +00:00
|
|
|
async def async_set_cover_position(self, **kwargs) -> None:
|
2019-01-22 08:22:46 +00:00
|
|
|
"""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
|
|
|
|
|
2019-11-25 13:17:14 +00:00
|
|
|
async def async_open_cover(self, **kwargs) -> None:
|
2019-01-22 08:22:46 +00:00
|
|
|
"""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
|
|
|
|
2019-11-25 13:17:14 +00:00
|
|
|
async def async_close_cover(self, **kwargs) -> None:
|
2019-01-22 08:22:46 +00:00
|
|
|
"""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
|
|
|
|
2019-11-25 13:17:14 +00:00
|
|
|
async def async_stop_cover(self, **kwargs) -> None:
|
2019-01-22 08:22:46 +00:00
|
|
|
"""Stop the device if in motion."""
|
|
|
|
await self._device.set_shutter_stop()
|
2019-07-17 01:05:58 +00:00
|
|
|
|
|
|
|
|
2020-04-25 16:07:15 +00:00
|
|
|
class HomematicipCoverSlats(HomematicipCoverShutter, CoverEntity):
|
2020-08-25 23:55:55 +00:00
|
|
|
"""Representation of the HomematicIP cover slats."""
|
2019-07-17 01:05:58 +00:00
|
|
|
|
|
|
|
@property
|
|
|
|
def current_cover_tilt_position(self) -> int:
|
|
|
|
"""Return current tilt position of cover."""
|
2020-01-12 04:01:13 +00:00
|
|
|
if self._device.slatsLevel is not None:
|
|
|
|
return int((1 - self._device.slatsLevel) * 100)
|
|
|
|
return None
|
2019-07-17 01:05:58 +00:00
|
|
|
|
2019-11-25 13:17:14 +00:00
|
|
|
async def async_set_cover_tilt_position(self, **kwargs) -> None:
|
2019-07-17 01:05:58 +00:00
|
|
|
"""Move the cover to a specific tilt position."""
|
|
|
|
position = kwargs[ATTR_TILT_POSITION]
|
|
|
|
# HmIP slats is closed:1 -> open:0
|
|
|
|
level = 1 - position / 100.0
|
|
|
|
await self._device.set_slats_level(level)
|
|
|
|
|
2019-11-25 13:17:14 +00:00
|
|
|
async def async_open_cover_tilt(self, **kwargs) -> None:
|
2019-07-17 01:05:58 +00:00
|
|
|
"""Open the slats."""
|
|
|
|
await self._device.set_slats_level(HMIP_SLATS_OPEN)
|
|
|
|
|
2019-11-25 13:17:14 +00:00
|
|
|
async def async_close_cover_tilt(self, **kwargs) -> None:
|
2019-07-17 01:05:58 +00:00
|
|
|
"""Close the slats."""
|
|
|
|
await self._device.set_slats_level(HMIP_SLATS_CLOSED)
|
|
|
|
|
2019-11-25 13:17:14 +00:00
|
|
|
async def async_stop_cover_tilt(self, **kwargs) -> None:
|
2019-07-17 01:05:58 +00:00
|
|
|
"""Stop the device if in motion."""
|
|
|
|
await self._device.set_shutter_stop()
|
2019-12-28 15:29:14 +00:00
|
|
|
|
|
|
|
|
2020-08-25 23:55:55 +00:00
|
|
|
class HomematicipGarageDoorModule(HomematicipGenericEntity, CoverEntity):
|
|
|
|
"""Representation of the HomematicIP Garage Door Module."""
|
2019-12-28 15:29:14 +00:00
|
|
|
|
|
|
|
@property
|
|
|
|
def current_cover_position(self) -> int:
|
|
|
|
"""Return current position of cover."""
|
|
|
|
door_state_to_position = {
|
|
|
|
DoorState.CLOSED: 0,
|
|
|
|
DoorState.OPEN: 100,
|
|
|
|
DoorState.VENTILATION_POSITION: 10,
|
|
|
|
DoorState.POSITION_UNKNOWN: None,
|
|
|
|
}
|
|
|
|
return door_state_to_position.get(self._device.doorState)
|
|
|
|
|
|
|
|
@property
|
|
|
|
def is_closed(self) -> Optional[bool]:
|
|
|
|
"""Return if the cover is closed."""
|
|
|
|
return self._device.doorState == DoorState.CLOSED
|
|
|
|
|
|
|
|
async def async_open_cover(self, **kwargs) -> None:
|
|
|
|
"""Open the cover."""
|
|
|
|
await self._device.send_door_command(DoorCommand.OPEN)
|
|
|
|
|
|
|
|
async def async_close_cover(self, **kwargs) -> None:
|
|
|
|
"""Close the cover."""
|
|
|
|
await self._device.send_door_command(DoorCommand.CLOSE)
|
|
|
|
|
|
|
|
async def async_stop_cover(self, **kwargs) -> None:
|
|
|
|
"""Stop the cover."""
|
|
|
|
await self._device.send_door_command(DoorCommand.STOP)
|
2020-02-19 09:59:49 +00:00
|
|
|
|
|
|
|
|
2020-04-25 16:07:15 +00:00
|
|
|
class HomematicipCoverShutterGroup(HomematicipCoverSlats, CoverEntity):
|
2020-08-25 23:55:55 +00:00
|
|
|
"""Representation of the HomematicIP cover shutter group."""
|
2020-02-19 09:59:49 +00:00
|
|
|
|
|
|
|
def __init__(self, hap: HomematicipHAP, device, post: str = "ShutterGroup") -> None:
|
|
|
|
"""Initialize switching group."""
|
|
|
|
device.modelType = f"HmIP-{post}"
|
|
|
|
super().__init__(hap, device, post)
|