Skip to content

Commit 01cce41

Browse files
Fix for @abandonware/nobles breaking changes that cause: TypeError: this.noble.once is not a function.
1 parent d8a25e8 commit 01cce41

File tree

6 files changed

+94
-2771
lines changed

6 files changed

+94
-2771
lines changed

CHANGELOG.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,14 @@
22

33
All notable changes to this project will be documented in this file. This project uses [Semantic Versioning](https://semver.org/)
44

5+
## [Version 1.7.1](https://github.com/OpenWonderLabs/node-switchbot/releases/tag/v1.7.1) (2022-12-20)
6+
7+
## What's Changed
8+
9+
- Fix for @abandonware/nobles breaking changes that cause: `TypeError: this.noble.once is not a function`.
10+
11+
**Full Changelog**: https://github.com/OpenWonderLabs/node-switchbot/compare/v1.7.0...v1.7.1
12+
513
## [Version 1.7.0](https://github.com/OpenWonderLabs/node-switchbot/releases/tag/v1.7.0) (2022-12-08)
614

715
## What's Changed

errros.log

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
2+
/usr/local/lib/node_modules/@switchbot/homebridge-switchbot/node_modules/node-switchbot/node_modules/@abandonware/noble/lib/noble.js:137
3+
this._bindings.startScanning(serviceUuids, allowDuplicates);
4+
^
5+
TypeError: A string was expected
6+
at Noble.scan (/usr/local/lib/node_modules/@switchbot/homebridge-switchbot/node_modules/node-switchbot/node_modules/@abandonware/noble/lib/noble.js:137:22)
7+
at Noble.startScanning (/usr/local/lib/node_modules/@switchbot/homebridge-switchbot/node_modules/node-switchbot/node_modules/@abandonware/noble/lib/noble.js:149:10)
8+
at /usr/local/lib/node_modules/@switchbot/homebridge-switchbot/node_modules/node-switchbot/node_modules/@abandonware/noble/lib/noble.js:155:44
9+
at node:internal/util:364:7
10+
at new Promise (<anonymous>)
11+
at node:internal/util:350:12
12+
at Noble.startScanningAsync (/usr/local/lib/node_modules/@switchbot/homebridge-switchbot/node_modules/node-switchbot/node_modules/@abandonware/noble/lib/noble.js:155:99)
13+
at /usr/local/lib/node_modules/@switchbot/homebridge-switchbot/node_modules/node-switchbot/lib/switchbot.js:374:22

lib/switchbot-device.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ class SwitchbotDevice {
131131
});
132132

133133
// Connect
134-
this._peripheral.connect((error) => {
134+
this._peripheral.connectAsync((error) => {
135135
if (error) {
136136
reject(error);
137137
return;
@@ -145,7 +145,7 @@ class SwitchbotDevice {
145145
resolve();
146146
})
147147
.catch((error) => {
148-
this._peripheral.disconnect();
148+
this._peripheral.disconnectAsync();
149149
reject(error);
150150
});
151151
});
@@ -224,7 +224,7 @@ class SwitchbotDevice {
224224

225225
_discoverServices() {
226226
return new Promise((resolve, reject) => {
227-
this._peripheral.discoverServices([], (error, service_list) => {
227+
this._peripheral.discoverServicesAsync([], (error, service_list) => {
228228
if (error) {
229229
reject(error);
230230
return;
@@ -321,7 +321,7 @@ class SwitchbotDevice {
321321
// Unsubscribe
322322
this._unsubscribe().then(() => {
323323
// Disconnect
324-
this._peripheral.disconnect(() => {
324+
this._peripheral.disconnectAsync(() => {
325325
resolve();
326326
});
327327
});

lib/switchbot.js

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ class Switchbot {
3030
if (params && params.noble) {
3131
noble = params.noble;
3232
} else {
33-
noble = require("@abandonware/noble");
33+
noble = require('@abandonware/noble')({extended: false});
3434
}
3535

3636
// Public properties
@@ -127,7 +127,7 @@ class Switchbot {
127127
clearTimeout(timer);
128128
}
129129
this.noble.removeAllListeners("discover");
130-
this.noble.stopScanning();
130+
this.noble.stopScanningAsync(() => process.exit());
131131
let device_list = [];
132132
for (let addr in peripherals) {
133133
device_list.push(peripherals[addr]);
@@ -155,7 +155,7 @@ class Switchbot {
155155
});
156156

157157
// Start scanning
158-
this.noble.startScanning(
158+
this.noble.startScanningAsync(
159159
this._PRIMARY_SERVICE_UUID_LIST,
160160
false,
161161
(error) => {
@@ -167,7 +167,7 @@ class Switchbot {
167167
finishDiscovery();
168168
}, p.duration);
169169
}
170-
);
170+
, false);
171171
})
172172
.catch((error) => {
173173
reject(error);
@@ -371,7 +371,7 @@ class Switchbot {
371371
});
372372

373373
// Start scanning
374-
this.noble.startScanning(
374+
this.noble.startScanningAsync(
375375
this._PRIMARY_SERVICE_UUID_LIST,
376376
true,
377377
(error) => {
@@ -381,7 +381,7 @@ class Switchbot {
381381
resolve();
382382
}
383383
}
384-
);
384+
, false);
385385
})
386386
.catch((error) => {
387387
reject(error);
@@ -402,7 +402,7 @@ class Switchbot {
402402
* ---------------------------------------------------------------- */
403403
stopScan() {
404404
this.noble.removeAllListeners("discover");
405-
this.noble.stopScanning();
405+
this.noble.stopScanningAsync(() => process.exit());
406406
}
407407

408408
/* ------------------------------------------------------------------

0 commit comments

Comments
 (0)