From 298aafc79d3aa99aaa0e00ff0520204db93b1275 Mon Sep 17 00:00:00 2001 From: Rocik Date: Sun, 1 Sep 2019 10:42:17 +0200 Subject: [PATCH] Add support for Supla switches (#26188) * add support for Supla switches * remove blank line at the end of file * Add comma on last element of a list * Remove unnecessary supla dependencies variable --- homeassistant/components/supla/__init__.py | 5 ++- homeassistant/components/supla/cover.py | 2 -- homeassistant/components/supla/switch.py | 38 ++++++++++++++++++++++ 3 files changed, 42 insertions(+), 3 deletions(-) create mode 100644 homeassistant/components/supla/switch.py diff --git a/homeassistant/components/supla/__init__.py b/homeassistant/components/supla/__init__.py index 50b8e29f88e..9eef9d989cb 100644 --- a/homeassistant/components/supla/__init__.py +++ b/homeassistant/components/supla/__init__.py @@ -17,7 +17,10 @@ DOMAIN = "supla" CONF_SERVER = "server" CONF_SERVERS = "servers" -SUPLA_FUNCTION_HA_CMP_MAP = {"CONTROLLINGTHEROLLERSHUTTER": "cover"} +SUPLA_FUNCTION_HA_CMP_MAP = { + "CONTROLLINGTHEROLLERSHUTTER": "cover", + "LIGHTSWITCH": "switch", +} SUPLA_CHANNELS = "supla_channels" SUPLA_SERVERS = "supla_servers" diff --git a/homeassistant/components/supla/cover.py b/homeassistant/components/supla/cover.py index 0b842bd181c..3182aa8c136 100644 --- a/homeassistant/components/supla/cover.py +++ b/homeassistant/components/supla/cover.py @@ -5,8 +5,6 @@ from pprint import pformat from homeassistant.components.cover import ATTR_POSITION, CoverDevice from homeassistant.components.supla import SuplaChannel -DEPENDENCIES = ["supla"] - _LOGGER = logging.getLogger(__name__) diff --git a/homeassistant/components/supla/switch.py b/homeassistant/components/supla/switch.py new file mode 100644 index 00000000000..5e7a5469950 --- /dev/null +++ b/homeassistant/components/supla/switch.py @@ -0,0 +1,38 @@ +"""Support for Supla cover - curtains, rollershutters etc.""" +import logging +from pprint import pformat + +from homeassistant.components.switch import SwitchDevice +from homeassistant.components.supla import SuplaChannel + +_LOGGER = logging.getLogger(__name__) + + +def setup_platform(hass, config, add_entities, discovery_info=None): + """Set up the Supla switches.""" + if discovery_info is None: + return + + _LOGGER.debug("Discovery: %s", pformat(discovery_info)) + + add_entities([SuplaSwitch(device) for device in discovery_info]) + + +class SuplaSwitch(SuplaChannel, SwitchDevice): + """Representation of a Supla Switch.""" + + def turn_on(self, **kwargs): + """Turn on the switch.""" + self.action("TURN_ON") + + def turn_off(self, **kwargs): + """Turn off the switch.""" + self.action("TURN_OFF") + + @property + def is_on(self): + """Return true if switch is on.""" + state = self.channel_data.get("state") + if state: + return state["on"] + return False