2019-02-14 15:01:46 +00:00
|
|
|
"""Support for HomeMatic covers."""
|
2016-08-24 01:23:18 +00:00
|
|
|
import logging
|
2018-01-19 07:20:05 +00:00
|
|
|
|
2018-08-21 19:25:16 +00:00
|
|
|
from homeassistant.components.cover import (
|
|
|
|
ATTR_POSITION, ATTR_TILT_POSITION, CoverDevice)
|
2018-01-19 07:20:05 +00:00
|
|
|
from homeassistant.const import STATE_UNKNOWN
|
2016-08-24 01:23:18 +00:00
|
|
|
|
2019-03-21 05:56:46 +00:00
|
|
|
from . import ATTR_DISCOVER_DEVICES, HMDevice
|
|
|
|
|
2016-08-24 01:23:18 +00:00
|
|
|
_LOGGER = logging.getLogger(__name__)
|
|
|
|
|
|
|
|
DEPENDENCIES = ['homematic']
|
|
|
|
|
|
|
|
|
2018-08-24 14:37:30 +00:00
|
|
|
def setup_platform(hass, config, add_entities, discovery_info=None):
|
2017-04-30 05:04:49 +00:00
|
|
|
"""Set up the platform."""
|
2016-08-24 01:23:18 +00:00
|
|
|
if discovery_info is None:
|
|
|
|
return
|
|
|
|
|
2017-02-20 16:07:33 +00:00
|
|
|
devices = []
|
2017-07-06 06:30:01 +00:00
|
|
|
for conf in discovery_info[ATTR_DISCOVER_DEVICES]:
|
2017-08-31 19:16:44 +00:00
|
|
|
new_device = HMCover(conf)
|
2017-02-20 16:07:33 +00:00
|
|
|
devices.append(new_device)
|
|
|
|
|
2018-08-24 14:37:30 +00:00
|
|
|
add_entities(devices)
|
2016-08-24 01:23:18 +00:00
|
|
|
|
|
|
|
|
2016-11-29 19:53:02 +00:00
|
|
|
class HMCover(HMDevice, CoverDevice):
|
2017-06-10 08:08:36 +00:00
|
|
|
"""Representation a HomeMatic Cover."""
|
2016-08-24 01:23:18 +00:00
|
|
|
|
|
|
|
@property
|
|
|
|
def current_cover_position(self):
|
|
|
|
"""
|
|
|
|
Return current position of cover.
|
|
|
|
|
|
|
|
None is unknown, 0 is closed, 100 is fully open.
|
|
|
|
"""
|
2017-02-14 22:19:57 +00:00
|
|
|
return int(self._hm_get_state() * 100)
|
2016-08-24 01:23:18 +00:00
|
|
|
|
|
|
|
def set_cover_position(self, **kwargs):
|
|
|
|
"""Move the cover to a specific position."""
|
2017-02-14 22:19:57 +00:00
|
|
|
if ATTR_POSITION in kwargs:
|
|
|
|
position = float(kwargs[ATTR_POSITION])
|
|
|
|
position = min(100, max(0, position))
|
|
|
|
level = position / 100.0
|
|
|
|
self._hmdevice.set_level(level, self._channel)
|
2016-08-24 01:23:18 +00:00
|
|
|
|
|
|
|
@property
|
|
|
|
def is_closed(self):
|
|
|
|
"""Return if the cover is closed."""
|
|
|
|
if self.current_cover_position is not None:
|
2017-07-06 06:30:01 +00:00
|
|
|
return self.current_cover_position == 0
|
2016-08-24 01:23:18 +00:00
|
|
|
|
|
|
|
def open_cover(self, **kwargs):
|
|
|
|
"""Open the cover."""
|
2017-02-14 22:19:57 +00:00
|
|
|
self._hmdevice.move_up(self._channel)
|
2016-08-24 01:23:18 +00:00
|
|
|
|
|
|
|
def close_cover(self, **kwargs):
|
|
|
|
"""Close the cover."""
|
2017-02-14 22:19:57 +00:00
|
|
|
self._hmdevice.move_down(self._channel)
|
2016-08-24 01:23:18 +00:00
|
|
|
|
|
|
|
def stop_cover(self, **kwargs):
|
|
|
|
"""Stop the device if in motion."""
|
2017-02-14 22:19:57 +00:00
|
|
|
self._hmdevice.stop(self._channel)
|
2016-08-24 01:23:18 +00:00
|
|
|
|
|
|
|
def _init_data_struct(self):
|
2018-01-29 22:37:19 +00:00
|
|
|
"""Generate a data dictionary (self._data) from metadata."""
|
2016-08-24 01:23:18 +00:00
|
|
|
self._state = "LEVEL"
|
|
|
|
self._data.update({self._state: STATE_UNKNOWN})
|
2018-01-19 07:20:05 +00:00
|
|
|
if "LEVEL_2" in self._hmdevice.WRITENODE:
|
|
|
|
self._data.update(
|
|
|
|
{'LEVEL_2': STATE_UNKNOWN})
|
|
|
|
|
|
|
|
@property
|
|
|
|
def current_cover_tilt_position(self):
|
|
|
|
"""Return current position of cover tilt.
|
|
|
|
|
|
|
|
None is unknown, 0 is closed, 100 is fully open.
|
|
|
|
"""
|
|
|
|
if 'LEVEL_2' not in self._data:
|
|
|
|
return None
|
|
|
|
|
|
|
|
return int(self._data.get('LEVEL_2', 0) * 100)
|
|
|
|
|
|
|
|
def set_cover_tilt_position(self, **kwargs):
|
|
|
|
"""Move the cover tilt to a specific position."""
|
|
|
|
if "LEVEL_2" in self._data and ATTR_TILT_POSITION in kwargs:
|
|
|
|
position = float(kwargs[ATTR_TILT_POSITION])
|
|
|
|
position = min(100, max(0, position))
|
|
|
|
level = position / 100.0
|
|
|
|
self._hmdevice.set_cover_tilt_position(level, self._channel)
|
|
|
|
|
|
|
|
def open_cover_tilt(self, **kwargs):
|
|
|
|
"""Open the cover tilt."""
|
|
|
|
if "LEVEL_2" in self._data:
|
|
|
|
self._hmdevice.open_slats()
|
|
|
|
|
|
|
|
def close_cover_tilt(self, **kwargs):
|
|
|
|
"""Close the cover tilt."""
|
|
|
|
if "LEVEL_2" in self._data:
|
|
|
|
self._hmdevice.close_slats()
|
|
|
|
|
|
|
|
def stop_cover_tilt(self, **kwargs):
|
|
|
|
"""Stop cover tilt."""
|
|
|
|
if "LEVEL_2" in self._data:
|
|
|
|
self.stop_cover(**kwargs)
|