Skip to content

Commit

Permalink
Merge branch 'latest' into beta-3.3.1
Browse files Browse the repository at this point in the history
  • Loading branch information
donavanbecker committed Nov 18, 2024
2 parents 480379c + efdd310 commit 501db2c
Showing 1 changed file with 13 additions and 2 deletions.
15 changes: 13 additions & 2 deletions src/switchbot-ble.ts
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,11 @@ export class SwitchBotBLE extends EventEmitter {
this.log('error', `discover stopScanningAsync error: ${JSON.stringify(e.message ?? e)}`)
}
}
return Object.values(peripherals)
const devices = Object.values(peripherals)
if (devices.length === 0) {
this.log('warn', 'No devices found during discovery.')
}
return devices
}

return new Promise<SwitchbotDevice[]>((resolve, reject) => {
Expand All @@ -194,7 +198,14 @@ export class SwitchBotBLE extends EventEmitter {

this.noble.startScanningAsync(PRIMARY_SERVICE_UUID_LIST, false)
.then(() => {
timer = setTimeout(async () => resolve(await finishDiscovery()), p.duration)
timer = setTimeout(async () => {
const result = await finishDiscovery()
if (result.length === 0) {
reject(new Error('No devices found during discovery.'))
} else {
resolve(result)
}
}, p.duration)
})
.catch(reject)
})
Expand Down

0 comments on commit 501db2c

Please sign in to comment.