Daniel Matuschek 50ea3c7744 Implementation of a KNX platform driver and a KNX switch (#2439)
* Implementation of a KNX platform driver and a KNX switch

* Starting working on a KNX thermostat implementation

* Removed KNX thermostat implementation from this branch again

* Make gateway parameter optional (can be auto-detected in many cases)

* Removed check for double initialisation

* KNX messages now will be handled internally and not send to the Home Assistant message bus

* Call update_ha_state only if should_poll is false

* Removed unused HASS variable

* knxip library version changed

* pylint optimization
2016-07-10 10:36:54 -07:00

45 lines
1.2 KiB
Python

"""
Support KNX switching actuators.
For more details about this platform, please refer to the documentation at
https://home-assistant.io/components/switch.knx/
(c) 2016 Daniel Matuschek <info@open-homeautomation.com>
"""
from homeassistant.components.switch import SwitchDevice
from homeassistant.components.knx import (
KNXConfig, KNXGroupAddress)
DEPENDENCIES = ["knx"]
def setup_platform(hass, config, add_entities, discovery_info=None):
"""Create and add an entity based on the configuration."""
add_entities([
KNXSwitch(hass, KNXConfig(config))
])
class KNXSwitch(KNXGroupAddress, SwitchDevice):
"""Representation of a KNX switch device."""
def turn_on(self, **kwargs):
"""Turn the switch on.
This sends a value 0 to the group address of the device
"""
self.group_write(1)
self._state = [1]
if not self.should_poll:
self.update_ha_state()
def turn_off(self, **kwargs):
"""Turn the switch off.
This sends a value 1 to the group address of the device
"""
self.group_write(0)
self._state = [0]
if not self.should_poll:
self.update_ha_state()