-
Notifications
You must be signed in to change notification settings - Fork 23
/
Copy pathlock.js
39 lines (33 loc) · 1.04 KB
/
lock.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
'use strict';
const { TTLockClient, sleep } = require('../dist');
const fs = require('fs/promises');
const settingsFile = "lockData.json";
async function doStuff() {
let lockData = await require("./common/loadData")(settingsFile);
let options = require("./common/options")(lockData);
const client = new TTLockClient(options);
await client.prepareBTService();
client.startScanLock();
console.log("Scan started");
client.on("foundLock", async (lock) => {
console.log(lock.toJSON());
console.log();
if (lock.isInitialized() && lock.isPaired()) {
await lock.connect();
console.log("Trying to lock the lock");
console.log();
console.log();
const unlock = await lock.lock();
await lock.disconnect();
const newLockData = client.getLockData();
console.log(JSON.stringify(newLockData));
try {
await fs.writeFile(settingsFile, Buffer.from(JSON.stringify(newLockData)));
} catch (error) {
process.exit(1);
}
process.exit(0);
}
});
}
doStuff();