File tree Expand file tree Collapse file tree 1 file changed +27
-17
lines changed
Expand file tree Collapse file tree 1 file changed +27
-17
lines changed Original file line number Diff line number Diff line change @@ -437,28 +437,38 @@ export default function(RED) {
437437 if ( readables . length === 0 ) {
438438 return Promise . resolve ( ) ;
439439 }
440+ let notifiables = this . characteristics . filter ( c => {
441+ if ( c . notifiable ) {
442+ if ( uuids . length === 0 ) {
443+ return true ;
444+ }
445+ return uuids . indexOf ( c . uuid ) >= 0 ;
446+ }
447+ } ) ;
440448 // perform read here right now
441449 let readObj = { } ;
442- return Promise . all ( readables . map ( ( r ) => {
443- // {uuid:'characteristic-uuid-to-read'}
444- return new Promise ( ( resolve , reject ) => {
445- r . object . read (
446- ( err , data ) => {
447- if ( err ) {
450+ return Promise . all ( notifiables . map ( ( n ) => n . unsubscribe ( ) ) ) . then ( ( ) => {
451+ return Promise . all ( readables . map ( ( r ) => {
452+ // {uuid:'characteristic-uuid-to-read'}
453+ return new Promise ( ( resolve , reject ) => {
454+ r . object . read (
455+ ( err , data ) => {
456+ if ( err ) {
457+ if ( TRACE ) {
458+ this . log ( `<Read> ${ r . uuid } => FAIL` ) ;
459+ }
460+ return reject ( err ) ;
461+ }
448462 if ( TRACE ) {
449- this . log ( `<Read> ${ r . uuid } => FAIL ` ) ;
463+ this . log ( `<Read> ${ r . uuid } => ${ JSON . stringify ( data ) } ` ) ;
450464 }
451- return reject ( err ) ;
452- }
453- if ( TRACE ) {
454- this . log ( `<Read> ${ r . uuid } => ${ JSON . stringify ( data ) } ` ) ;
465+ readObj [ r . uuid ] = data ;
466+ resolve ( ) ;
455467 }
456- readObj [ r . uuid ] = data ;
457- resolve ( ) ;
458- }
459- ) ;
460- } ) ;
461- } ) ) . then ( ( ) => {
468+ ) ;
469+ } ) ;
470+ } ) ) ;
471+ } ) . then ( ( ) => {
462472 return readObj ;
463473 } ) ;
464474 } ) ;
You can’t perform that action at this time.
0 commit comments