File tree Expand file tree Collapse file tree 1 file changed +13
-2
lines changed
Expand file tree Collapse file tree 1 file changed +13
-2
lines changed Original file line number Diff line number Diff line change @@ -171,7 +171,11 @@ export class SwitchBotBLE extends EventEmitter {
171171 this . log ( 'error' , `discover stopScanningAsync error: ${ JSON . stringify ( e . message ?? e ) } ` )
172172 }
173173 }
174- return Object . values ( peripherals )
174+ const devices = Object . values ( peripherals )
175+ if ( devices . length === 0 ) {
176+ this . log ( 'warn' , 'No devices found during discovery.' )
177+ }
178+ return devices
175179 }
176180
177181 return new Promise < SwitchbotDevice [ ] > ( ( resolve , reject ) => {
@@ -192,7 +196,14 @@ export class SwitchBotBLE extends EventEmitter {
192196
193197 this . noble . startScanningAsync ( PRIMARY_SERVICE_UUID_LIST , false )
194198 . then ( ( ) => {
195- timer = setTimeout ( async ( ) => resolve ( await finishDiscovery ( ) ) , p . duration )
199+ timer = setTimeout ( async ( ) => {
200+ const result = await finishDiscovery ( )
201+ if ( result . length === 0 ) {
202+ reject ( new Error ( 'No devices found during discovery.' ) )
203+ } else {
204+ resolve ( result )
205+ }
206+ } , p . duration )
196207 } )
197208 . catch ( reject )
198209 } )
You can’t perform that action at this time.
0 commit comments