node-switchbot 1.8.2 → 1.9.0-beta.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/switchbot-advertising.js +45 -0
- package/lib/switchbot.js +28 -22
- package/package.json +5 -5
|
@@ -110,6 +110,8 @@ class SwitchbotAdvertising {
|
|
|
110
110
|
sd = this._parseServiceDataForWoSensorTHPlus(buf, onlog);// WoMeterPlus
|
|
111
111
|
} else if (model === "r") {
|
|
112
112
|
sd = this._parseServiceDataForWoStrip(buf, onlog);// WoStrip
|
|
113
|
+
} else if (model === "w") {
|
|
114
|
+
sd = this._parseServiceDataForWoIOSensorTH(buf, manufacturerData, onlog); // Indoor/Outdoor Thermo-Hygrometer
|
|
113
115
|
} else {
|
|
114
116
|
if (onlog && typeof onlog === "function") {
|
|
115
117
|
onlog(
|
|
@@ -662,6 +664,49 @@ class SwitchbotAdvertising {
|
|
|
662
664
|
|
|
663
665
|
return data;
|
|
664
666
|
}
|
|
667
|
+
|
|
668
|
+
_parseServiceDataForWoIOSensorTH(serviceDataBuf, manufacturerDataBuf, onlog) {
|
|
669
|
+
if (serviceDataBuf.length !== 3) {
|
|
670
|
+
if (onlog && typeof onlog === "function") {
|
|
671
|
+
onlog(
|
|
672
|
+
`[_parseServiceDataForWoIOSensorTH] Service Data Buffer length ${serviceDataBuf.length} !== 3!`
|
|
673
|
+
);
|
|
674
|
+
}
|
|
675
|
+
return null;
|
|
676
|
+
}
|
|
677
|
+
if (manufacturerDataBuf.length !== 14) {
|
|
678
|
+
if (onlog && typeof onlog === "function") {
|
|
679
|
+
onlog(
|
|
680
|
+
`[_parseServiceDataForWoIOSensorTH] Manufacturer Data Buffer length ${manufacturerDataBuf.length} !== 14!`
|
|
681
|
+
);
|
|
682
|
+
}
|
|
683
|
+
return null;
|
|
684
|
+
}
|
|
685
|
+
const mdByte10 = manufacturerDataBuf.readUInt8(10);
|
|
686
|
+
const mdByte11 = manufacturerDataBuf.readUInt8(11);
|
|
687
|
+
const mdByte12 = manufacturerDataBuf.readUInt8(12);
|
|
688
|
+
|
|
689
|
+
const sdByte2 = serviceDataBuf.readUInt8(2);
|
|
690
|
+
|
|
691
|
+
const temp_sign = mdByte11 & 0b10000000 ? 1 : -1;
|
|
692
|
+
const temp_c = temp_sign * ((mdByte11 & 0b01111111) + (mdByte10 & 0b00001111) / 10);
|
|
693
|
+
const temp_f = Math.round(((temp_c * 9 / 5) + 32) * 10) / 10;
|
|
694
|
+
|
|
695
|
+
const data = {
|
|
696
|
+
model: "w",
|
|
697
|
+
modelName: "WoIOSensorTH",
|
|
698
|
+
temperature: {
|
|
699
|
+
c: temp_c,
|
|
700
|
+
f: temp_f,
|
|
701
|
+
},
|
|
702
|
+
fahrenheit: mdByte12 & 0b10000000 ? true : false, // needs to be confirmed!
|
|
703
|
+
humidity: mdByte12 & 0b01111111,
|
|
704
|
+
battery: sdByte2 & 0b01111111,
|
|
705
|
+
};
|
|
706
|
+
|
|
707
|
+
console.log(data);
|
|
708
|
+
return data;
|
|
709
|
+
}
|
|
665
710
|
}
|
|
666
711
|
|
|
667
712
|
module.exports = new SwitchbotAdvertising();
|
package/lib/switchbot.js
CHANGED
|
@@ -196,29 +196,35 @@ class Switchbot {
|
|
|
196
196
|
_init() {
|
|
197
197
|
const promise = new Promise((resolve, reject) => {
|
|
198
198
|
let err;
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
"Failed to initialize the Noble object: " + this.noble.state
|
|
203
|
-
);
|
|
204
|
-
reject(err);
|
|
205
|
-
return;
|
|
206
|
-
case ("resetting", "unknown"):
|
|
207
|
-
err = new Error(
|
|
208
|
-
"Adapter is not ready: " + this.noble.state
|
|
209
|
-
);
|
|
210
|
-
reject(err);
|
|
211
|
-
return;
|
|
212
|
-
case "poweredOn":
|
|
213
|
-
resolve();
|
|
214
|
-
return;
|
|
215
|
-
default:
|
|
216
|
-
err = new Error(
|
|
217
|
-
"Uknown state: " + this.noble.state
|
|
218
|
-
);
|
|
219
|
-
reject(err);
|
|
220
|
-
return;
|
|
199
|
+
if (this.noble.state === "poweredOn") {
|
|
200
|
+
resolve();
|
|
201
|
+
return;
|
|
221
202
|
}
|
|
203
|
+
this.noble.once('stateChange', state => {
|
|
204
|
+
switch (state) {
|
|
205
|
+
case ("unsupported", "unauthorized", "poweredOff"):
|
|
206
|
+
err = new Error(
|
|
207
|
+
"Failed to initialize the Noble object: " + this.noble.state
|
|
208
|
+
);
|
|
209
|
+
reject(err);
|
|
210
|
+
return;
|
|
211
|
+
case ("resetting", "unknown"):
|
|
212
|
+
err = new Error(
|
|
213
|
+
"Adapter is not ready: " + this.noble.state
|
|
214
|
+
);
|
|
215
|
+
reject(err);
|
|
216
|
+
return;
|
|
217
|
+
case "poweredOn":
|
|
218
|
+
resolve();
|
|
219
|
+
return;
|
|
220
|
+
default:
|
|
221
|
+
err = new Error(
|
|
222
|
+
"Uknown state: " + this.noble.state
|
|
223
|
+
);
|
|
224
|
+
reject(err);
|
|
225
|
+
return;
|
|
226
|
+
}
|
|
227
|
+
});
|
|
222
228
|
});
|
|
223
229
|
return promise;
|
|
224
230
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "node-switchbot",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.9.0-beta.1",
|
|
4
4
|
"description": "The node-switchbot is a Node.js module which allows you to control your Switchbot Devices through Bluetooth (BLE).",
|
|
5
5
|
"main": "./lib/switchbot.js",
|
|
6
6
|
"files": [
|
|
@@ -36,13 +36,13 @@
|
|
|
36
36
|
},
|
|
37
37
|
"readmeFilename": "README.md",
|
|
38
38
|
"dependencies": {
|
|
39
|
-
"@abandonware/noble": "1.9.2-
|
|
39
|
+
"@abandonware/noble": "^1.9.2-23"
|
|
40
40
|
},
|
|
41
41
|
"optionalDependencies": {
|
|
42
|
-
"@abandonware/bluetooth-hci-socket": "0.5.3-10"
|
|
42
|
+
"@abandonware/bluetooth-hci-socket": "^0.5.3-10"
|
|
43
43
|
},
|
|
44
44
|
"devDependencies": {
|
|
45
|
-
"eslint": "^8.
|
|
46
|
-
"npm-check-updates": "^16.
|
|
45
|
+
"eslint": "^8.48.0",
|
|
46
|
+
"npm-check-updates": "^16.13.2"
|
|
47
47
|
}
|
|
48
48
|
}
|