node-switchbot 1.7.3-beta.1 → 1.8.0-beta.0
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.
|
@@ -94,6 +94,8 @@ class SwitchbotAdvertising {
|
|
|
94
94
|
sd = this._parseServiceDataForWoContact(buf, onlog);//WoContact
|
|
95
95
|
} else if (model === "c") {
|
|
96
96
|
sd = this._parseServiceDataForWoCurtain(buf, onlog);// WoCurtain
|
|
97
|
+
} else if (model === "x") {
|
|
98
|
+
sd = this._parseServiceDataForWoBlindTilt(buf, onlog);// WoBlindTilt
|
|
97
99
|
} else if (model === "u") {
|
|
98
100
|
sd = this._parseServiceDataForWoBulb(manufacturerData, onlog);// WoBulb
|
|
99
101
|
} else if (model === "g") {
|
|
@@ -365,6 +367,41 @@ class SwitchbotAdvertising {
|
|
|
365
367
|
return data;
|
|
366
368
|
}
|
|
367
369
|
|
|
370
|
+
_parseServiceDataForWoBlindTilt(buf, onlog) {
|
|
371
|
+
if (buf.length !== 5 && buf.length !== 6) {
|
|
372
|
+
if (onlog && typeof onlog === "function") {
|
|
373
|
+
onlog(
|
|
374
|
+
`[_parseServiceDataForWoBlindTilt] Buffer length ${buf.length} !== 5 or 6!`
|
|
375
|
+
);
|
|
376
|
+
}
|
|
377
|
+
return null;
|
|
378
|
+
}
|
|
379
|
+
let byte1 = buf.readUInt8(1);
|
|
380
|
+
let byte2 = buf.readUInt8(2);
|
|
381
|
+
let byte3 = buf.readUInt8(3);
|
|
382
|
+
let byte4 = buf.readUInt8(4);
|
|
383
|
+
|
|
384
|
+
let calibration = byte1 & 0b01000000 ? true : false; // Whether the calibration is completed
|
|
385
|
+
let battery = byte2 & 0b01111111; // %
|
|
386
|
+
let inMotion = byte3 & 0b10000000 ? true : false;
|
|
387
|
+
let currPosition = byte3 & 0b01111111; // current positon %
|
|
388
|
+
let lightLevel = (byte4 >> 4) & 0b00001111; // light sensor level (1-10)
|
|
389
|
+
let deviceChain = byte4 & 0b00000111;
|
|
390
|
+
|
|
391
|
+
let data = {
|
|
392
|
+
model: "x",
|
|
393
|
+
modelName: "WoBlindTilt",
|
|
394
|
+
calibration: calibration,
|
|
395
|
+
battery: battery,
|
|
396
|
+
inMotion: inMotion,
|
|
397
|
+
position: currPosition,
|
|
398
|
+
lightLevel: lightLevel,
|
|
399
|
+
deviceChain: deviceChain,
|
|
400
|
+
};
|
|
401
|
+
|
|
402
|
+
return data;
|
|
403
|
+
}
|
|
404
|
+
|
|
368
405
|
_parseServiceDataForWoBulb(manufacturerData, onlog) {
|
|
369
406
|
if (manufacturerData.length !== 13) {
|
|
370
407
|
if (onlog && typeof onlog === "function") {
|
|
@@ -0,0 +1,117 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
let SwitchbotDevice = require("./switchbot-device.js");
|
|
3
|
+
|
|
4
|
+
class SwitchbotDeviceWoBlindTilt extends SwitchbotDevice {
|
|
5
|
+
/* ------------------------------------------------------------------
|
|
6
|
+
* open()
|
|
7
|
+
* - Open the blindtilt
|
|
8
|
+
*
|
|
9
|
+
* [Arguments]
|
|
10
|
+
* - none
|
|
11
|
+
*
|
|
12
|
+
* [Return value]
|
|
13
|
+
* - Promise object
|
|
14
|
+
* Nothing will be passed to the `resolve()`.
|
|
15
|
+
* ---------------------------------------------------------------- */
|
|
16
|
+
open() {
|
|
17
|
+
return this._operateBlindTilt([0x57, 0x0f, 0x45, 0x01, 0x05, 0xff, 0x00]);
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
/* ------------------------------------------------------------------
|
|
21
|
+
* close()
|
|
22
|
+
* - close the blindtilt
|
|
23
|
+
*
|
|
24
|
+
* [Arguments]
|
|
25
|
+
* - none
|
|
26
|
+
*
|
|
27
|
+
* [Return value]
|
|
28
|
+
* - Promise object
|
|
29
|
+
* Nothing will be passed to the `resolve()`.
|
|
30
|
+
* ---------------------------------------------------------------- */
|
|
31
|
+
close() {
|
|
32
|
+
return this._operateBlindTilt([0x57, 0x0f, 0x45, 0x01, 0x05, 0xff, 0x64]);
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
/* ------------------------------------------------------------------
|
|
36
|
+
* pause()
|
|
37
|
+
* - pause the blindtilt
|
|
38
|
+
*
|
|
39
|
+
* [Arguments]
|
|
40
|
+
* - none
|
|
41
|
+
*
|
|
42
|
+
* [Return value]
|
|
43
|
+
* - Promise object
|
|
44
|
+
* Nothing will be passed to the `resolve()`.
|
|
45
|
+
* ---------------------------------------------------------------- */
|
|
46
|
+
pause() {
|
|
47
|
+
return this._operateBlindTilt([0x57, 0x0f, 0x45, 0x01, 0x00, 0xff]);
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
/* ------------------------------------------------------------------
|
|
51
|
+
* runToPos()
|
|
52
|
+
* - run to the targe position
|
|
53
|
+
*
|
|
54
|
+
* [Arguments]
|
|
55
|
+
* - percent | number | Required | the percentage of target position
|
|
56
|
+
*
|
|
57
|
+
* [Return value]
|
|
58
|
+
* - Promise object
|
|
59
|
+
* Nothing will be passed to the `resolve()`.
|
|
60
|
+
* ---------------------------------------------------------------- */
|
|
61
|
+
runToPos(percent, mode) {
|
|
62
|
+
if (typeof percent != "number") {
|
|
63
|
+
return new Promise((resolve, reject) => {
|
|
64
|
+
reject(
|
|
65
|
+
new Error(
|
|
66
|
+
"The type of target position percentage is incorrent: " +
|
|
67
|
+
typeof percent
|
|
68
|
+
)
|
|
69
|
+
);
|
|
70
|
+
});
|
|
71
|
+
}
|
|
72
|
+
if (mode == null) {
|
|
73
|
+
mode = 0xff;
|
|
74
|
+
} else {
|
|
75
|
+
if (typeof mode != "number") {
|
|
76
|
+
return new Promise((resolve, reject) => {
|
|
77
|
+
reject(
|
|
78
|
+
new Error("The type of running mode is incorrent: " + typeof mode)
|
|
79
|
+
);
|
|
80
|
+
});
|
|
81
|
+
}
|
|
82
|
+
if (mode > 1) {
|
|
83
|
+
mode = 0xff;
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
if (percent > 100) {
|
|
87
|
+
percent = 100;
|
|
88
|
+
} else if (percent < 0) {
|
|
89
|
+
percent = 0;
|
|
90
|
+
}
|
|
91
|
+
return this._operateBlindTilt([0x57, 0x0f, 0x45, 0x01, 0x05, mode, percent]);
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
_operateBlindTilt(bytes) {
|
|
95
|
+
return new Promise((resolve, reject) => {
|
|
96
|
+
let req_buf = Buffer.from(bytes);
|
|
97
|
+
this._command(req_buf)
|
|
98
|
+
.then((res_buf) => {
|
|
99
|
+
let code = res_buf.readUInt8(0);
|
|
100
|
+
if (res_buf.length === 3 && code === 0x01) {
|
|
101
|
+
resolve();
|
|
102
|
+
} else {
|
|
103
|
+
reject(
|
|
104
|
+
new Error(
|
|
105
|
+
"The device returned an error: 0x" + res_buf.toString("hex")
|
|
106
|
+
)
|
|
107
|
+
);
|
|
108
|
+
}
|
|
109
|
+
})
|
|
110
|
+
.catch((error) => {
|
|
111
|
+
reject(error);
|
|
112
|
+
});
|
|
113
|
+
});
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
module.exports = SwitchbotDeviceWoBlindTilt;
|
package/lib/switchbot.js
CHANGED
|
@@ -5,6 +5,7 @@ let switchbotAdvertising = require("./switchbot-advertising.js");
|
|
|
5
5
|
let SwitchbotDevice = require("./switchbot-device.js");
|
|
6
6
|
let SwitchbotDeviceWoHand = require("./switchbot-device-wohand.js");
|
|
7
7
|
let SwitchbotDeviceWoCurtain = require("./switchbot-device-wocurtain.js");
|
|
8
|
+
let SwitchbotDeviceWoBlindTilt = require("./switchbot-device-woblindtilt.js");
|
|
8
9
|
let SwitchbotDeviceWoPresence = require("./switchbot-device-wopresence.js");
|
|
9
10
|
let SwitchbotDeviceWoContact = require("./switchbot-device-wocontact.js");
|
|
10
11
|
let SwitchbotDeviceWoSensorTH = require("./switchbot-device-wosensorth.js");
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "node-switchbot",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.8.0-beta.0",
|
|
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": [
|
|
@@ -20,6 +20,7 @@
|
|
|
20
20
|
"temperature",
|
|
21
21
|
"humidity",
|
|
22
22
|
"curtain",
|
|
23
|
+
"blind",
|
|
23
24
|
"BLE",
|
|
24
25
|
"Bluetooth Low Energy",
|
|
25
26
|
"Bluetooth smart",
|
|
@@ -37,6 +38,6 @@
|
|
|
37
38
|
"@abandonware/noble": "^1.9.2-19"
|
|
38
39
|
},
|
|
39
40
|
"devDependencies": {
|
|
40
|
-
"npm-check-updates": "^16.6.
|
|
41
|
+
"npm-check-updates": "^16.6.3"
|
|
41
42
|
}
|
|
42
43
|
}
|