2016-06-20 05:30:57 +00:00
|
|
|
"""
|
|
|
|
Support for Zwave roller shutter components.
|
|
|
|
|
|
|
|
For more details about this platform, please refer to the documentation
|
|
|
|
https://home-assistant.io/components/rollershutter.zwave/
|
|
|
|
"""
|
|
|
|
# Because we do not compile openzwave on CI
|
|
|
|
# pylint: disable=import-error
|
|
|
|
import logging
|
|
|
|
from homeassistant.components.rollershutter import DOMAIN
|
|
|
|
from homeassistant.components.zwave import ZWaveDeviceEntity
|
|
|
|
from homeassistant.components import zwave
|
|
|
|
from homeassistant.components.rollershutter import RollershutterDevice
|
|
|
|
|
|
|
|
COMMAND_CLASS_SWITCH_MULTILEVEL = 0x26 # 38
|
|
|
|
COMMAND_CLASS_SWITCH_BINARY = 0x25 # 37
|
|
|
|
|
|
|
|
_LOGGER = logging.getLogger(__name__)
|
|
|
|
|
|
|
|
|
|
|
|
def setup_platform(hass, config, add_devices, discovery_info=None):
|
|
|
|
"""Find and return Z-Wave roller shutters."""
|
|
|
|
if discovery_info is None or zwave.NETWORK is None:
|
|
|
|
return
|
|
|
|
|
|
|
|
node = zwave.NETWORK.nodes[discovery_info[zwave.ATTR_NODE_ID]]
|
|
|
|
value = node.values[discovery_info[zwave.ATTR_VALUE_ID]]
|
|
|
|
|
|
|
|
if value.command_class != zwave.COMMAND_CLASS_SWITCH_MULTILEVEL:
|
|
|
|
return
|
2016-06-24 15:44:24 +00:00
|
|
|
if value.index != 0:
|
2016-06-20 05:30:57 +00:00
|
|
|
return
|
|
|
|
|
|
|
|
value.set_change_verified(False)
|
|
|
|
add_devices([ZwaveRollershutter(value)])
|
|
|
|
|
|
|
|
|
|
|
|
class ZwaveRollershutter(zwave.ZWaveDeviceEntity, RollershutterDevice):
|
|
|
|
"""Representation of an Zwave roller shutter."""
|
|
|
|
|
|
|
|
def __init__(self, value):
|
|
|
|
"""Initialize the zwave rollershutter."""
|
2016-08-10 06:31:44 +00:00
|
|
|
import libopenzwave
|
2016-06-20 05:30:57 +00:00
|
|
|
from openzwave.network import ZWaveNetwork
|
|
|
|
from pydispatch import dispatcher
|
|
|
|
ZWaveDeviceEntity.__init__(self, value, DOMAIN)
|
2016-08-10 06:31:44 +00:00
|
|
|
self._lozwmgr = libopenzwave.PyManager()
|
|
|
|
self._lozwmgr.create()
|
2016-06-20 05:30:57 +00:00
|
|
|
self._node = value.node
|
2016-08-10 06:31:44 +00:00
|
|
|
self._current_position = None
|
2016-06-20 05:30:57 +00:00
|
|
|
dispatcher.connect(
|
|
|
|
self.value_changed, ZWaveNetwork.SIGNAL_VALUE_CHANGED)
|
|
|
|
|
|
|
|
def value_changed(self, value):
|
|
|
|
"""Called when a value has changed on the network."""
|
2016-07-22 08:01:40 +00:00
|
|
|
if self._value.value_id == value.value_id or \
|
|
|
|
self._value.node == value.node:
|
2016-08-10 06:31:44 +00:00
|
|
|
self.update_properties()
|
2016-07-22 08:01:40 +00:00
|
|
|
self.update_ha_state()
|
2016-06-20 05:30:57 +00:00
|
|
|
_LOGGER.debug("Value changed on network %s", value)
|
|
|
|
|
2016-08-10 06:31:44 +00:00
|
|
|
def update_properties(self):
|
|
|
|
"""Callback on data change for the registered node/value pair."""
|
|
|
|
# Position value
|
|
|
|
for value in self._node.get_values(
|
|
|
|
class_id=COMMAND_CLASS_SWITCH_MULTILEVEL).values():
|
|
|
|
if value.command_class == zwave.COMMAND_CLASS_SWITCH_MULTILEVEL \
|
|
|
|
and value.label == 'Level':
|
|
|
|
self._current_position = value.data
|
|
|
|
|
2016-06-20 05:30:57 +00:00
|
|
|
@property
|
|
|
|
def current_position(self):
|
|
|
|
"""Return the current position of Zwave roller shutter."""
|
2016-08-10 06:31:44 +00:00
|
|
|
if self._current_position is not None:
|
|
|
|
if self._current_position <= 5:
|
|
|
|
return 100
|
|
|
|
elif self._current_position >= 95:
|
|
|
|
return 0
|
|
|
|
else:
|
|
|
|
return 100 - self._current_position
|
2016-06-20 05:30:57 +00:00
|
|
|
|
|
|
|
def move_up(self, **kwargs):
|
|
|
|
"""Move the roller shutter up."""
|
2016-08-10 06:31:44 +00:00
|
|
|
for value in self._node.get_values(
|
|
|
|
class_id=COMMAND_CLASS_SWITCH_MULTILEVEL).values():
|
|
|
|
if value.command_class == zwave.COMMAND_CLASS_SWITCH_MULTILEVEL \
|
|
|
|
and value.label == 'Open':
|
|
|
|
self._lozwmgr.pressButton(value.value_id)
|
|
|
|
break
|
2016-06-20 05:30:57 +00:00
|
|
|
|
|
|
|
def move_down(self, **kwargs):
|
|
|
|
"""Move the roller shutter down."""
|
2016-08-10 06:31:44 +00:00
|
|
|
for value in self._node.get_values(
|
|
|
|
class_id=COMMAND_CLASS_SWITCH_MULTILEVEL).values():
|
|
|
|
if value.command_class == zwave.COMMAND_CLASS_SWITCH_MULTILEVEL \
|
|
|
|
and value.label == 'Close':
|
|
|
|
self._lozwmgr.pressButton(value.value_id)
|
|
|
|
break
|
2016-06-20 05:30:57 +00:00
|
|
|
|
2016-08-16 07:37:58 +00:00
|
|
|
def move_position(self, position, **kwargs):
|
|
|
|
"""Move the roller shutter to a specific position."""
|
|
|
|
self._node.set_dimmer(self._value.value_id, 100 - position)
|
|
|
|
|
2016-06-20 05:30:57 +00:00
|
|
|
def stop(self, **kwargs):
|
|
|
|
"""Stop the roller shutter."""
|
|
|
|
for value in self._node.get_values(
|
2016-08-10 06:31:44 +00:00
|
|
|
class_id=COMMAND_CLASS_SWITCH_MULTILEVEL).values():
|
|
|
|
if value.command_class == zwave.COMMAND_CLASS_SWITCH_MULTILEVEL \
|
|
|
|
and value.label == 'Open':
|
|
|
|
self._lozwmgr.releaseButton(value.value_id)
|
|
|
|
break
|