def add_value(self, notification): item_id = "{0}:{1}".format(notification.network_id, notification.node_id) obj_value_id = notification.value_id value_type = Manager.get_value_type( obj_value_id ) value = Manager.get_value_as_string( obj_value_id ) last_changed = Manager.get_value_last_changed(obj_value_id) text="{0}={1} ({2})".format(value_type,value,last_changed) self.tree.insert(item_id,"end", obj_value_id.id, text=text)
def change_value(self, notification): obj_value_id = notification.value_id if self.tree.exists(obj_value_id.id): value_type = Manager.get_value_type( obj_value_id ) value = Manager.get_value_as_string( obj_value_id ) last_changed = Manager.get_value_last_changed(obj_value_id) text="{0}={1} ({2})".format(value_type,value,last_changed) self.tree.item(obj_value_id.id, text=text, tags=('updated')) self.root.after(10000, self.reset_foreground, obj_value_id.id)
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 ))
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) desc = Manager.get_node_description(node.network_id, node.node_id) if desc == "window": 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) ) print("------------------------------------------------------------")