-
Notifications
You must be signed in to change notification settings - Fork 11
/
Copy pathpair.js
45 lines (39 loc) · 1.27 KB
/
pair.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
const nubli = require('../dist/index.js').default;
nubli.setDebug(true);
nubli.onReadyToScan()
.then(() => {
console.log("Ready to scan :)");
nubli.startActiveScanning();
})
.catch((err) => {
console.log(err);
});
nubli.on("smartLockDiscovered", (smartlock) => {
nubli.stopScanning();
smartlock.on("connected", () => {
console.log("connected");
});
smartlock.connect()
.then(async () => {
if (smartlock.configExists()) {
await smartlock.readConfig();
}
if (smartlock.paired) {
console.log("already paired");
await smartlock.disconnect();
process.exit(0);
} else {
smartlock.pair()
.then(async () => {
console.log("successfully paired");
await smartlock.saveConfig(nubli.configPath);
await smartlock.disconnect();
process.exit(0);
})
.catch((error) => {
console.log("Pairing unsuccessful - error message: " + error);
process.exit(1);
});
}
});
});