node-switchbot 1.7.1 → 1.7.3-beta.0
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/lib/switchbot-device.js +7 -4
- package/lib/switchbot.js +10 -8
- package/package.json +3 -3
package/lib/switchbot-device.js
CHANGED
|
@@ -131,7 +131,7 @@ class SwitchbotDevice {
|
|
|
131
131
|
});
|
|
132
132
|
|
|
133
133
|
// Connect
|
|
134
|
-
this._peripheral.
|
|
134
|
+
this._peripheral.connect((error) => {
|
|
135
135
|
if (error) {
|
|
136
136
|
reject(error);
|
|
137
137
|
return;
|
|
@@ -145,7 +145,7 @@ class SwitchbotDevice {
|
|
|
145
145
|
resolve();
|
|
146
146
|
})
|
|
147
147
|
.catch((error) => {
|
|
148
|
-
this._peripheral.
|
|
148
|
+
this._peripheral.disconnect();
|
|
149
149
|
reject(error);
|
|
150
150
|
});
|
|
151
151
|
});
|
|
@@ -224,7 +224,7 @@ class SwitchbotDevice {
|
|
|
224
224
|
|
|
225
225
|
_discoverServices() {
|
|
226
226
|
return new Promise((resolve, reject) => {
|
|
227
|
-
this._peripheral.
|
|
227
|
+
this._peripheral.discoverServices([], (error, service_list) => {
|
|
228
228
|
if (error) {
|
|
229
229
|
reject(error);
|
|
230
230
|
return;
|
|
@@ -321,7 +321,7 @@ class SwitchbotDevice {
|
|
|
321
321
|
// Unsubscribe
|
|
322
322
|
this._unsubscribe().then(() => {
|
|
323
323
|
// Disconnect
|
|
324
|
-
this._peripheral.
|
|
324
|
+
this._peripheral.disconnect(() => {
|
|
325
325
|
resolve();
|
|
326
326
|
});
|
|
327
327
|
});
|
|
@@ -443,6 +443,9 @@ class SwitchbotDevice {
|
|
|
443
443
|
|
|
444
444
|
this._connect()
|
|
445
445
|
.then(() => {
|
|
446
|
+
if (!this._chars) {
|
|
447
|
+
return reject("No characteristics available.");
|
|
448
|
+
}
|
|
446
449
|
return this._write(this._chars.write, req_buf);
|
|
447
450
|
})
|
|
448
451
|
.then(() => {
|
package/lib/switchbot.js
CHANGED
|
@@ -30,7 +30,7 @@ class Switchbot {
|
|
|
30
30
|
if (params && params.noble) {
|
|
31
31
|
noble = params.noble;
|
|
32
32
|
} else {
|
|
33
|
-
noble = require(
|
|
33
|
+
noble = require("@abandonware/noble");
|
|
34
34
|
}
|
|
35
35
|
|
|
36
36
|
// Public properties
|
|
@@ -127,12 +127,14 @@ class Switchbot {
|
|
|
127
127
|
clearTimeout(timer);
|
|
128
128
|
}
|
|
129
129
|
this.noble.removeAllListeners("discover");
|
|
130
|
-
this.noble.
|
|
130
|
+
this.noble.stopScanning();
|
|
131
131
|
let device_list = [];
|
|
132
132
|
for (let addr in peripherals) {
|
|
133
133
|
device_list.push(peripherals[addr]);
|
|
134
134
|
}
|
|
135
|
-
|
|
135
|
+
if (device_list.length) {
|
|
136
|
+
resolve(device_list);
|
|
137
|
+
}
|
|
136
138
|
};
|
|
137
139
|
|
|
138
140
|
// Set a handler for the 'discover' event
|
|
@@ -155,7 +157,7 @@ class Switchbot {
|
|
|
155
157
|
});
|
|
156
158
|
|
|
157
159
|
// Start scanning
|
|
158
|
-
this.noble.
|
|
160
|
+
this.noble.startScanning(
|
|
159
161
|
this._PRIMARY_SERVICE_UUID_LIST,
|
|
160
162
|
false,
|
|
161
163
|
(error) => {
|
|
@@ -167,7 +169,7 @@ class Switchbot {
|
|
|
167
169
|
finishDiscovery();
|
|
168
170
|
}, p.duration);
|
|
169
171
|
}
|
|
170
|
-
|
|
172
|
+
);
|
|
171
173
|
})
|
|
172
174
|
.catch((error) => {
|
|
173
175
|
reject(error);
|
|
@@ -371,7 +373,7 @@ class Switchbot {
|
|
|
371
373
|
});
|
|
372
374
|
|
|
373
375
|
// Start scanning
|
|
374
|
-
this.noble.
|
|
376
|
+
this.noble.startScanning(
|
|
375
377
|
this._PRIMARY_SERVICE_UUID_LIST,
|
|
376
378
|
true,
|
|
377
379
|
(error) => {
|
|
@@ -381,7 +383,7 @@ class Switchbot {
|
|
|
381
383
|
resolve();
|
|
382
384
|
}
|
|
383
385
|
}
|
|
384
|
-
|
|
386
|
+
);
|
|
385
387
|
})
|
|
386
388
|
.catch((error) => {
|
|
387
389
|
reject(error);
|
|
@@ -402,7 +404,7 @@ class Switchbot {
|
|
|
402
404
|
* ---------------------------------------------------------------- */
|
|
403
405
|
stopScan() {
|
|
404
406
|
this.noble.removeAllListeners("discover");
|
|
405
|
-
this.noble.
|
|
407
|
+
this.noble.stopScanning();
|
|
406
408
|
}
|
|
407
409
|
|
|
408
410
|
/* ------------------------------------------------------------------
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "node-switchbot",
|
|
3
|
-
"version": "1.7.
|
|
3
|
+
"version": "1.7.3-beta.0",
|
|
4
4
|
"description": "The node-switchbot is a Node.js module which allows you to control your Switchbot Devices through Bluetooth (BLE).",
|
|
5
5
|
"main": "./lib/switchbot.js",
|
|
6
6
|
"files": [
|
|
@@ -37,6 +37,6 @@
|
|
|
37
37
|
"@abandonware/noble": "1.9.2-15"
|
|
38
38
|
},
|
|
39
39
|
"devDependencies": {
|
|
40
|
-
"npm-check-updates": "^16.6.
|
|
40
|
+
"npm-check-updates": "^16.6.2"
|
|
41
41
|
}
|
|
42
|
-
}
|
|
42
|
+
}
|