1
mirror of https://github.com/home-assistant/core synced 2024-09-03 08:14:07 +02:00
ha-core/homeassistant/components/supla/switch.py
Rocik d996a4a9a9
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
2020-02-24 15:34:53 +01:00

39 lines
1002 B
Python

"""Support for Supla switch."""
import logging
from pprint import pformat
from homeassistant.components.supla import SuplaChannel
from homeassistant.components.switch import SwitchDevice
_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