Add Supla gate (#31643)

* Add support for Supla gate with sensor

* Fix Supla switch module description and state access

* Add docs to methods of Supla gate

* Add missing comma

* Remove unused import

* Sort imports of Supla cover

* Add returning availability for every Supla device

* Use direct access to dict

* Remove deprecated property "hidden"

* Remove unused constant

* Revert using get function on dict
This commit is contained in:
Rocik 2020-02-24 15:34:53 +01:00 committed by GitHub
parent df9363610c
commit d996a4a9a9
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 73 additions and 4 deletions

View file

@ -1,12 +1,19 @@
"""Support for Supla cover - curtains, rollershutters etc."""
"""Support for Supla cover - curtains, rollershutters, entry gate etc."""
import logging
from pprint import pformat
from homeassistant.components.cover import ATTR_POSITION, CoverDevice
from homeassistant.components.cover import (
ATTR_POSITION,
DEVICE_CLASS_GARAGE,
CoverDevice,
)
from homeassistant.components.supla import SuplaChannel
_LOGGER = logging.getLogger(__name__)
SUPLA_SHUTTER = "CONTROLLINGTHEROLLERSHUTTER"
SUPLA_GATE = "CONTROLLINGTHEGATE"
def setup_platform(hass, config, add_entities, discovery_info=None):
"""Set up the Supla covers."""
@ -15,7 +22,14 @@ def setup_platform(hass, config, add_entities, discovery_info=None):
_LOGGER.debug("Discovery: %s", pformat(discovery_info))
add_entities([SuplaCover(device) for device in discovery_info])
entities = []
for device in discovery_info:
device_name = device["function"]["name"]
if device_name == SUPLA_SHUTTER:
entities.append(SuplaCover(device))
elif device_name == SUPLA_GATE:
entities.append(SuplaGateDoor(device))
add_entities(entities)
class SuplaCover(SuplaChannel, CoverDevice):
@ -51,3 +65,38 @@ class SuplaCover(SuplaChannel, CoverDevice):
def stop_cover(self, **kwargs):
"""Stop the cover."""
self.action("STOP")
class SuplaGateDoor(SuplaChannel, CoverDevice):
"""Representation of a Supla gate door."""
@property
def is_closed(self):
"""Return if the gate is closed or not."""
state = self.channel_data.get("state")
if state and "hi" in state:
return state.get("hi")
return None
def open_cover(self, **kwargs) -> None:
"""Open the gate."""
if self.is_closed:
self.action("OPEN_CLOSE")
def close_cover(self, **kwargs) -> None:
"""Close the gate."""
if not self.is_closed:
self.action("OPEN_CLOSE")
def stop_cover(self, **kwargs) -> None:
"""Stop the gate."""
self.action("OPEN_CLOSE")
def toggle(self, **kwargs) -> None:
"""Toggle the gate."""
self.action("OPEN_CLOSE")
@property
def device_class(self):
"""Return the class of this device, from component DEVICE_CLASSES."""
return DEVICE_CLASS_GARAGE