def OnNotification( notification, context ): global initFailed global criticalSection global initCondition with criticalSection: notification_type = notification.type if notification_type == Notification.Type_DriverReady: context.on_message("StatusUpdate","Driver Ready") initFailed = False elif notification_type == Notification.Type_DriverFailed: context.on_message("StatusUpdate","Driver Failed") elif notification_type == Notification.Type_DriverReset: context.on_message("StatusUpdate","Driver Reset") elif notification_type == Notification.Type_AllNodesQueried: context.on_message("StatusUpdate","All Nodes Queried") elif notification_type == Notification.Type_NodeAdded: node_info = NodeInfo() node_info.network_id = notification.network_id node_info.node_id = notification.node_id nodes.append(node_info) context.on_message('NodeAdded', notification) elif notification_type == Notification.Type_NodeRemoved: network_id = notification.network_id node_id = notification.node_id for node in nodes[:]: if node_id == node.node_id and network_id == node.network_id: nodes.remove(node) del node context.on_message('NodeRemoved', notification) break elif notification_type == Notification.Type_NodeChanged: context.on_message('NodeChanged', notification) elif notification_type == Notification.Type_ValueAdded: #print("Manager: Value Added %s" % (notification.node_id ) ) node_info = get_node_info( notification ) if node_info is not None: node_info.value_ids.append( notification.value_id ) context.on_message('ValueAdded', notification) elif notification_type == Notification.Type_ValueChanged: node_info = get_node_info( notification ) network_id = node_info.network_id node_id = node_info.node_id value_id = notification.value_id value_type = Manager.get_value_type( value_id ) value_id = Manager.get_value_id( value_id ) value = Manager.get_value_as_string( value_id ) units = Manager.get_value_units( value_id ) node_name = Manager.get_node_name( network_id, node_id ) node_location_name = Manager.get_node_location_name( network_id, node_id ) text = "{0} Node {1}: {2} @ {3} changed {4} to {5}".format( str(datetime.today()), node_id, node_name, node_location_name, value_type, value ) context.on_message('ValueChanged', notification) context.on_message("StatusUpdate", text) elif notification_type == Notification.Type_NodeQueriesComplete: node_name = Manager.get_node_name( notification.network_id, notification.node_id ) context.on_message('NodeQueriesComplete', notification)
def OnNotification( notification, context ): global initFailed global criticalSection global initCondition with criticalSection: notification_type = notification.type #print "OnNotification: %d" % type if notification_type == Notification.Type_DriverReady: print("Manager: Driver Ready!") initFailed = False elif notification_type == Notification.Type_DriverFailed: print("Manager: Driver Failed!") with initCondition: initFailed = True initCondition.notifyAll() elif notification_type == Notification.Type_DriverReset: print("Manager: Driver Reset!") elif notification_type == Notification.Type_AllNodesQueried: print("Manager: All Nodes Queried") with initCondition: initCondition.notifyAll() elif notification_type == Notification.Type_NodeAdded: print("Manager: Node Added %s" % (notification.node_id ) ) node_info = NodeInfo() node_info.network_id = notification.network_id node_info.node_id = notification.node_id nodes.append(node_info) elif notification_type == Notification.Type_NodeRemoved: print( "Manager: Node Removed %s" % (notification.node_id ) ) network_id = notification.network_id node_id = notification.node_id for node in nodes[:]: if node_id == node.node_id and network_id == node.network_id: nodes.remove(node) del node break elif notification_type == Notification.Type_ValueAdded: print("Manager: Value Added %s" % (notification.node_id ) ) node_info = get_node_info( notification ) if node_info is not None: node_info.value_ids.append( notification.value_id ) elif notification_type == Notification.Type_ValueChanged: node_info = get_node_info( notification ) network_id = node_info.network_id node_id = node_info.node_id value_id = notification.value_id value_type = Manager.get_value_type( value_id ) value_id = Manager.get_value_id( value_id ) value = Manager.get_value_as_string( value_id ) units = Manager.get_value_units( value_id ) node_name = Manager.get_node_name( network_id, node_id ) node_location_name = Manager.get_node_location_name( network_id, node_id ) print("%s" % str(datetime.now()), end="" ) print(" Node %03s: %s in %s changed %s to %s" % ( node_id, node_name, node_location_name, value_type, value )) elif notification_type == Notification.Type_NodeQueriesComplete: pass print("Manager: NodeQueriesComplete %s" % (notification.node_id ))