From c48ef281ab513018bb20e79f496bafd3ad6ec15b Mon Sep 17 00:00:00 2001 From: Steaff Date: Fri, 19 Jan 2018 08:20:05 +0100 Subject: [PATCH] Homematic ip tilt covers (#11650) * add pyhomematic support for ip and tiltable covers * use cached data in current_cover_tilt_position * check for existance not for None * reformatting * check node for LEVEL_2 --- homeassistant/components/cover/homematic.py | 43 ++++++++++++++++++++- 1 file changed, 41 insertions(+), 2 deletions(-) diff --git a/homeassistant/components/cover/homematic.py b/homeassistant/components/cover/homematic.py index 9e3d675cabe..1fa215e5fb9 100644 --- a/homeassistant/components/cover/homematic.py +++ b/homeassistant/components/cover/homematic.py @@ -5,9 +5,11 @@ For more details about this platform, please refer to the documentation at https://home-assistant.io/components/cover.homematic/ """ import logging -from homeassistant.const import STATE_UNKNOWN -from homeassistant.components.cover import CoverDevice, ATTR_POSITION + +from homeassistant.components.cover import CoverDevice, ATTR_POSITION,\ + ATTR_TILT_POSITION from homeassistant.components.homematic import HMDevice, ATTR_DISCOVER_DEVICES +from homeassistant.const import STATE_UNKNOWN _LOGGER = logging.getLogger(__name__) @@ -69,3 +71,40 @@ class HMCover(HMDevice, CoverDevice): """Generate a data dictoinary (self._data) from metadata.""" self._state = "LEVEL" self._data.update({self._state: STATE_UNKNOWN}) + 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)