def node_queries_complete(self, notification): item_id = "{0}:{1}".format(notification.network_id, notification.node_id) node_name = Manager.get_node_name( notification.network_id, notification.node_id ) node_location_name = Manager.get_node_location_name( notification.network_id, notification.node_id ) node_type = Manager.get_node_type( notification.network_id, notification.node_id ) #print(node_location_name) if not self.tree.exists(node_location_name): self.tree.insert("", "end", node_location_name, text=node_location_name) text = "{1} (Node:{0}:{2})".format(notification.node_id, node_name, node_type) self.tree.item(item_id, text=text) self.tree.move(item_id, node_location_name, "end")
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 ))
Manager.read_config("manager.ini") print("Condition wait") initCondition.wait(60) print("Condition relese") print("Pending drivers %s:" % Manager.pending_drivers) print("Ready drivers %s:" % Manager.ready_drivers) initCondition.release() if not initFailed: print("------------------------------------------------------------") for node in nodes: is_light = Manager.is_node_light(node.network_id, node.node_id) is_dead = Manager.is_node_dead(node.network_id, node.node_id) node_type = Manager.get_node_type(node.network_id, node.node_id) name = Manager.get_node_name(node.network_id, node.node_id) room = Manager.get_node_location_name(node.network_id, node.node_id) desc = Manager.get_node_description(node.network_id, node.node_id) if is_light or True: print("Node id: %s, Name: %s, Room: %s, Type: %s, Light: %s, Dead: %s, Desc: %s" % (node.node_id, name, room, node_type, is_light, is_dead, desc) ) for valueID in node.value_ids: print("ValueID:%s Type: %s, Value %s" % ( valueID.id, Manager.get_value_type( valueID ), Manager.get_value( valueID ) )) print("------------------------------------------------------------") for node in nodes: is_light = Manager.is_node_light(node.network_id, node.node_id) is_dead = Manager.is_node_dead(node.network_id, node.node_id) node_type = Manager.get_node_type(node.network_id, node.node_id) name = Manager.get_node_name(node.network_id, node.node_id) room = Manager.get_node_location_name(node.network_id, node.node_id)