def manual_backup(): logging.info('Manually creating a backup') if globals.files_manager.backup_xml_config('manual', globals.network.home_id_str): return utils.format_json_result( data='Xml config file successfully backup') else: return utils.format_json_result( sucess='error', data='See openzwave log file for details')
def get(self): try: utils.check_apikey(self.get_argument('apikey', '')) type = self.get_argument('type', '') if type == 'do': logging.info('Manually creating a backup') if globals.files_manager.backup_xml_config( 'manual', globals.network.home_id_str): self.write(utils.format_json_result()) else: raise Exception('See openzwave log file for details') elif type == 'list': self.write( utils.format_json_result( data=globals.files_manager.get_openzwave_backups())) elif type == 'restore': backup = self.get_argument('backup', '') logging.info('Restoring backup ' + backup) backup_folder = globals.data_folder + "/xml_backups" try: os.stat(backup_folder) except: os.mkdir(backup_folder) backup_file = os.path.join(backup_folder, backup) target_file = globals.data_folder + "/zwcfg_" + globals.network.home_id_str + ".xml" if not os.path.isfile(backup_file): raise Exception('No config file found with name ' + str(backup)) else: tree = etree.parse(backup_file) globals.network_is_running = False globals.network.stop() logging.info('ZWave network is now stopped') time.sleep(3) shutil.copy2(backup_file, target_file) os.chmod(target_file, 0777) network_utils.start_network() self.write(utils.format_json_result()) elif type == 'delete': backup = self.get_argument('backup', '') logging.info('Manually deleting a backup') backup_file = os.path.join( globals.data_folder + '/xml_backups', backup) if not os.path.isfile(backup_file): raise Exception('No config file found with name ' + str(backup)) else: os.unlink(backup_file) self.write(utils.format_json_result()) except Exception, e: self.write(utils.format_json_result(success="error", data=str(e)))
def add_assoc(node_id, group, target_id, instance, action): utils.can_execute_command(0) utils.check_node_exist(node_id) if action == 'add': utils.check_node_exist(target_id) logging.info(action + ' assoc to nodeId: ' + str(node_id) + ' in group ' + str(group) + ' with nodeId: ' + str(node_id) + ' on instance ' + str(instance)) if node_id not in globals.pending_associations: globals.pending_associations[node_id] = dict() if action == 'remove': globals.pending_associations[node_id][group] = PendingAssociation( pending_added=None, pending_removed=target_id, timeout=0) if instance < 1: globals.network.manager.removeAssociation(globals.network.home_id, node_id, group, target_id) else: globals.network.manager.removeAssociation(globals.network.home_id, node_id, group, target_id, instance) if action == 'add': globals.pending_associations[node_id][group] = PendingAssociation( pending_added=target_id, pending_removed=None, timeout=0) if instance < 1: globals.network.manager.addAssociation(globals.network.home_id, node_id, group, target_id) else: globals.network.manager.addAssociation(globals.network.home_id, node_id, group, target_id, instance) return utils.format_json_result()
def refresh_dynamic(node_id): globals.network.manager.requestNodeDynamic(globals.network.home_id, node_id) globals.network.nodes[node_id].last_update = time.time() logging.info("Fetch the dynamic command class data for the node %s" % (node_id, )) return utils.format_json_result()
def remove_unknowns_devices_openzwave_config(): globals.network_is_running = False globals.network.stop() logging.info('ZWave network is now stopped') globals.files_manager.remove_unknowns_devices_openzwave_config(globals.network.home_id_str) network_utils.start_network() return utils.format_json_result()
def ghost_killer(node_id): logging.info('Remove cc 0x84 (wake_up) for a ghost device: %s' % (node_id,)) filename = globals.data_folder + "/zwcfg_" + globals.network.home_id_str + ".xml" globals.network_is_running = False globals.network.stop() logging.info('ZWave network is now stopped') time.sleep(5) found = False message = None tree = etree.parse(filename) namespace = tree.getroot().tag[1:].split("}")[0] node = tree.find("{%s}Node[@id='%s']" % (namespace, node_id,)) if node is None: message = 'node not found' else: command_classes = node.find(".//{%s}CommandClasses" % namespace) if command_classes is None: message = 'commandClasses not found' else: for command_Class in command_classes.findall(".//{%s}CommandClass" % namespace): if int(command_Class.get("id")[:7]) == globals.COMMAND_CLASS_WAKE_UP: command_classes.remove(command_Class) found = True break if found: config_file = open(filename, "w") config_file.write('<?xml version="1.0" encoding="utf-8" ?>\n') config_file.writelines(etree.tostring(tree, pretty_print=True)) config_file.close() else: message = 'commandClass wake_up not found' globals.ghost_node_id = node_id network_utils.start_network() return utils.format_json_result(found, message)
def get_health(): network_health = {'updateTime': int(time.time())} nodes_data = {} if globals.network is not None and globals.network.state >= globals.network.STATE_STARTED and globals.network_is_running: for node_id in list(globals.network.nodes): nodes_data[node_id] = serialization.serialize_node_to_json(node_id) network_health['devices'] = nodes_data return utils.format_json_result(data=network_health)
def heal(node_id, perform_return_routes_initialization=False): utils.check_node_exist(node_id, True) logging.info( "Heal network node (%s) by requesting the node rediscover their neighbors" % (node_id, )) globals.network.manager.healNetworkNode( globals.network.home_id, node_id, perform_return_routes_initialization) return utils.format_json_result()
def remove_unknowns_devices_openzwave_config(): globals.network_is_running = False globals.network.stop() logging.info('ZWave network is now stopped') globals.files_manager.remove_unknowns_devices_openzwave_config( globals.network.home_id_str) network_utils.start_network() return utils.format_json_result()
def hard_reset(): globals.network.controller.hard_reset() logging.info( 'The controller becomes a primary controller ready to add devices to a new network' ) time.sleep(3) network_utils.start_network() return utils.format_json_result()
def get(self): try: utils.check_apikey(self.get_argument('apikey','')) type = self.get_argument('type','') if type == 'do': logging.info('Manually creating a backup') if globals.files_manager.backup_xml_config('manual', globals.network.home_id_str): self.write(utils.format_json_result()) else: raise Exception ('See openzwave log file for details') elif type == 'list': self.write(utils.format_json_result(data=globals.files_manager.get_openzwave_backups())) elif type == 'restore': backup = self.get_argument('backup','') logging.info('Restoring backup ' + backup) backup_folder = globals.data_folder + "/xml_backups" try: os.stat(backup_folder) except: os.mkdir(backup_folder) backup_file = os.path.join(backup_folder, backup) target_file = globals.data_folder + "/zwcfg_" + globals.network.home_id_str + ".xml" if not os.path.isfile(backup_file): raise Exception ('No config file found with name ' + str(backup)) else: tree = etree.parse(backup_file) globals.network_is_running = False globals.network.stop() logging.info('ZWave network is now stopped') time.sleep(3) shutil.copy2(backup_file, target_file) os.chmod(target_file, 0777) network_utils.start_network() self.write(utils.format_json_result()) elif type == 'delete': backup = self.get_argument('backup','') logging.info('Manually deleting a backup') backup_file = os.path.join(globals.data_folder + '/xml_backups', backup) if not os.path.isfile(backup_file): raise Exception ('No config file found with name ' + str(backup)) else: os.unlink(backup_file) self.write(utils.format_json_result()) except Exception,e: self.write(utils.format_json_result(success="error",data=str(e)))
def get_neighbours(): neighbours = {'updateTime': int(time.time())} nodes_data = {} if globals.network is not None and globals.network.state >= globals.network.STATE_STARTED and globals.network_is_running: for node_id in list(globals.network.nodes): if node_id not in globals.disabled_nodes: nodes_data[node_id] = serialization.serialize_neighbour_to_json(node_id) neighbours['devices'] = nodes_data return utils.format_json_result(data=neighbours)
def get_neighbours(): neighbours = {'updateTime': int(time.time())} nodes_data = {} if globals.network is not None and globals.network.state >= globals.network.STATE_STARTED and globals.network_is_running: for node_id in list(globals.network.nodes): if node_id not in globals.disabled_nodes: nodes_data[ node_id] = serialization.serialize_neighbour_to_json( node_id) neighbours['devices'] = nodes_data return utils.format_json_result(data=neighbours)
def get(self): try: utils.check_apikey(self.get_argument('apikey', '')) type = self.get_argument('type', '') action = self.get_argument('action', '') info = self.get_argument('info', '') if type == 'action': if action in globals.NETWORK_REST_MAPPING: self.write(globals.NETWORK_REST_MAPPING[action]()) else: self.write(utils.format_json_result()) elif type == 'info': if info in globals.NETWORK_REST_MAPPING: self.write(globals.NETWORK_REST_MAPPING[info]()) else: self.write(utils.format_json_result()) else: self.write(utils.format_json_result()) except Exception, e: self.write(utils.format_json_result(success="error", data=str(e)))
def get(self): try: utils.check_apikey(self.get_argument('apikey','')) type = self.get_argument('type','') action = self.get_argument('action','') info = self.get_argument('info','') if type == 'action': if action in globals.NETWORK_REST_MAPPING: self.write(globals.NETWORK_REST_MAPPING[action]()) else: self.write(utils.format_json_result()) elif type == 'info': if info in globals.NETWORK_REST_MAPPING: self.write(globals.NETWORK_REST_MAPPING[info]()) else: self.write(utils.format_json_result()) else: self.write(utils.format_json_result()) except Exception,e: self.write(utils.format_json_result(success="error",data=str(e)))
def test_network(): utils.can_execute_command() logging.info("Sends a series of messages to a network node for testing network reliability") for node_id in list(globals.network.nodes): if node_id in globals.not_supported_nodes: logging.debug("skip not supported (nodeId: %s)" % (node_id,)) continue if node_id in globals.disabled_nodes: continue globals.network.manager.testNetworkNode(globals.network.home_id, node_id, 3) return utils.format_json_result()
def start_network(): globals.pending_configurations.clear() globals.pending_associations.clear() globals.node_notifications.clear() if globals.network_information is None: globals.network_information = NetworkInformation(globals.maximum_number_notifications) else: globals.network_information.reset() logging.info('******** The ZWave network is being started ********') globals.network.start() return utils.format_json_result()
def get(self): try: utils.check_apikey(self.get_argument('apikey', '')) type = self.get_argument('type', '') node_id = int(self.get_argument('node_id', '0')) info = self.get_argument('info', '') action = self.get_argument('action', '') do_security = int(self.get_argument('security', '0')) if type == 'replicationSend': utils.can_execute_command(0) utils.check_node_exist(node_id) logging.info('Send information from primary to secondary %s' % (node_id, )) self.write( utils.format_json_result( data=globals.network.manager.replicationSend( globals.network.home_id, node_id))) elif type == 'info': logging.info("Controller info " + str(info)) self.write(utils.format_json_result()) elif type == 'action': logging.info("Controller action " + str(action)) if action in globals.CONTROLLER_REST_MAPPING: self.write(globals.CONTROLLER_REST_MAPPING[action]()) else: self.write(utils.format_json_result()) elif type == 'addNode': utils.can_execute_command(0) if do_security == 1: do_security = True logging.info( "Start the Inclusion Process to add a Node to the Network with Security CC if the node is supports it" ) else: do_security = False logging.info( "Start the Inclusion Process to add a Node to the Network" ) execution_result = globals.network.manager.addNode( globals.network.home_id, do_security) if execution_result: globals.network_information.actual_mode = ControllerMode.AddDevice self.write(utils.format_json_result(data=execution_result)) elif type == 'removeNode': utils.can_execute_command(0) logging.info( "Remove a Device from the Z-Wave Network (Started)") execution_result = globals.network.manager.removeNode( globals.network.home_id) if execution_result: globals.network_information.actual_mode = ControllerMode.RemoveDevice self.write(utils.format_json_result(data=execution_result)) else: self.write(utils.format_json_result()) except Exception, e: self.write(utils.format_json_result(success="error", data=str(e)))
def start_network(): globals.pending_configurations.clear() globals.pending_associations.clear() globals.node_notifications.clear() if globals.network_information is None: globals.network_information = NetworkInformation( globals.maximum_number_notifications) else: globals.network_information.reset() logging.info('******** The ZWave network is being started ********') globals.network.start() return utils.format_json_result()
def test_network(): if not network_utils.can_execute_network_command(): raise Exception('Controller is bussy') logging.info("Sends a series of messages to a network node for testing network reliability") for node_id in list(globals.network.nodes): if node_id in globals.not_supported_nodes: logging.debug("skip not supported (nodeId: %s)" % (node_id,)) continue if node_id in globals.disabled_nodes: continue globals.network.manager.testNetworkNode(globals.network.home_id, node_id, 3) return utils.format_json_result()
def get_status(): json_result = {} if globals.network is not None and globals.network.state >= globals.network.STATE_STARTED and globals.network_is_running: json_result = { 'nodesCount': globals.network.nodes_count, 'sleepingNodesCount': utils.get_sleeping_nodes_count(), 'scenesCount': globals.network.scenes_count, 'pollInterval': globals.network.manager.getPollInterval(), 'isReady': globals.network.is_ready, 'stateDescription': globals.network.state_str, 'state': globals.network.state, 'controllerCapabilities': utils.concatenate_list(globals.network.controller.capabilities), 'controllerNodeCapabilities': utils.concatenate_list( globals.network.controller.node.capabilities), 'outgoingSendQueue': globals.network.controller.send_queue_count, 'controllerStatistics': globals.network.controller.stats, 'devicePath': globals.network.controller.device, 'OpenZwaveLibraryVersion': globals.network.manager.getOzwLibraryVersionNumber(), 'PythonOpenZwaveLibraryVersion': globals.network.manager.getPythonLibraryVersionNumber(), 'neighbors': utils.concatenate_list(globals.network.controller.node.neighbors), 'isBusy': globals.network_information.controller_is_busy, 'startTime': globals.network_information.start_time, 'isPrimaryController': globals.network.controller.is_primary_controller, 'isStaticUpdateController': globals.network.controller.is_static_update_controller, 'isBridgeController': globals.network.controller.is_bridge_controller, 'awakedDelay': globals.network_information.controller_awake_delay, 'mode': get_network_mode() } return utils.format_json_result(data=json_result)
def graceful_stop_network(): logging.info('Graceful stopping the ZWave network.') if globals.network is not None: home_id = globals.network.home_id_str globals.network_is_running = False globals.network.stop() dispatcher_utils.disconnect_dispatcher() globals.network.destroy() globals.network = None logging.info('The Openzwave REST-server was stopped in a normal way') globals.files_manager.backup_xml_config('stop', home_id) else: logging.info('The Openzwave REST-server is already stopped') return utils.format_json_result()
def refresh_all_values(node_id): utils.check_node_exist(node_id, True) current_node = globals.network.nodes[node_id] counter = 0 logging.info("refresh_all_values node %s" % (node_id, )) for value_id in current_node.get_values(): current_value = current_node.values[value_id] if current_value.type == 'Button': continue if current_value.is_write_only: continue current_value.refresh() counter += 1 message = 'Refreshed values count: %s' % (counter, ) return utils.format_json_result(data=message)
def refresh_all_values(node_id): utils.check_node_exist(node_id,True) current_node = globals.network.nodes[node_id] counter = 0 logging.info("refresh_all_values node %s" % (node_id,)) for value_id in current_node.get_values(): current_value = current_node.values[value_id] if current_value.type == 'Button': continue if current_value.is_write_only: continue current_value.refresh() counter += 1 message = 'Refreshed values count: %s' % (counter,) return utils.format_json_result(data=message)
def get_pending_changes(node_id): utils.check_node_exist(node_id, True) query_stage_description = globals.network.manager.getNodeQueryStage( globals.network.home_id, node_id) query_stage_code = globals.network.manager.getNodeQueryStageCode( query_stage_description) return utils.format_json_result( data={ 'statistics': globals.network.manager.getNodeStatistics(globals.network.home_id, node_id), 'queryStageCode': query_stage_code, 'queryStageDescription': query_stage_description })
def get(self): try: utils.check_apikey(self.get_argument('apikey','')) type = self.get_argument('type','') node_id = int(self.get_argument('node_id','0')) info = self.get_argument('info','') action = self.get_argument('action','') do_security = int(self.get_argument('security','0')) if type == 'replicationSend': utils.can_execute_command(0) utils.check_node_exist(node_id) logging.info('Send information from primary to secondary %s' % (node_id,)) self.write(utils.format_json_result(data=globals.network.manager.replicationSend(globals.network.home_id, node_id))) elif type == 'info': logging.info("Controller info "+str(info)) self.write(utils.format_json_result()) elif type == 'action': logging.info("Controller action "+str(action)) if action in globals.CONTROLLER_REST_MAPPING: self.write(globals.CONTROLLER_REST_MAPPING[action]()) else: self.write(utils.format_json_result()) elif type == 'addNode': utils.can_execute_command(0) if do_security == 1: do_security = True logging.info("Start the Inclusion Process to add a Node to the Network with Security CC if the node is supports it") else: do_security = False logging.info("Start the Inclusion Process to add a Node to the Network") execution_result = globals.network.manager.addNode(globals.network.home_id, do_security) if execution_result: globals.network_information.actual_mode = ControllerMode.AddDevice self.write(utils.format_json_result(data=execution_result)) elif type == 'removeNode': utils.can_execute_command(0) logging.info("Remove a Device from the Z-Wave Network (Started)") execution_result = globals.network.manager.removeNode(globals.network.home_id) if execution_result: globals.network_information.actual_mode = ControllerMode.RemoveDevice self.write(utils.format_json_result(data=execution_result)) else: self.write(utils.format_json_result()) except Exception,e: self.write(utils.format_json_result(success="error",data=str(e)))
def get_status(): json_result = {} if globals.network is not None and globals.network.state >= globals.network.STATE_STARTED and globals.network_is_running: json_result = {'nodesCount': globals.network.nodes_count, 'sleepingNodesCount': utils.get_sleeping_nodes_count(), 'scenesCount': globals.network.scenes_count, 'pollInterval': globals.network.manager.getPollInterval(), 'isReady': globals.network.is_ready, 'stateDescription': globals.network.state_str, 'state': globals.network.state, 'controllerCapabilities': utils.concatenate_list(globals.network.controller.capabilities), 'controllerNodeCapabilities': utils.concatenate_list(globals.network.controller.node.capabilities), 'outgoingSendQueue': globals.network.controller.send_queue_count, 'controllerStatistics': globals.network.controller.stats, 'devicePath': globals.network.controller.device, 'OpenZwaveLibraryVersion': globals.network.manager.getOzwLibraryVersionNumber(), 'PythonOpenZwaveLibraryVersion': globals.network.manager.getPythonLibraryVersionNumber(), 'neighbors': utils.concatenate_list(globals.network.controller.node.neighbors), 'isBusy': globals.network_information.controller_is_busy, 'startTime': globals.network_information.start_time, 'isPrimaryController': globals.network.controller.is_primary_controller, 'isStaticUpdateController': globals.network.controller.is_static_update_controller, 'isBridgeController': globals.network.controller.is_bridge_controller, 'awakedDelay': globals.network_information.controller_awake_delay, 'mode': get_network_mode() } return utils.format_json_result(data=json_result)
def heal_network(): utils.can_execute_command(0) logging.info("Heal network by requesting node's rediscover their neighbors") for node_id in list(globals.network.nodes): if node_id in globals.not_supported_nodes: logging.debug("skip not supported (nodeId: "+str(node_id)+")") continue if globals.network.nodes[node_id].is_failed: logging.debug("skip presume dead (nodeId: "+str(node_id)+")") continue if globals.network.nodes[node_id].query_stage != "Complete": logging.debug("skip query stage not complete (nodeId:"+str(node_id)+")") continue if globals.network.nodes[node_id].generic == 1: logging.debug("skip Remote controller (nodeId: "+str(node_id)+") (they don't have neighbors)") continue if node_id in globals.disabled_nodes: continue globals.network.manager.healNetworkNode(globals.network.home_id, node_id, False) return utils.format_json_result()
def heal_network(): if not network_utils.can_execute_network_command(0): raise Exception('Controller is busy') logging.info("Heal network by requesting node's rediscover their neighbors") for node_id in list(globals.network.nodes): if node_id in globals.not_supported_nodes: logging.debug("skip not supported (nodeId: "+str(node_id)+")") continue if globals.network.nodes[node_id].is_failed: logging.debug("skip presume dead (nodeId: "+str(node_id)+")") continue if globals.network.nodes[node_id].query_stage != "Complete": logging.debug("skip query stage not complete (nodeId:"+str(node_id)+")") continue if globals.network.nodes[node_id].generic == 1: logging.debug("skip Remote controller (nodeId: "+str(node_id)+") (they don't have neighbors)") continue if node_id in globals.disabled_nodes: continue globals.network.manager.healNetworkNode(globals.network.home_id, node_id, False) return utils.format_json_result()
def ghost_killer(node_id): logging.info('Remove cc 0x84 (wake_up) for a ghost device: %s' % (node_id, )) filename = globals.data_folder + "/zwcfg_" + globals.network.home_id_str + ".xml" globals.network_is_running = False globals.network.stop() logging.info('ZWave network is now stopped') time.sleep(5) found = False message = None tree = etree.parse(filename) namespace = tree.getroot().tag[1:].split("}")[0] node = tree.find("{%s}Node[@id='%s']" % ( namespace, node_id, )) if node is None: message = 'node not found' else: command_classes = node.find(".//{%s}CommandClasses" % namespace) if command_classes is None: message = 'commandClasses not found' else: for command_Class in command_classes.findall( ".//{%s}CommandClass" % namespace): if int(command_Class.get("id") [:7]) == globals.COMMAND_CLASS_WAKE_UP: command_classes.remove(command_Class) found = True break if found: config_file = open(filename, "w") config_file.write('<?xml version="1.0" encoding="utf-8" ?>\n') config_file.writelines(etree.tostring(tree, pretty_print=True)) config_file.close() else: message = 'commandClass wake_up not found' globals.ghost_node_id = node_id network_utils.start_network() return utils.format_json_result(found, message)
def add_assoc(node_id, group, target_id,instance,action): utils.can_execute_command(0) utils.check_node_exist(node_id) if action == 'add': utils.check_node_exist(target_id) logging.info(action + ' assoc to nodeId: ' + str(node_id) + ' in group ' + str(group) + ' with nodeId: ' + str( node_id) + ' on instance ' + str(instance)) if node_id not in globals.pending_associations: globals.pending_associations[node_id] = dict() if action == 'remove': globals.pending_associations[node_id][group] = PendingAssociation(pending_added=None, pending_removed=target_id,timeout=0) if instance < 1: globals.network.manager.removeAssociation(globals.network.home_id, node_id, group, target_id) else: globals.network.manager.removeAssociation(globals.network.home_id, node_id, group, target_id, instance) if action == 'add': globals.pending_associations[node_id][group] = PendingAssociation(pending_added=target_id, pending_removed=None,timeout=0) if instance < 1: globals.network.manager.addAssociation(globals.network.home_id, node_id, group, target_id) else: globals.network.manager.addAssociation(globals.network.home_id, node_id, group, target_id, instance) return utils.format_json_result()
def get_nodes_list(): nodes_list = {'updateTime': int(time.time())} nodes_data = {} for node_id in list(globals.network.nodes): my_node = globals.network.nodes[node_id] json_node = {} try: manufacturer_id = int(my_node.manufacturer_id, 16) except ValueError: manufacturer_id = None try: product_id = int(my_node.product_id, 16) except ValueError: product_id = None try: product_type = int(my_node.product_type, 16) except ValueError: product_type = None node_name = my_node.name node_location = my_node.location if utils.is_none_or_empty(node_name): node_name = 'Unknown' if globals.network.controller.node_id == node_id: node_name = my_node.product_name node_location = 'Jeedom' json_node['description'] = {'name': node_name, 'location': node_location,'product_name': my_node.product_name,'is_static_controller': my_node.basic == 2,'is_enable': int(node_id) not in globals.disabled_nodes} json_node['product'] = {'manufacturer_id': manufacturer_id,'product_type': product_type,'product_id': product_id,'is_valid': manufacturer_id is not None and product_id is not None and product_type is not None} instances = [] for value_id in my_node.get_values(genre='User'): if my_node.values[value_id].instance in instances: continue instances.append(my_node.values[value_id].instance) json_node['multi_instance'] = {'support': globals.COMMAND_CLASS_MULTI_CHANNEL in my_node.command_classes,'instances': len(instances)} json_node['capabilities'] = {'isListening': my_node.is_listening_device,'isRouting': my_node.is_routing_device,'isBeaming': my_node.is_beaming_device,'isFlirs': my_node.is_frequent_listening_device} nodes_data[node_id] = json_node nodes_list['devices'] = nodes_data return utils.format_json_result(data=nodes_list)
def get_oz_backups(): return utils.format_json_result(data=globals.files_manager.get_openzwave_backups())
def transfer_primary_role(): if not network_utils.can_execute_network_command(0): raise Exception('Controller is bussy') logging.info("Transfer Primary Role") return utils.format_json_result(data=globals.network.manager.transferPrimaryRole(globals.network.home_id))
def create_new_primary(): if not network_utils.can_execute_network_command(0): raise Exception('Controller is busy') logging.info("Add a new controller to the Z-Wave network") return utils.format_json_result(data=globals.network.manager.createNewPrimary(globals.network.home_id))
def test_node(node_id, count=3): utils.can_execute_command() utils.check_node_exist(node_id, True) globals.network.manager.testNetworkNode(globals.network.home_id, node_id, count) return utils.format_json_result()
def receive_configuration(): if not network_utils.can_execute_network_command(0): raise Exception('Controller is busy') logging.info("Receive Configuration") return utils.format_json_result(data=globals.network.manager.receiveConfiguration(globals.network.home_id))
def cancel_command(): if globals.network.manager.cancelControllerCommand(globals.network.home_id): globals.network_information.controller_is_busy = False return utils.format_json_result()
def replace_failed(node_id): utils.check_node_exist(node_id,True) logging.info("replace_failed_node node %s" % (node_id,)) return utils.format_json_result(data=globals.network.manager.replaceFailedNode(globals.network.home_id, node_id))
def assign_return_route(node_id): logging.info("Ask Node (%s) to update its Return Route to the Controller" % (node_id,)) return utils.format_json_result(data=globals.network.manager.assignReturnRoute(globals.network.home_id, node_id))
def get_nodes_list(): nodes_list = {'updateTime': int(time.time())} nodes_data = {} for node_id in list(globals.network.nodes): my_node = globals.network.nodes[node_id] json_node = {} try: manufacturer_id = int(my_node.manufacturer_id, 16) except ValueError: manufacturer_id = None try: product_id = int(my_node.product_id, 16) except ValueError: product_id = None try: product_type = int(my_node.product_type, 16) except ValueError: product_type = None node_name = my_node.name node_location = my_node.location if utils.is_none_or_empty(node_name): node_name = 'Unknown' if globals.network.controller.node_id == node_id: node_name = my_node.product_name node_location = 'Jeedom' json_node['description'] = { 'name': node_name, 'location': node_location, 'product_name': my_node.product_name, 'is_static_controller': my_node.basic == 2, 'is_enable': int(node_id) not in globals.disabled_nodes } json_node['product'] = { 'manufacturer_id': manufacturer_id, 'product_type': product_type, 'product_id': product_id, 'is_valid': manufacturer_id is not None and product_id is not None and product_type is not None } instances = [] for value_id in my_node.get_values(genre='User'): if my_node.values[value_id].instance in instances: continue instances.append(my_node.values[value_id].instance) json_node['multi_instance'] = { 'support': COMMAND_CLASS_MULTI_CHANNEL in my_node.command_classes, 'instances': len(instances) } json_node['capabilities'] = { 'isListening': my_node.is_listening_device, 'isRouting': my_node.is_routing_device, 'isBeaming': my_node.is_beaming_device, 'isFlirs': my_node.is_frequent_listening_device } nodes_data[node_id] = json_node nodes_list['devices'] = nodes_data return utils.format_json_result(data=nodes_list)
def get_health(node_id): return utils.format_json_result(data=serialization.serialize_node_to_json(node_id))
def test_node(node_id, count=3): utils.can_execute_command() utils.check_node_exist(node_id,True) globals.network.manager.testNetworkNode(globals.network.home_id, node_id, count) return utils.format_json_result()
def request_neighbour_update(node_id): utils.check_node_exist(node_id,True) logging.info("request_node_neighbour_update for node %s" % (node_id,)) return utils.format_json_result(data=globals.network.manager.requestNodeNeighborUpdate(globals.network.home_id, node_id))
def remove_failed(node_id): logging.info("Remove a failed node %s" % (node_id,)) return utils.format_json_result(data=globals.network.manager.removeFailedNode(globals.network.home_id, node_id))
def heal(node_id,perform_return_routes_initialization=False): utils.check_node_exist(node_id,True) logging.info("Heal network node (%s) by requesting the node rediscover their neighbors" % (node_id,)) globals.network.manager.healNetworkNode(globals.network.home_id, node_id, perform_return_routes_initialization) return utils.format_json_result()
def serial_api_soft_reset(): globals.network.controller.soft_reset() return utils.format_json_result()
def get_oz_backups(): return utils.format_json_result( data=globals.files_manager.get_openzwave_backups())
def has_failed(node_id): utils.check_node_exist(node_id,True) logging.info("has_node_failed node %s" % (node_id,)) return utils.format_json_result(data=globals.network.manager.hasNodeFailed(globals.network.home_id, node_id))
def get_oz_config(): utils.write_config() filename = globals.data_folder + "/zwcfg_" + globals.network.home_id_str + ".xml" with open(filename, "r") as ins: content = ins.read() return utils.format_json_result(data=content)
def get_pending_changes(node_id): utils.check_node_exist(node_id,True) query_stage_description = globals.network.manager.getNodeQueryStage(globals.network.home_id, node_id) query_stage_code = globals.network.manager.getNodeQueryStageCode(query_stage_description) return utils.format_json_result(data={'statistics': globals.network.manager.getNodeStatistics(globals.network.home_id, node_id), 'queryStageCode': query_stage_code, 'queryStageDescription': query_stage_description})
def send_information(node_id): utils.check_node_exist(node_id,True) logging.info("send_node_information node %s" % (node_id,)) return utils.format_json_result(data=globals.network.manager.sendNodeInformation(globals.network.home_id, node_id))
def refresh_info(node_id): utils.check_node_exist(node_id, True) logging.info("refresh_node_info node %s" % (node_id, )) return utils.format_json_result( data=globals.network.manager.refreshNodeInfo(globals.network.home_id, node_id))
def assign_return_route(node_id): logging.info("Ask Node (%s) to update its Return Route to the Controller" % (node_id, )) return utils.format_json_result( data=globals.network.manager.assignReturnRoute(globals.network.home_id, node_id))
def refresh_dynamic(node_id): globals.network.manager.requestNodeDynamic(globals.network.home_id, node_id) globals.network.nodes[node_id].last_update = time.time() logging.info("Fetch the dynamic command class data for the node %s" % (node_id,)) return utils.format_json_result()
def test(node_id): utils.check_node_exist(node_id,True) globals.network.manager.testNetworkNode(globals.network.home_id, node_id, 3) return utils.format_json_result()
def refresh_info(node_id): utils.check_node_exist(node_id,True) logging.info("refresh_node_info node %s" % (node_id,)) return utils.format_json_result(data=globals.network.manager.refreshNodeInfo(globals.network.home_id, node_id))