Skip to content

Commit da76a2a

Browse files
authored
Merge pull request #5 from zizi4n5/support/raspi_zero_w
feat: Added support for running on the Raspberry Pi Zero W.
2 parents 684e4bd + 017b244 commit da76a2a

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

lib/switchbot-device.js

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff 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();

0 commit comments

Comments
 (0)