From 5c006cd2d272a17622fc8e8236c3ef61bd2d4df8 Mon Sep 17 00:00:00 2001 From: John Arild Berentsen Date: Mon, 2 Jan 2017 18:53:46 +0100 Subject: [PATCH] Prevent Homeassistant to create a segfault with OZW (#5085) --- homeassistant/components/zwave/__init__.py | 26 ++++++++++++++++++---- homeassistant/components/zwave/const.py | 1 + 2 files changed, 23 insertions(+), 4 deletions(-) diff --git a/homeassistant/components/zwave/__init__.py b/homeassistant/components/zwave/__init__.py index be4add384c3..82c116aaa5c 100755 --- a/homeassistant/components/zwave/__init__.py +++ b/homeassistant/components/zwave/__init__.py @@ -462,11 +462,29 @@ def setup(hass, config): node_id = service.data.get(const.ATTR_NODE_ID) node = NETWORK.nodes[node_id] param = service.data.get(const.ATTR_CONFIG_PARAMETER) - value = service.data.get(const.ATTR_CONFIG_VALUE) + selection = service.data.get(const.ATTR_CONFIG_VALUE) size = service.data.get(const.ATTR_CONFIG_SIZE, 2) - node.set_config_param(param, value, size) - _LOGGER.info("Setting config parameter %s on Node %s " - "with value %s and size=%s", param, node_id, value, size) + i = 0 + for value in ( + node.get_values(class_id=const.COMMAND_CLASS_CONFIGURATION) + .values()): + if value.index == param and value.type == const.TYPE_LIST: + _LOGGER.debug('Values for parameter %s: %s', param, + value.data_items) + i = len(value.data_items) - 1 + if i == 0: + node.set_config_param(param, selection, size) + else: + if selection > i: + _LOGGER.info('Config parameter selection does not exist!' + ' Please check zwcfg_[home_id].xml in' + ' your homeassistant config directory. ' + ' Available selections are 0 to %s', i) + return + node.set_config_param(param, selection, size) + _LOGGER.info('Setting config parameter %s on Node %s ' + 'with selection %s and size=%s', param, node_id, + selection, size) def print_config_parameter(service): """Print a config parameter from a node.""" diff --git a/homeassistant/components/zwave/const.py b/homeassistant/components/zwave/const.py index b5dbf2f402a..2350b4bee75 100644 --- a/homeassistant/components/zwave/const.py +++ b/homeassistant/components/zwave/const.py @@ -302,3 +302,4 @@ TYPE_BYTE = "Byte" TYPE_BOOL = "Bool" TYPE_DECIMAL = "Decimal" TYPE_INT = "Int" +TYPE_LIST = "List"