Exemple #1
0
def scene_event(network, node, scene_id):
    logging.info('Scene Activation: %s' % (scene_id, ))
    node_utils.save_node_value_event(node.node_id, COMMAND_CLASS_CENTRAL_SCENE,
                                     0, scene_id, 0)
    node_utils.save_node_value_event(node.node_id,
                                     COMMAND_CLASS_SCENE_ACTIVATION, 0,
                                     scene_id, 0)
Exemple #2
0
def send_command_zwave(_node_id, _cc_id, _instance_id, _index, _value):
    logging.info("Send command to node " + str(_node_id) + " on class " +
                 str(_cc_id) + " instance " + str(_instance_id) + " index " +
                 str(_index) + " value " + str(_value))
    utils.check_node_exist(_node_id)
    if _cc_id == globals.COMMAND_CLASS_NO_OPERATION:
        return node_utils.test_node(_node_id, 1)
    if _cc_id == globals.COMMAND_CLASS_ASSOCIATION:
        return
    for value_id in globals.network.nodes[_node_id].get_values(
            class_id=_cc_id,
            genre='All',
            type='All',
            readonly=False,
            writeonly='All'):
        if globals.network.nodes[_node_id].values[
                value_id].instance == _instance_id and (
                    _index is None
                    or globals.network.nodes[_node_id].values[value_id].index
                    == _index):
            value = globals.network.nodes[_node_id].values[
                value_id].check_data(_value)
            globals.network.nodes[_node_id].values[value_id].data = value
            if globals.network.nodes[_node_id].values[
                    value_id].genre == 'System':
                value_utils.mark_pending_change(
                    globals.network.nodes[_node_id].values[value_id], value)
            if _cc_id == globals.COMMAND_CLASS_THERMOSTAT_SETPOINT:
                # send back thermostat pending SETPOINT value
                node_utils.save_node_value_event(_node_id, _cc_id, _index,
                                                 _value, _instance_id + 10)
            return True
    raise Exception('Value not found')
def save_value(node, value, last_update):
	logging.debug('A node value has been updated. nodeId:%s value:%s' % (node.node_id, value.label))
	if node.node_id in globals.network.nodes:
		if globals.network.nodes[node.node_id].last_update > last_update:
			logging.warning('Timing Error. nodeLastUpdate:%s Last_update:%s' % (str(globals.network.nodes[node.node_id].last_update), str(last_update)))
			return
		globals.network.nodes[node.node_id].last_update = last_update
		value.last_update = last_update
		node_utils.save_node_value_event(node.node_id, value.command_class, value.index, extract_data(value, False),value.instance)
Exemple #4
0
def save_value(node, value, last_update):
	logging.debug('A node value has been updated. nodeId:%s value:%s' % (node.node_id, value.label))
	if node.node_id in globals.network.nodes:
		if globals.network.nodes[node.node_id].last_update > last_update:
			logging.warning('Timing Error. nodeLastUpdate:%s Last_update:%s' % (str(globals.network.nodes[node.node_id].last_update), str(last_update)))
			return
		globals.network.nodes[node.node_id].last_update = last_update
		value.last_update = last_update
		node_utils.save_node_value_event(node.node_id, value.command_class, value.index, extract_data(value, False), utils.change_instance(value))
Exemple #5
0
def refresh_value(node_id, instance_id, cc_id, index, value):
    try:
        if node_id not in globals.network.nodes or node_id in globals.not_supported_nodes:
            return
        my_node = globals.network.nodes[node_id]
        product_id = str(int(my_node.product_id, 16))
        product_type = str(int(my_node.product_type, 16))
        manufacturer_id = str(int(my_node.manufacturer_id, 16))
        globalId = manufacturer_id + '|' + product_type + '|' + product_id
        logging.debug("Searching refresh for : " + globalId)
        if globalId in globals.REFRESH_MAPPING:
            globalCommand = str(cc_id) + '|' + str(instance_id) + '|' + str(
                index)
            logging.debug("Found refresh for : " + globalId +
                          " searching for " + globalCommand)
            if globalCommand in globals.REFRESH_MAPPING[globalId]:
                for value_id in globals.network.nodes[node_id].get_values(
                        class_id=cc_id):
                    if globals.network.nodes[node_id].values[
                            value_id].instance == instance_id and globals.network.nodes[
                                node_id].values[value_id].index == index:
                        logging.debug("Refresh node " + str(node_id) +
                                      " on class " + str(cc_id) +
                                      " instance " + str(instance_id) +
                                      " index " + str(index) + " " +
                                      str(globals.REFRESH_MAPPING[globalId]
                                          [globalCommand]['number']) +
                                      " times in " +
                                      str(globals.REFRESH_MAPPING[globalId]
                                          [globalCommand]['sleep']) +
                                      " seconds")
                        if 'onlyset' in globals.REFRESH_MAPPING[globalId][
                                globalCommand]:
                            commandTorefresh = globals.REFRESH_MAPPING[
                                globalId][globalCommand]['onlyset']
                            commandTorefreshArray = commandTorefresh.split('|')
                            logging.debug("Setting back value for " +
                                          str(node_id) + " on class " +
                                          str(commandTorefreshArray[0]) +
                                          " instance " +
                                          str(commandTorefreshArray[1]) +
                                          " index " +
                                          str(commandTorefreshArray[2]) +
                                          " with value " + str(value))
                            node_utils.save_node_value_event(
                                node_id, commandTorefreshArray[0],
                                commandTorefreshArray[2], value,
                                commandTorefreshArray[1])
                            continue
                        for i in range(
                                0, globals.REFRESH_MAPPING[globalId]
                            [globalCommand]['number']):
                            time.sleep(globals.REFRESH_MAPPING[globalId]
                                       [globalCommand]['sleep'])
                            logging.debug("Performing refresh for node : " +
                                          str(node_id))
                            globals.network.nodes[node_id].values[
                                value_id].refresh()
                            if 'other' in globals.REFRESH_MAPPING[globalId][
                                    globalCommand]:
                                other = globals.REFRESH_MAPPING[globalId][
                                    globalCommand]['other']
                                list = other.split('|')
                                for value_id in globals.network.nodes[
                                        node_id].get_values(
                                            class_id=int(list[0])):
                                    if globals.network.nodes[node_id].values[
                                            value_id].instance == int(
                                                list[1]
                                            ) and globals.network.nodes[
                                                node_id].values[
                                                    value_id].index == int(
                                                        list[2]):
                                        logging.debug("Refresh node " +
                                                      str(node_id) +
                                                      " on class " +
                                                      str(list[0]) +
                                                      " instance " +
                                                      str(list[1]) +
                                                      " index " + str(list[2]))
                                        globals.network.nodes[node_id].values[
                                            value_id].refresh()
        return
    except Exception as e:
        logging.debug("Ignoring refresh for node : " + str(node_id))
        logging.debug(str(e))
        pass
def scene_event(network, node, scene_id):
	logging.info('Scene Activation: %s' % (scene_id,))
	node_utils.save_node_value_event(node.node_id,  globals.COMMAND_CLASS_SCENE_ACTIVATION, 0, scene_id, 1)