Skip to content

Commit ca5f050

Browse files
committed
Bump noble to v2.3.4
1 parent d3d9ad6 commit ca5f050

File tree

4 files changed

+43
-57
lines changed

4 files changed

+43
-57
lines changed

package-lock.json

Lines changed: 37 additions & 18 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@
5151
},
5252
"readmeFilename": "README.md",
5353
"dependencies": {
54-
"@stoprocent/noble": "^1.19.1",
54+
"@stoprocent/noble": "^2.3.4",
5555
"async-mutex": "^0.5.0",
5656
"undici": "7.4.0"
5757
},

src/device.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -229,7 +229,7 @@ export interface Chars {
229229
}
230230

231231
export interface NobleTypes {
232-
noble: typeof Noble
232+
noble: Noble.Noble
233233
state: 'unknown' | 'resetting' | 'unsupported' | 'unauthorized' | 'poweredOff' | 'poweredOn'
234234
peripheral: Noble.Peripheral
235235
}
@@ -380,8 +380,8 @@ export class SwitchbotDevice extends EventEmitter {
380380
* @returns A Promise that resolves when the connection is complete.
381381
*/
382382
public async internalConnect(): Promise<void> {
383-
if (this.noble._state !== 'poweredOn') {
384-
throw new Error(`The Bluetooth status is ${this.noble._state}, not poweredOn.`)
383+
if (this.noble.state !== 'poweredOn') {
384+
throw new Error(`The Bluetooth status is ${this.noble.state}, not poweredOn.`)
385385
}
386386

387387
const state = this.connectionState

src/switchbot-ble.ts

Lines changed: 2 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -72,39 +72,6 @@ export class SwitchBotBLE extends EventEmitter {
7272
}
7373
}
7474

75-
/**
76-
* Waits for the noble object to be powered on.
77-
*
78-
* @returns {Promise<void>} - Resolves when the noble object is powered on.
79-
*/
80-
private async waitForPowerOn(): Promise<void> {
81-
await this.ready
82-
if (this.noble && this.noble._state === 'poweredOn') {
83-
return
84-
}
85-
86-
return new Promise<void>((resolve, reject) => {
87-
this.noble?.once('stateChange', (state: NobleTypes['state']) => {
88-
switch (state) {
89-
case 'unsupported':
90-
case 'unauthorized':
91-
case 'poweredOff':
92-
reject(new Error(`Failed to initialize the Noble object: ${state}`))
93-
break
94-
case 'resetting':
95-
case 'unknown':
96-
reject(new Error(`Adapter is not ready: ${state}`))
97-
break
98-
case 'poweredOn':
99-
resolve()
100-
break
101-
default:
102-
reject(new Error(`Unknown state: ${state}`))
103-
}
104-
})
105-
})
106-
}
107-
10875
/**
10976
* Discovers Switchbot devices.
11077
* @param params The discovery parameters.
@@ -119,7 +86,7 @@ export class SwitchBotBLE extends EventEmitter {
11986
quick: { required: false, type: 'boolean' },
12087
})
12188

122-
await this.waitForPowerOn()
89+
await this.noble.waitForPoweredOnAsync()
12390

12491
if (!this.noble) {
12592
throw new Error('noble failed to initialize')
@@ -265,7 +232,7 @@ export class SwitchBotBLE extends EventEmitter {
265232
id: { required: false, type: 'string', min: 12, max: 17 },
266233
})
267234

268-
await this.waitForPowerOn()
235+
await this.noble.waitForPoweredOnAsync()
269236

270237
if (!this.noble) {
271238
throw new Error('noble object failed to initialize')

0 commit comments

Comments
 (0)