def get_wake_up_interval(node_id): interval = value_utils.get_value_by_label(node_id, globals.COMMAND_CLASS_WAKE_UP, 1, 'Wake-up Interval') if interval is not None: return interval.data return None
def node_notification(args): code = int(args['notificationCode']) node_id = int(args['nodeId']) if node_id in globals.not_supported_nodes: return if node_id in globals.disabled_nodes: return if node_id in globals.network.nodes: my_node = globals.network.nodes[node_id] # mark as updated my_node.last_update = time.time() # try auto remove unsupported nodes if node_id in globals.not_supported_nodes and globals.network.state >= globals.network.STATE_AWAKED: logging.info('remove fake nodeId: %s' % (node_id,)) globals.network.manager.removeFailedNode(globals.network.home_id, node_id) return wake_up_time = get_wake_up_interval(node_id) if node_id not in globals.node_notifications: globals.node_notifications[node_id] = NodeNotification(code, wake_up_time) else: globals.node_notifications[node_id].refresh(code, wake_up_time) if code == 3: my_value = value_utils.get_value_by_label(node_id, globals.COMMAND_CLASS_WAKE_UP, 1, 'Wake-up Interval Step') if my_value is not None: wake_up_interval_step = my_value.data + 2.0 else: wake_up_interval_step = 60.0 logging.info('NodeId %s send a notification: %s' % (node_id, globals.node_notifications[node_id].description,)) push_node_notification(node_id, code)
def node_notification(args): code = int(args['notificationCode']) node_id = int(args['nodeId']) if node_id in globals.not_supported_nodes: return if node_id in globals.disabled_nodes: return if node_id in globals.network.nodes: my_node = globals.network.nodes[node_id] # mark as updated my_node.last_update = time.time() # try auto remove unsupported nodes if node_id in globals.not_supported_nodes and globals.network.state >= globals.network.STATE_AWAKED: logging.info('remove fake nodeId: %s' % (node_id, )) globals.network.manager.removeFailedNode(globals.network.home_id, node_id) return wake_up_time = get_wake_up_interval(node_id) if node_id not in globals.node_notifications: globals.node_notifications[node_id] = NodeNotification( code, wake_up_time) else: globals.node_notifications[node_id].refresh(code, wake_up_time) if code == 3: my_value = value_utils.get_value_by_label( node_id, globals.COMMAND_CLASS_WAKE_UP, 1, 'Wake-up Interval Step') if my_value is not None: wake_up_interval_step = my_value.data + 2.0 else: wake_up_interval_step = 60.0 logging.info('NodeId %s send a notification: %s' % ( node_id, globals.node_notifications[node_id].description, )) push_node_notification(node_id, code)
def serialize_node_to_json(node_id): json_result = {} if node_id not in globals.network.nodes or node_id in globals.not_supported_nodes: return json_result my_node = globals.network.nodes[node_id] try: timestamp = int(my_node.last_update) except TypeError: timestamp = int(1) 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 json_result['data'] = {} node_name = my_node.name if globals.network.controller.node_id == node_id: node_name = my_node.product_name if utils.is_none_or_empty(node_name): node_name = 'Unknown' json_result['data']['description'] = {'name': node_name, 'location': my_node.location,'product_name': my_node.product_name} json_result['data']['manufacturerId'] = {'value': manufacturer_id, 'hex': my_node.manufacturer_id} json_result['data']['vendorString'] = {'value': my_node.manufacturer_name} json_result['data']['manufacturerProductId'] = {'value': product_id, 'hex': my_node.product_id} json_result['data']['product_name'] = {'value': my_node.product_name} json_result['data']['location'] = {'value': my_node.location} json_result['data']['name'] = {'value': my_node.name} json_result['data']['version'] = {'value': my_node.version} json_result['data']['manufacturerProductType'] = {'value': product_type, 'hex': my_node.product_type} json_result['data']['neighbours'] = {'value': list(my_node.neighbors)} json_result['data']['isVirtual'] = {'value': ''} if globals.network.controller.node_id == node_id and my_node.basic == 1: json_result['data']['basicType'] = {'value': 2} else: json_result['data']['basicType'] = {'value': my_node.basic} json_result['data']['genericType'] = {'value': my_node.generic} json_result['data']['specificType'] = {'value': my_node.specific} json_result['data']['type'] = {'value': my_node.type} json_result['data']['state'] = {'value': str(my_node.query_stage)} json_result['data']['isAwake'] = {'value': my_node.is_awake, "updateTime": timestamp} json_result['data']['isReady'] = {'value': my_node.is_ready, "updateTime": timestamp} json_result['data']['isEnable'] = {'value': int(node_id) not in globals.disabled_nodes} json_result['data']['isInfoReceived'] = {'value': my_node.is_info_received} try: can_wake_up = my_node.can_wake_up() except RuntimeError: can_wake_up = False json_result['data']['can_wake_up'] = {'value': can_wake_up} json_result['data']['battery_level'] = {'value': my_node.get_battery_level()} json_result['last_notification'] = {} next_wake_up = None if node_id in globals.node_notifications: notification = globals.node_notifications[node_id] next_wake_up = notification.next_wake_up json_result['last_notification'] = {"receiveTime": notification.receive_time,"description": notification.description,"help": notification.help} json_result['data']['wakeup_interval'] = {'value': node_utils.get_wake_up_interval(node_id), 'next_wakeup': next_wake_up} json_result['data']['isFailed'] = {'value': my_node.is_failed} json_result['data']['isListening'] = {'value': my_node.is_listening_device} json_result['data']['isRouting'] = {'value': my_node.is_routing_device} json_result['data']['isSecurity'] = {'value': my_node.is_security_device} json_result['data']['isBeaming'] = {'value': my_node.is_beaming_device} json_result['data']['isFrequentListening'] = {'value': my_node.is_frequent_listening_device} json_result['data']['security'] = {'value': my_node.security} json_result['data']['lastReceived'] = {'updateTime': timestamp} json_result['data']['maxBaudRate'] = {'value': my_node.max_baud_rate} json_result['data']['is_enable'] = {'value': int(node_id) not in globals.disabled_nodes} json_result['data']['isZwavePlus'] = {'value': my_node.is_zwave_plus} statistics = globals.network.manager.getNodeStatistics(globals.network.home_id, node_id) send_total = statistics['sentCnt'] + statistics['sentFailed'] percent_delivered = 0 if send_total > 0: percent_delivered = (statistics['sentCnt'] * 100) / send_total average_request_rtt = statistics['averageRequestRTT'] json_result['data']['statistics'] = {'total': send_total, 'delivered': percent_delivered,'deliveryTime': average_request_rtt} have_group = False query_stage_index = utils.convert_query_stage_to_int(my_node.query_stage) if my_node.groups and query_stage_index >= 12 and my_node.generic != 2: check_for_group = len(my_node.groups) > 0 if check_for_group : have_group = node_utils.check_primary_controller(my_node) else: check_for_group = False json_result['data']['is_groups_ok'] = {'value': have_group, 'enabled': check_for_group} is_neighbours_ok = query_stage_index > 13 if my_node.generic == 1: is_neighbours_ok = False if my_node.generic == 8 and not my_node.is_listening_device: is_neighbours_ok = False json_result['data']['is_neighbours_ok'] = {'value': len(my_node.neighbors) > 0,'neighbors': len(my_node.neighbors), 'enabled': is_neighbours_ok} json_result['data']['is_manufacturer_specific_ok'] = {'value': my_node.product_name != '','enabled': query_stage_index >= 7} is_secured = value_utils.get_value_by_label(node_id, globals.COMMAND_CLASS_SECURITY, 1, 'Secured') json_result['data']['isSecured'] = {'value': is_secured is not None and is_secured.data, 'enabled' : is_secured is not None} pending_changes = 0 json_result['instances'] = {"updateTime": timestamp} json_result['groups'] = {"updateTime": timestamp} for groupIndex in list(my_node.groups): group = my_node.groups[groupIndex] pending_state = 1 if my_node.node_id in globals.pending_associations: pending_associations = globals.pending_associations[my_node.node_id] if groupIndex in pending_associations: pending_association = pending_associations[groupIndex] if pending_association.state is not None: pending_state = pending_association.state if pending_state is not None and pending_state > 1: pending_changes += 1 json_result['groups'][groupIndex] = {"label": group.label, "maximumAssociations": group.max_associations,"associations": list(group.associations_instances),"pending": pending_state} json_result['associations'] = serialize_associations(node_id) if node_id in globals.node_notifications: notification = globals.node_notifications[node_id] json_result['last_notification'] = {"receiveTime": notification.receive_time,"code": notification.code,"description": notification.description,"help": notification.help,"next_wakeup": notification.next_wake_up} else: json_result['last_notification'] = {} json_result['command_classes'] = {} for command_class in my_node.command_classes: json_result['command_classes'][command_class] = {'name': my_node.get_command_class_as_string(command_class),'hex': '0x' + utils.convert_user_code_to_hex(command_class)} instances = [] for value_id in my_node.get_values(): my_value = my_node.values[value_id] if my_value.command_class is None or (my_value.instance > 1 and my_value.command_class in [globals.COMMAND_CLASS_ZWAVEPLUS_INFO,globals.COMMAND_CLASS_VERSION]): continue try: label = my_value.label except Exception, exception: label = exception.message logging.error('Value label contains unsupported text: %s' % (str(exception),)) try: value_help = my_value.help except Exception, exception: value_help = exception.message logging.error('Value help contains unsupported text: %s' % (str(exception),))