@@ -20,9 +20,6 @@ import debugLogger from 'debug';
2020import dbus from 'dbus-next' ;
2121
2222const debug = debugLogger ( 'node-red-contrib-generic-ble:noble:bluez' ) ;
23- const CHRARACTERISTICS_DISCOVERY_TIMEOUT_MS = parseInt (
24- process . env . CHRARACTERISTICS_DISCOVERY_TIMEOUT_MS || '500'
25- ) ;
2623
2724// Workaround for a Jest Issue
2825// https://github.com/kulshekhar/ts-jest/issues/727#issuecomment-422747294
@@ -360,48 +357,30 @@ class BluezBindings extends EventEmitter {
360357 debug (
361358 `discoverCharacteristics:deviceUuid=>${ deviceUuid } ,serviceUuid=>${ serviceUuid } ,characteristicUuids=>${ characteristicUuids } `
362359 ) ;
363- let timeout = 0 ;
364- let discoveredCharacteristics = await this . _listCharacteristics (
360+ const discoveredCharacteristics = await this . _listCharacteristics (
365361 deviceUuid ,
366362 serviceUuid ,
367363 characteristicUuids
368364 ) ;
369- if ( ! discoveredCharacteristics ) {
370- timeout = CHRARACTERISTICS_DISCOVERY_TIMEOUT_MS ;
371- }
372- setTimeout ( async ( ) => {
373- if ( ! discoveredCharacteristics ) {
374- discoveredCharacteristics = await this . _listCharacteristics (
375- deviceUuid ,
376- serviceUuid ,
377- characteristicUuids
378- ) ;
365+ const resultChrs = Object . values ( discoveredCharacteristics || { } ) . map (
366+ ( chr ) => {
367+ return {
368+ uuid : this . _stripDashes ( chr . UUID . value ) ,
369+ properties : chr . Flags . value ,
370+ } ;
379371 }
380- const resultChrs = Object . values ( discoveredCharacteristics || { } ) . map (
381- ( chr ) => {
382- return {
383- uuid : this . _stripDashes ( chr . UUID . value ) ,
384- properties : chr . Flags . value ,
385- } ;
386- }
372+ ) ;
373+ debug ( `resultChrs => ${ JSON . stringify ( resultChrs ) } ` ) ;
374+ try {
375+ this . emit ( 'characteristicsDiscover' , deviceUuid , serviceUuid , resultChrs ) ;
376+ debug (
377+ `[${ deviceUuid } ] OK. Found ${ resultChrs . length } Characteristics. characteristicsDiscover event`
387378 ) ;
388- debug ( `resultChrs => ${ JSON . stringify ( resultChrs ) } ` ) ;
389- try {
390- this . emit (
391- 'characteristicsDiscover' ,
392- deviceUuid ,
393- serviceUuid ,
394- resultChrs
395- ) ;
396- debug (
397- `[${ deviceUuid } ] OK. Found ${ resultChrs . length } Characteristics.`
398- ) ;
399- } catch ( err ) {
400- debug (
401- `Failed to emit 'characteristicsDiscover' event. message:${ err . message } `
402- ) ;
403- }
404- } , timeout ) ;
379+ } catch ( err ) {
380+ debug (
381+ `Failed to emit 'characteristicsDiscover' event. message:${ err . message } `
382+ ) ;
383+ }
405384 }
406385
407386 async read ( deviceUuid , serviceUuid , characteristicUuid ) {
0 commit comments