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
|
|
|
|
|
2016-08-20 11:59:23 +00:00
|
|
|
SOMFY = 0x47
|
|
|
|
SOMFY_ZRTSI = 0x5a52
|
|
|
|
SOMFY_ZRTSI_CONTROLLER = (SOMFY, SOMFY_ZRTSI)
|
|
|
|
WORKAROUND = 'workaround'
|
|
|
|
|
|
|
|
DEVICE_MAPPINGS = {
|
|
|
|
SOMFY_ZRTSI_CONTROLLER: WORKAROUND
|
|
|
|
}
|
|
|
|
|
2016-06-20 05:30:57 +00:00
|
|
|
_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
|
|
|
|
|
2016-09-30 15:43:18 +00:00
|
|
|
node = zwave.NETWORK.nodes[discovery_info[zwave.const.ATTR_NODE_ID]]
|
|
|
|
value = node.values[discovery_info[zwave.const.ATTR_VALUE_ID]]
|
2016-06-20 05:30:57 +00:00
|
|
|
|
2016-09-30 15:43:18 +00:00
|
|
|
if value.command_class != zwave.const.COMMAND_CLASS_SWITCH_MULTILEVEL:
|
2016-06-20 05:30:57 +00:00
|
|
|
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-08-20 11:59:23 +00:00
|
|
|
self._workaround = None
|
2016-06-20 05:30:57 +00:00
|
|
|
dispatcher.connect(
|
|
|
|
self.value_changed, ZWaveNetwork.SIGNAL_VALUE_CHANGED)
|
2016-08-20 11:59:23 +00:00
|
|
|
if (value.node.manufacturer_id.strip() and
|
|
|
|
value.node.product_id.strip()):
|
|
|
|
specific_sensor_key = (int(value.node.manufacturer_id, 16),
|
|
|
|
int(value.node.product_type, 16))
|
|
|
|
|
|
|
|
if specific_sensor_key in DEVICE_MAPPINGS:
|
|
|
|
if DEVICE_MAPPINGS[specific_sensor_key] == WORKAROUND:
|
|
|
|
_LOGGER.debug("Controller without positioning feedback")
|
|
|
|
self._workaround = 1
|
2016-06-20 05:30:57 +00:00
|
|
|
|
|
|
|
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(
|
2016-09-30 15:43:18 +00:00
|
|
|
class_id=zwave.const.COMMAND_CLASS_SWITCH_MULTILEVEL).values():
|
|
|
|
if value.command_class == \
|
|
|
|
zwave.const.COMMAND_CLASS_SWITCH_MULTILEVEL and \
|
|
|
|
value.label == 'Level':
|
2016-08-10 06:31:44 +00:00
|
|
|
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-20 11:59:23 +00:00
|
|
|
if not self._workaround:
|
|
|
|
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-09-30 15:43:18 +00:00
|
|
|
for value in (self._node.get_values(
|
|
|
|
class_id=zwave.const.COMMAND_CLASS_SWITCH_MULTILEVEL)
|
|
|
|
.values()):
|
|
|
|
if value.command_class == \
|
|
|
|
zwave.const.COMMAND_CLASS_SWITCH_MULTILEVEL and value.label == \
|
|
|
|
'Open' or value.command_class == \
|
|
|
|
zwave.const.COMMAND_CLASS_SWITCH_MULTILEVEL and value.label == \
|
|
|
|
'Down':
|
2016-08-10 06:31:44 +00:00
|
|
|
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(
|
2016-09-30 15:43:18 +00:00
|
|
|
class_id=zwave.const.COMMAND_CLASS_SWITCH_MULTILEVEL).values():
|
|
|
|
if value.command_class == \
|
|
|
|
zwave.const.COMMAND_CLASS_SWITCH_MULTILEVEL and value.label == \
|
|
|
|
'Up' or value.command_class == \
|
|
|
|
zwave.const.COMMAND_CLASS_SWITCH_MULTILEVEL and value.label == \
|
|
|
|
'Close':
|
2016-08-10 06:31:44 +00:00
|
|
|
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-09-30 15:43:18 +00:00
|
|
|
class_id=zwave.const.COMMAND_CLASS_SWITCH_MULTILEVEL).values():
|
|
|
|
if value.command_class == \
|
|
|
|
zwave.const.COMMAND_CLASS_SWITCH_MULTILEVEL and value.label == \
|
|
|
|
'Open' or value.command_class == \
|
|
|
|
zwave.const.COMMAND_CLASS_SWITCH_MULTILEVEL and value.label == \
|
|
|
|
'Down':
|
2016-08-10 06:31:44 +00:00
|
|
|
self._lozwmgr.releaseButton(value.value_id)
|
|
|
|
break
|