File tree Expand file tree Collapse file tree 1 file changed +8
-1
lines changed Expand file tree Collapse file tree 1 file changed +8
-1
lines changed Original file line number Diff line number Diff line change @@ -38,6 +38,7 @@ class SwitchbotDevice {
3838 this . _modelName = ad . serviceData . modelName ;
3939
4040 this . _was_connected_explicitly = false ;
41+ this . _connected = false ;
4142
4243 this . _onconnect = ( ) => { } ;
4344 this . _ondisconnect = ( ) => { } ;
@@ -59,7 +60,11 @@ class SwitchbotDevice {
5960 return this . _modelName ;
6061 }
6162 get connectionState ( ) {
62- return this . _peripheral . state ;
63+ if ( ! this . _connected && this . _peripheral . state === 'disconnecting' ) {
64+ return 'disconnected' ;
65+ } else {
66+ return this . _peripheral . state ;
67+ }
6368 }
6469
6570 // Setters
@@ -106,10 +111,12 @@ class SwitchbotDevice {
106111
107112 // Set event handlers for events fired on the `Peripheral` object
108113 this . _peripheral . once ( 'connect' , ( ) => {
114+ this . _connected = true ;
109115 this . _onconnect ( ) ;
110116 } ) ;
111117
112118 this . _peripheral . once ( 'disconnect' , ( ) => {
119+ this . _connected = false ;
113120 this . _chars = null ;
114121 this . _peripheral . removeAllListeners ( ) ;
115122 this . _ondisconnect_internal ( ) ;
You can’t perform that action at this time.
0 commit comments