1
mirror of https://github.com/home-assistant/core synced 2024-09-18 19:55:20 +02:00
ha-core/homeassistant/components/supla/cover.py

54 lines
1.5 KiB
Python
Raw Normal View History

"""Support for Supla cover - curtains, rollershutters etc."""
import logging
from pprint import pformat
from homeassistant.components.cover import ATTR_POSITION, CoverDevice
from homeassistant.components.supla import SuplaChannel
_LOGGER = logging.getLogger(__name__)
def setup_platform(hass, config, add_entities, discovery_info=None):
"""Set up the Supla covers."""
if discovery_info is None:
return
2019-07-31 21:25:30 +02:00
_LOGGER.debug("Discovery: %s", pformat(discovery_info))
2019-07-31 21:25:30 +02:00
add_entities([SuplaCover(device) for device in discovery_info])
class SuplaCover(SuplaChannel, CoverDevice):
"""Representation of a Supla Cover."""
@property
def current_cover_position(self):
"""Return current position of cover. 0 is closed, 100 is open."""
2019-07-31 21:25:30 +02:00
state = self.channel_data.get("state")
if state:
2019-07-31 21:25:30 +02:00
return 100 - state["shut"]
return None
def set_cover_position(self, **kwargs):
"""Move the cover to a specific position."""
2019-07-31 21:25:30 +02:00
self.action("REVEAL", percentage=kwargs.get(ATTR_POSITION))
@property
def is_closed(self):
"""Return if the cover is closed."""
if self.current_cover_position is None:
return None
return self.current_cover_position == 0
def open_cover(self, **kwargs):
"""Open the cover."""
2019-07-31 21:25:30 +02:00
self.action("REVEAL")
def close_cover(self, **kwargs):
"""Close the cover."""
2019-07-31 21:25:30 +02:00
self.action("SHUT")
def stop_cover(self, **kwargs):
"""Stop the cover."""
2019-07-31 21:25:30 +02:00
self.action("STOP")