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
|
|
|
"""
|
2017-01-02 17:55:56 +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
|
2016-04-17 21:46:51 +00:00
|
|
|
from homeassistant.components import zwave
|
2017-02-23 21:06:28 +00:00
|
|
|
from homeassistant.components.zwave import async_setup_platform # noqa # pylint: disable=unused-import
|
2015-11-07 14:52:36 +00:00
|
|
|
|
2017-01-02 17:55:56 +00:00
|
|
|
_LOGGER = logging.getLogger(__name__)
|
|
|
|
|
2015-11-07 14:52:36 +00:00
|
|
|
|
2017-02-24 14:17:27 +00:00
|
|
|
def get_device(value, **kwargs):
|
2017-02-23 21:06:28 +00:00
|
|
|
"""Create zwave entity device."""
|
|
|
|
return ZwaveSwitch(value)
|
2015-11-07 14:52:36 +00:00
|
|
|
|
|
|
|
|
2016-04-17 21:46:51 +00:00
|
|
|
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."""
|
2016-04-17 21:46:51 +00:00
|
|
|
zwave.ZWaveDeviceEntity.__init__(self, value, DOMAIN)
|
2017-02-18 07:56:05 +00:00
|
|
|
self.update_properties()
|
|
|
|
|
|
|
|
def update_properties(self):
|
|
|
|
"""Callback on data changes for node values."""
|
|
|
|
self._state = self._value.data
|
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."""
|
2017-02-18 07:56:05 +00:00
|
|
|
return self._state
|
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."""
|
2016-01-26 21:11:27 +00:00
|
|
|
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."""
|
2016-01-26 21:11:27 +00:00
|
|
|
self._value.node.set_switch(self._value.value_id, False)
|