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

@ -18,8 +18,10 @@ CONF_SERVERS = "servers"
SUPLA_FUNCTION_HA_CMP_MAP = {
"CONTROLLINGTHEROLLERSHUTTER": "cover",
"CONTROLLINGTHEGATE": "cover",
"LIGHTSWITCH": "switch",
}
SUPLA_FUNCTION_NONE = "NONE"
SUPLA_CHANNELS = "supla_channels"
SUPLA_SERVERS = "supla_servers"
@ -86,6 +88,14 @@ def discover_devices(hass, hass_config):
for channel in server.get_channels(include=["iodevice"]):
channel_function = channel["function"]["name"]
if channel_function == SUPLA_FUNCTION_NONE:
_LOGGER.debug(
"Ignored function: %s, channel id: %s",
channel_function,
channel["id"],
)
continue
component_name = SUPLA_FUNCTION_HA_CMP_MAP.get(channel_function)
if component_name is None:
@ -130,6 +140,16 @@ class SuplaChannel(Entity):
"""Return the name of the device."""
return self.channel_data["caption"]
@property
def available(self) -> bool:
"""Return True if entity is available."""
if self.channel_data is None:
return False
state = self.channel_data.get("state")
if state is None:
return False
return state.get("connected")
def action(self, action, **add_pars):
"""
Run server action.

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

View file

@ -1,4 +1,4 @@
"""Support for Supla cover - curtains, rollershutters etc."""
"""Support for Supla switch."""
import logging
from pprint import pformat