@@ -30,7 +30,7 @@ export class SwitchbotDevice {
3030 _onconnect : ( ) => void ;
3131 _ondisconnect : ( ) => void ;
3232 _ondisconnect_internal : ( ) => void ;
33- _onnotify_internal : ( ) => void ;
33+ _onnotify_internal : ( buf : Buffer ) => void ;
3434 /* ------------------------------------------------------------------
3535 * Constructor
3636 *
@@ -46,6 +46,13 @@ export class SwitchbotDevice {
4646
4747 this . _SERV_UUID_PRIMARY = 'cba20d00224d11e69fb80002a5d5c51b' ;
4848 this . _CHAR_UUID_WRITE = 'cba20002224d11e69fb80002a5d5c51b' ;
49+ this . _CHAR_UUID_NOTIFY = 'cba20003224d11e69fb80002a5d5c51b' ;
50+ this . _CHAR_UUID_DEVICE = '2a00' ;
51+
52+ this . _READ_TIMEOUT_MSEC = 3000 ;
53+ this . _WRITE_TIMEOUT_MSEC = 3000 ;
54+ this . _COMMAND_TIMEOUT_MSEC = 3000 ;
55+
4956 // Save the device information
5057 const ad : ad = Advertising . parse ( peripheral ) ;
5158 this . _id = ad ?. id ;
@@ -296,8 +303,8 @@ export class SwitchbotDevice {
296303 reject ( error ) ;
297304 return ;
298305 }
299- char . on ( 'data' , ( ) => { // Remove the argument passed to the _onnotify_internal function
300- this . _onnotify_internal ( ) ;
306+ char . on ( 'data' , ( buf ) => { // Remove the argument passed to the _onnotify_internal function
307+ this . _onnotify_internal ( buf ) ;
301308 } ) ;
302309 resolve ( ) ;
303310 } ) ;
@@ -459,14 +466,14 @@ export class SwitchbotDevice {
459466 // Write the specified Buffer data to the write characteristic
460467 // and receive the response from the notify characteristic
461468 // with connection handling
462- _command ( req_buf ) {
469+ _command ( req_buf : Buffer ) {
463470 return new Promise ( ( resolve , reject ) => {
464471 if ( ! Buffer . isBuffer ( req_buf ) ) {
465472 reject ( new Error ( 'The specified data is not acceptable for writing.' ) ) ;
466473 return ;
467474 }
468475
469- let res_buf ;
476+ let res_buf : Buffer | unknown ;
470477
471478 this . _connect ( )
472479 . then ( ( ) => {
@@ -493,15 +500,13 @@ export class SwitchbotDevice {
493500
494501 _waitCommandResponse ( ) {
495502 return new Promise ( ( resolve , reject ) => {
496- const buf : Buffer | null = null ;
497-
498503 let timer : NodeJS . Timeout | undefined = setTimeout ( ( ) => {
499504 timer = undefined ;
500505 this . _onnotify_internal = ( ) => { } ;
501506 reject ( new Error ( 'COMMAND_TIMEOUT' ) ) ;
502507 } , this . _COMMAND_TIMEOUT_MSEC ) ;
503508
504- this . _onnotify_internal = ( ) => {
509+ this . _onnotify_internal = ( buf ) => {
505510 if ( timer ) {
506511 clearTimeout ( timer ) ;
507512 timer = undefined ;
0 commit comments