core/homeassistant/components/switch/zwave.py

54 lines
1.6 KiB
Python
Raw Normal View History

2015-11-07 14:52:36 +00:00
"""
2016-07-13 12:47:29 +00:00
Z-Wave platform that handles simple binary switches.
2016-03-08 12:35:39 +00:00
For more details about this platform, please refer to the documentation at
https://home-assistant.io/components/switch.zwave/
2015-11-07 14:52:36 +00:00
"""
import logging
2015-11-29 21:49:05 +00:00
# Because we do not compile openzwave on CI
2015-11-07 14:52:36 +00:00
# pylint: disable=import-error
2016-02-19 05:27:50 +00:00
from homeassistant.components.switch import DOMAIN, SwitchDevice
from homeassistant.components import zwave
2015-11-07 14:52:36 +00:00
_LOGGER = logging.getLogger(__name__)
2015-11-07 14:52:36 +00:00
# pylint: disable=unused-argument
def setup_platform(hass, config, add_devices, discovery_info=None):
2016-07-13 12:47:29 +00:00
"""Setup the Z-Wave platform."""
if discovery_info is None or zwave.NETWORK is None:
2015-11-07 14:52:36 +00:00
return
node = zwave.NETWORK.nodes[discovery_info[zwave.const.ATTR_NODE_ID]]
value = node.values[discovery_info[zwave.const.ATTR_VALUE_ID]]
2015-11-07 14:52:36 +00:00
if not node.has_command_class(zwave.const.COMMAND_CLASS_SWITCH_BINARY):
2015-11-07 14:52:36 +00:00
return
if value.type != zwave.const.TYPE_BOOL or value.genre != \
zwave.const.GENRE_USER:
2015-11-07 14:52:36 +00:00
return
value.set_change_verified(False)
add_devices([ZwaveSwitch(value)])
class ZwaveSwitch(zwave.ZWaveDeviceEntity, SwitchDevice):
2016-03-08 12:35:39 +00:00
"""Representation of a Z-Wave switch."""
2015-11-07 14:52:36 +00:00
def __init__(self, value):
2016-03-08 12:35:39 +00:00
"""Initialize the Z-Wave switch device."""
zwave.ZWaveDeviceEntity.__init__(self, value, DOMAIN)
2015-11-07 14:52:36 +00:00
@property
def is_on(self):
2016-03-08 12:35:39 +00:00
"""Return true if device is on."""
return self._value.data
2015-11-07 14:52:36 +00:00
def turn_on(self, **kwargs):
2016-03-08 12:35:39 +00:00
"""Turn the device on."""
self._value.node.set_switch(self._value.value_id, True)
2015-11-07 14:52:36 +00:00
def turn_off(self, **kwargs):
2016-03-08 12:35:39 +00:00
"""Turn the device off."""
self._value.node.set_switch(self._value.value_id, False)