Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

HomematicIP add cover FROLL and BROLL devices #19794

Merged
merged 12 commits into from Jan 22, 2019
76 changes: 76 additions & 0 deletions homeassistant/components/cover/homematicip_cloud.py
@@ -0,0 +1,76 @@
"""
Support for HomematicIP Cloud cover.

For more details about this platform, please refer to the documentation at
https://home-assistant.io/components/switch.homematicip_cloud/
"""
import logging

from homeassistant.components.cover import (
worm-ee marked this conversation as resolved.
Show resolved Hide resolved
ATTR_POSITION, ATTR_TILT_POSITION, CoverDevice)
from homeassistant.components.homematicip_cloud import (
HMIPC_HAPID, HomematicipGenericDevice)
from homeassistant.components.homematicip_cloud import DOMAIN as HMIPC_DOMAIN
worm-ee marked this conversation as resolved.
Show resolved Hide resolved

DEPENDENCIES = ['homematicip_cloud']

_LOGGER = logging.getLogger(__name__)


async def async_setup_platform(
hass, config, async_add_entities, discovery_info=None):
"""Set up the HomematicIP Cloud cover devices."""
pass


async def async_setup_entry(hass, config_entry, async_add_entities):
"""Set up the HomematicIP cover from a config entry."""
from homematicip.device import AsyncFullFlushShutter

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."""
worm-ee marked this conversation as resolved.
Show resolved Hide resolved

def __init__(self, home, device):
worm-ee marked this conversation as resolved.
Show resolved Hide resolved
"""Initialize the cover device."""
super().__init__(home, device)

@property
def current_cover_position(self):
"""Return current position of cover."""
return int(self._device.shutterLevel * 100)

def set_cover_position(self, **kwargs):
"""Move the cover to a specific position."""
if ATTR_POSITION in kwargs:
worm-ee marked this conversation as resolved.
Show resolved Hide resolved
position = float(kwargs[ATTR_POSITION])
worm-ee marked this conversation as resolved.
Show resolved Hide resolved
position = min(100, max(0, position))
worm-ee marked this conversation as resolved.
Show resolved Hide resolved
level = position / 100.0
self._device.set_shutter_level(level)

@property
def is_closed(self):
"""Return if the cover is closed."""
if self._device.shutterLevel is not None:
return self._device.shutterLevel == 0

worm-ee marked this conversation as resolved.
Show resolved Hide resolved
def open_cover(self, **kwargs):
"""Open the cover."""
self._device.set_shutter_level(1)

def close_cover(self, **kwargs):
"""Close the cover."""
self._device.set_shutter_level(0)

def stop_cover(self, **kwargs):
"""Stop the device if in motion."""
self._device.set_shutter_stop()