Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 13 additions & 2 deletions src/switchbot-ble.ts
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,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 @@ -192,7 +196,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
Loading