homebridge-lovesac-stealthtech 1.1.3 → 1.1.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/ble/BleClient.js +22 -12
- package/package.json +2 -2
package/dist/ble/BleClient.js
CHANGED
|
@@ -1,11 +1,21 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
3
|
exports.BleClient = void 0;
|
|
7
|
-
const noble_1 = __importDefault(require("@stoprocent/noble"));
|
|
8
4
|
const settings_1 = require("../settings");
|
|
5
|
+
// Lazy-import noble to avoid opening an HCI socket in Homebridge's main
|
|
6
|
+
// process. The top-level import runs during plugin registration (main
|
|
7
|
+
// process), but BLE is only used in the child bridge. Deferring the
|
|
8
|
+
// require() ensures the HCI socket is only opened once, in the child.
|
|
9
|
+
// eslint-disable-next-line @typescript-eslint/no-require-imports
|
|
10
|
+
const getNoble = (() => {
|
|
11
|
+
let instance = null;
|
|
12
|
+
return () => {
|
|
13
|
+
if (!instance) {
|
|
14
|
+
instance = require('@stoprocent/noble');
|
|
15
|
+
}
|
|
16
|
+
return instance;
|
|
17
|
+
};
|
|
18
|
+
})();
|
|
9
19
|
class BleClient {
|
|
10
20
|
log;
|
|
11
21
|
peripheral = null;
|
|
@@ -71,7 +81,7 @@ class BleClient {
|
|
|
71
81
|
else {
|
|
72
82
|
peripheral.disconnectAsync().catch(() => { });
|
|
73
83
|
}
|
|
74
|
-
|
|
84
|
+
getNoble().reset();
|
|
75
85
|
throw err;
|
|
76
86
|
}
|
|
77
87
|
this._connected = true;
|
|
@@ -189,17 +199,17 @@ class BleClient {
|
|
|
189
199
|
resolve(peripheral);
|
|
190
200
|
};
|
|
191
201
|
const cleanup = () => {
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
202
|
+
getNoble().stopScanning();
|
|
203
|
+
getNoble().removeListener('discover', onDiscover);
|
|
204
|
+
getNoble().removeListener('stateChange', onStateChange);
|
|
195
205
|
};
|
|
196
206
|
const timeout = setTimeout(() => {
|
|
197
207
|
cleanup();
|
|
198
208
|
resolve(null);
|
|
199
209
|
}, settings_1.BLE_SCAN_TIMEOUT);
|
|
200
|
-
|
|
210
|
+
getNoble().on('discover', onDiscover);
|
|
201
211
|
const startScan = () => {
|
|
202
|
-
|
|
212
|
+
getNoble().startScanning([settings_1.SOFA_SERVICE_UUID_SHORT], false, (err) => {
|
|
203
213
|
if (err) {
|
|
204
214
|
clearTimeout(timeout);
|
|
205
215
|
cleanup();
|
|
@@ -217,11 +227,11 @@ class BleClient {
|
|
|
217
227
|
reject(new Error(`Bluetooth adapter state: ${state}`));
|
|
218
228
|
}
|
|
219
229
|
};
|
|
220
|
-
if (
|
|
230
|
+
if (getNoble().state === 'poweredOn') {
|
|
221
231
|
startScan();
|
|
222
232
|
}
|
|
223
233
|
else {
|
|
224
|
-
|
|
234
|
+
getNoble().once('stateChange', onStateChange);
|
|
225
235
|
}
|
|
226
236
|
});
|
|
227
237
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "homebridge-lovesac-stealthtech",
|
|
3
|
-
"version": "1.1.
|
|
3
|
+
"version": "1.1.5",
|
|
4
4
|
"description": "Homebridge plugin for Lovesac StealthTech Sound + Charge BLE control",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"files": [
|
|
@@ -40,7 +40,7 @@
|
|
|
40
40
|
"homebridge": "^1.8.0 || ^2.0.0-beta.0"
|
|
41
41
|
},
|
|
42
42
|
"dependencies": {
|
|
43
|
-
"@stoprocent/noble": "^
|
|
43
|
+
"@stoprocent/noble": "^2.3.17"
|
|
44
44
|
},
|
|
45
45
|
"peerDependencies": {
|
|
46
46
|
"hap-nodejs": ">=0.12.0",
|