Exemple #1
0
 def queue_check(self):
     while self.queue.qsize():
         try:
             message, notification = self.queue.get_nowait()
             if message == 'NodeAdded':
                 self.add_node(notification)
             elif message == 'ValueAdded':
                 self.add_value(notification)
             elif message == 'ValueChanged':    
                 self.change_value(notification)
             elif message == 'NodeRemoved':
                 self.remove_node(notification)
             elif message == 'NodeChanged':
                 self.update_node(notification)
             elif message == 'NodeQueriesComplete':
                 self.node_queries_complete(notification)
             elif message == 'StatusUpdate':
                 self.status_update(notification)
         except Empty:
             pass
             
     if not self.running:
         Manager.close()
         print("Done")
         self.root.destroy()
         
     else:
         self.root.after(1000, self.queue_check)
Exemple #2
0
 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)
Exemple #3
0
 def run(self):
     self.running = 1
     Manager.add_watcher( OnNotification, self)
     Manager.read_config("manager.ini")
     
     #self.thread1 = threading.Thread(target=self.worker_thread)
     #self.thread1.start()
     self.queue_check()
Exemple #4
0
 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)    
Exemple #5
0
 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")
Exemple #6
0
 def update(self, value):
     self._value = str(value)
     notification = Notification( Notification.Type_ValueChanged )
     notification.node_id = self.__node_id
     notification.network_id = self.__network_id
     notification.value_id = self.__id
     from has.manager.manager import Manager
     driver = Manager.get_driver( self.__network_id )
     driver.queue_notification( notification )
Exemple #7
0
    def set(self, value):
        if( self.is_read_only ):
            logger.debug("Value:set ValueType:%s is read only" % self.value_type)
            return False
        
        from has.manager.manager import Manager
        driver = Manager.get_driver( self.__network_id ) 
        if driver is not None:
            node = driver.get_node_unsafe( self.__node_id )
            if node is not None:
                node.set_value( self, value )
                return True

        return False
Exemple #8
0
 def get_as_string(self):
     from  has.manager.manager import Manager  # to avoid import loop
     driver = Manager.get_driver( self.__network_id )
     node = driver.get_node_unsafe( self.__node_id )
     result = "{0}{1}".format(self._value, self.__units)
     return result
Exemple #9
0
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)
Exemple #10
0
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 ))
Exemple #11
0
            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 ))
            


        
if __name__ == "__main__":
    
    initCondition.acquire()
    
    Manager.add_watcher( OnNotification, None)
    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)
Exemple #12
0
 def driver(self):
     from has.manager.manager import Manager
     driver = Manager.get_driver( self._network_id )
     return driver