-
Notifications
You must be signed in to change notification settings - Fork 11
/
requestAuthorizations.js
52 lines (42 loc) · 1.29 KB
/
requestAuthorizations.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
40
41
42
43
44
45
46
47
48
49
50
51
52
const nubli = require('../dist/index.js').default;
if (process.argv.length != 3) {
console.log("Security PIN as argument required.");
process.exit(1);
}
let pin = process.argv[2];
nubli.setDebug(true);
nubli.onReadyToScan()
.then(() => {
console.log("Ready to scan :)");
nubli.startScanning();
})
.catch((err) => {
console.log(err);
});
nubli.on("smartLockDiscovered", async (smartlock) => {
nubli.stopScanning();
smartlock.on("connected", () => {
console.log("connected");
});
if (smartlock.configExists()) {
await smartlock.readConfig();
}
smartlock.connect()
.then(async () => {
if (smartlock.paired) {
console.log("Good we're paired");
try {
let lockState = await smartlock.requestAuthorizations(pin);
console.log(JSON.stringify(lockState, null, 4));
} catch (error) {
console.log(error.message);
}
await smartlock.disconnect();
process.exit(0);
} else {
console.log("Pair first :(");
await smartlock.disconnect();
process.exit(1);
}
});
});