コード例 #1
0
ファイル: signal.py プロジェクト: homecontrol/server
    def sql_load(sql, signal_id = None, order_by = None):
        Signal.sql_create(sql)
        
        if signal_id != None:
            sql.execute("SELECT id, dev_name, name, vendor, description, delay "
                        "FROM signals WHERE id=? LIMIT 0,1", (signal_id,))
        else:
            if order_by == None: order_by = "name"
            sql.execute("SELECT id, dev_name, name, vendor, description, delay "
                        "FROM signals ORDER BY ?", (order_by,))
            
        result = sql.fetchall()
        if signal_id != None and len(result) == 0:
            raise Exception("Could not find signal id \"%s\"" % signal_id)
            return None
        
        signals = []
        for data in result:
            signal = Signal()
            
            signal.id = get_value(data[0], "id", int, optional = True)
            signal.dev_name = get_value(data[1], "dev_name", str, optional = True)
            signal.name = get_value(data[2], "name", str, optional = True)
            signal.vendor = get_value(data[3], "vendor", str, optional = True)
            signal.description = get_value(data[4], "description", str, optional = True)
            signal.delay = get_value(data[5], "delay", int, optional = True)            

            for e in Event.sql_load(sql, signal_id = signal.id):
                signal.add_event(e)
                
            if signal_id != None: return signal
            signals.append(signal)
            
        return signals
コード例 #2
0
ファイル: listener.py プロジェクト: homecontrol/server
	def run(self):
					
		while not self.is_stopped():
			
			try:
				
				if not self.connect():
					time.sleep(0.5)
					continue
			
				data = self.conn.read_until("\n", self.timeout)
				if data == None or data == "": continue
				
				event = Event.from_json(data)
				if event == None: continue
					
				for (callback,filters) in self.callbacks:

					if not event.include(filters):
						continue
					
					# Append event to the callback's event stack	
					events = self.append_event(str(callback), event)
	
					# Call callback function.
					callback(event, events)
					
			except socket.timeout:
				continue
コード例 #3
0
ファイル: signal.py プロジェクト: homecontrol/server
    def from_json(data):
        
        if type(data) != type({}):
            data = json.loads(str(data).strip())

        signal = Signal()
        
        signal.id = get_value(data, "id", int, optional = True)
        signal.dev_name = get_value(data, "dev_name", str, optional = True)
        signal.name = get_value(data, "name", str, optional = True)
        signal.vendor = get_value(data, "vendor", str, optional = True)
        signal.description = get_value(data, "description", str, optional = True)
        signal.delay = get_value(data, "delay", int, optional = True)

        for e in data["events"]: 
            signal.add_event(Event.from_json(e))
                        
        return signal