def add_device(self, shortaddr, panid):
    if (self.conn == None):
        raise Exception('DBLogger requires active connection status.')
    self.conn.execute(('SELECT dev_id FROM devices WHERE %s AND %s LIMIT 1' % ((("short_addr = '%04x'" % shortaddr) if (shortaddr != None) else 'short_addr IS NULL'), (("pan_id = '%04x'" % panid) if (panid != None) else 'pan_id IS NULL'))))
    res = self.conn.fetchone()
    if (res != None):
        return res
    else:
        self.conn.execute(('INSERT INTO devices SET %s, %s' % ((("short_addr = '%04x'" % shortaddr) if (shortaddr != None) else 'short_addr = NULL'), (("pan_id = '%04x'" % panid) if (panid != None) else 'pan_id = NULL'))))
        if (self.conn.rowcount != 1):
            raise Exception('Device insert did not succeed.')
        self.db.commit()
        return self.conn.lastrowid
def add_device(self, shortaddr, panid):
    if (self.conn == None):
        raise Exception('DBLogger requires active connection status.')
    self.conn.execute(('SELECT dev_id FROM devices WHERE %s AND %s LIMIT 1' % ((("short_addr = '%04x'" % shortaddr) if (shortaddr != None) else 'short_addr IS NULL'), (("pan_id = '%04x'" % panid) if (panid != None) else 'pan_id IS NULL'))))
    res = self.conn.fetchone()
    if (res != None):
        return res
    else:
        self.conn.execute(('INSERT INTO devices SET %s, %s' % ((("short_addr = '%04x'" % shortaddr) if (shortaddr != None) else 'short_addr = NULL'), (("pan_id = '%04x'" % panid) if (panid != None) else 'pan_id = NULL'))))
        if (self.conn.rowcount != 1):
            raise Exception('Device insert did not succeed.')
        self.db.commit()
        return self.conn.lastrowid