示例#1
0
 def code():
     uuid = request.args["state"]
     code = generate_code()
     print(code)
     with DeviceDatabase(SQL_DEVICES_URI, debug=DEBUG) as device_db:
         device_db = DeviceDatabase(SQL_DEVICES_URI, debug=DEBUG)
         device_db.add_unpaired_device(uuid, code)
         result = {"code": code, "uuid": uuid}
     return nice_json(result)
from personal_mycroft_backend.database.devices import DeviceDatabase

db = DeviceDatabase()

username = "******"
code = "XQFTNM"
uuid = "cc3524c7-ff52-42b3-af8f-de89249b19c8s"
mail = "fakemail2@not_real.com"

# add a device to the db
if not db.add_device(uuid):

    # cant commit device to db before pairing, make available for pairing
    db.add_unpaired_device(uuid, code)

    if not db.add_device(uuid):
        # user did not pair yet, perform manual pairing
        device = db.get_unpaired_by_code(code)
        if device:
            db.add_user(mail, username, "password")
            if db.add_device(uuid=device.uuid, mail=mail):
                db.remove_unpaired(device.uuid)

# Browse the db
device = db.get_device_by_uuid(uuid)
print(device.name)
print(device.last_seen)
print(device.created_at)
print(device.paired)
print(device.uuid)
print(device.ips)