node-switchbot 1.1.3-beta.0 → 1.1.3-beta.4
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/parameter-checker.js +317 -319
- package/lib/switchbot-advertising.js +190 -192
- package/lib/switchbot-device-wocontact.js +2 -3
- package/lib/switchbot-device-wocurtain.js +51 -52
- package/lib/switchbot-device-wohand.js +37 -38
- package/lib/switchbot-device-wohumi.js +41 -42
- package/lib/switchbot-device-wopresence.js +2 -3
- package/lib/switchbot-device-wosensorth.js +2 -3
- package/lib/switchbot-device.js +437 -438
- package/lib/switchbot.js +237 -238
- package/package.json +10 -3
|
@@ -1,9 +1,8 @@
|
|
|
1
|
-
|
|
2
|
-
const SwitchbotDevice = require('./switchbot-device.js');
|
|
1
|
+
import SwitchbotDevice from "./switchbot-device.js";
|
|
3
2
|
|
|
4
3
|
class SwitchbotDeviceWoHand extends SwitchbotDevice {
|
|
5
4
|
|
|
6
|
-
|
|
5
|
+
/* ------------------------------------------------------------------
|
|
7
6
|
* press()
|
|
8
7
|
* - Press
|
|
9
8
|
*
|
|
@@ -14,11 +13,11 @@ class SwitchbotDeviceWoHand extends SwitchbotDevice {
|
|
|
14
13
|
* - Promise object
|
|
15
14
|
* Nothing will be passed to the `resolve()`.
|
|
16
15
|
* ---------------------------------------------------------------- */
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
16
|
+
press() {
|
|
17
|
+
return this._operateBot([0x57, 0x01, 0x00]);
|
|
18
|
+
}
|
|
20
19
|
|
|
21
|
-
|
|
20
|
+
/* ------------------------------------------------------------------
|
|
22
21
|
* turnOn()
|
|
23
22
|
* - Turn on
|
|
24
23
|
*
|
|
@@ -29,11 +28,11 @@ class SwitchbotDeviceWoHand extends SwitchbotDevice {
|
|
|
29
28
|
* - Promise object
|
|
30
29
|
* Nothing will be passed to the `resolve()`.
|
|
31
30
|
* ---------------------------------------------------------------- */
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
31
|
+
turnOn() {
|
|
32
|
+
return this._operateBot([0x57, 0x01, 0x01]);
|
|
33
|
+
}
|
|
35
34
|
|
|
36
|
-
|
|
35
|
+
/* ------------------------------------------------------------------
|
|
37
36
|
* turnOff()
|
|
38
37
|
* - Turn off
|
|
39
38
|
*
|
|
@@ -44,11 +43,11 @@ class SwitchbotDeviceWoHand extends SwitchbotDevice {
|
|
|
44
43
|
* - Promise object
|
|
45
44
|
* Nothing will be passed to the `resolve()`.
|
|
46
45
|
* ---------------------------------------------------------------- */
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
46
|
+
turnOff() {
|
|
47
|
+
return this._operateBot([0x57, 0x01, 0x02]);
|
|
48
|
+
}
|
|
50
49
|
|
|
51
|
-
|
|
50
|
+
/* ------------------------------------------------------------------
|
|
52
51
|
* down()
|
|
53
52
|
* - Down
|
|
54
53
|
*
|
|
@@ -59,11 +58,11 @@ class SwitchbotDeviceWoHand extends SwitchbotDevice {
|
|
|
59
58
|
* - Promise object
|
|
60
59
|
* Nothing will be passed to the `resolve()`.
|
|
61
60
|
* ---------------------------------------------------------------- */
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
61
|
+
down() {
|
|
62
|
+
return this._operateBot([0x57, 0x01, 0x03]);
|
|
63
|
+
}
|
|
65
64
|
|
|
66
|
-
|
|
65
|
+
/* ------------------------------------------------------------------
|
|
67
66
|
* up()
|
|
68
67
|
* - Up
|
|
69
68
|
*
|
|
@@ -74,26 +73,26 @@ class SwitchbotDeviceWoHand extends SwitchbotDevice {
|
|
|
74
73
|
* - Promise object
|
|
75
74
|
* Nothing will be passed to the `resolve()`.
|
|
76
75
|
* ---------------------------------------------------------------- */
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
76
|
+
up() {
|
|
77
|
+
return this._operateBot([0x57, 0x01, 0x04]);
|
|
78
|
+
}
|
|
80
79
|
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
80
|
+
_operateBot(bytes) {
|
|
81
|
+
return new Promise((resolve, reject) => {
|
|
82
|
+
let req_buf = Buffer.from(bytes);
|
|
83
|
+
this._command(req_buf).then((res_buf) => {
|
|
84
|
+
let code = res_buf.readUInt8(0);
|
|
85
|
+
if (res_buf.length === 3 && (code === 0x01 || code === 0x05)) {
|
|
86
|
+
resolve();
|
|
87
|
+
} else {
|
|
88
|
+
reject(new Error("The device returned an error: 0x" + res_buf.toString("hex")));
|
|
89
|
+
}
|
|
90
|
+
}).catch((error) => {
|
|
91
|
+
reject(error);
|
|
92
|
+
});
|
|
93
|
+
});
|
|
94
|
+
}
|
|
96
95
|
|
|
97
96
|
}
|
|
98
97
|
|
|
99
|
-
|
|
98
|
+
export default SwitchbotDeviceWoHand;
|
|
@@ -1,9 +1,8 @@
|
|
|
1
|
-
|
|
2
|
-
const SwitchbotDevice = require('./switchbot-device.js');
|
|
1
|
+
import SwitchbotDevice from "./switchbot-device.js";
|
|
3
2
|
|
|
4
3
|
class SwitchbotDeviceWoHumi extends SwitchbotDevice {
|
|
5
4
|
|
|
6
|
-
|
|
5
|
+
/* ------------------------------------------------------------------
|
|
7
6
|
* Auto()
|
|
8
7
|
* - Set Mode to Auto
|
|
9
8
|
*
|
|
@@ -14,11 +13,11 @@ class SwitchbotDeviceWoHumi extends SwitchbotDevice {
|
|
|
14
13
|
* - Promise object
|
|
15
14
|
* Nothing will be passed to the `resolve()`.
|
|
16
15
|
* ---------------------------------------------------------------- */
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
16
|
+
Auto() {
|
|
17
|
+
return this._operateHumi([0x57, 0x01, 0x80]);
|
|
18
|
+
}
|
|
20
19
|
|
|
21
|
-
|
|
20
|
+
/* ------------------------------------------------------------------
|
|
22
21
|
* First()
|
|
23
22
|
* - Set Mode to First
|
|
24
23
|
*
|
|
@@ -29,11 +28,11 @@ class SwitchbotDeviceWoHumi extends SwitchbotDevice {
|
|
|
29
28
|
* - Promise object
|
|
30
29
|
* Nothing will be passed to the `resolve()`.
|
|
31
30
|
* ---------------------------------------------------------------- */
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
31
|
+
First() {
|
|
32
|
+
return this._operateHumi([0x57, 0x01, 0x65]);
|
|
33
|
+
}
|
|
35
34
|
|
|
36
|
-
|
|
35
|
+
/* ------------------------------------------------------------------
|
|
37
36
|
* Second()
|
|
38
37
|
* - Set Mode to Second
|
|
39
38
|
*
|
|
@@ -44,11 +43,11 @@ class SwitchbotDeviceWoHumi extends SwitchbotDevice {
|
|
|
44
43
|
* - Promise object
|
|
45
44
|
* Nothing will be passed to the `resolve()`.
|
|
46
45
|
* ---------------------------------------------------------------- */
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
46
|
+
Second() {
|
|
47
|
+
return this._operateHumi([0x57, 0x01, 0x66]);
|
|
48
|
+
}
|
|
50
49
|
|
|
51
|
-
|
|
50
|
+
/* ------------------------------------------------------------------
|
|
52
51
|
* Third()
|
|
53
52
|
* - Set Mode to Third
|
|
54
53
|
*
|
|
@@ -59,11 +58,11 @@ class SwitchbotDeviceWoHumi extends SwitchbotDevice {
|
|
|
59
58
|
* - Promise object
|
|
60
59
|
* Nothing will be passed to the `resolve()`.
|
|
61
60
|
* ---------------------------------------------------------------- */
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
61
|
+
Third() {
|
|
62
|
+
return this._operateHumi([0x57, 0x01, 0x67]);
|
|
63
|
+
}
|
|
65
64
|
|
|
66
|
-
|
|
65
|
+
/* ------------------------------------------------------------------
|
|
67
66
|
* up()
|
|
68
67
|
* - Up
|
|
69
68
|
*
|
|
@@ -74,11 +73,11 @@ class SwitchbotDeviceWoHumi extends SwitchbotDevice {
|
|
|
74
73
|
* - Promise object
|
|
75
74
|
* Nothing will be passed to the `resolve()`.
|
|
76
75
|
* ---------------------------------------------------------------- */
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
76
|
+
percentage() {
|
|
77
|
+
return this._operateHumi([0x57, 0x01, 0x01]);
|
|
78
|
+
}
|
|
80
79
|
|
|
81
|
-
|
|
80
|
+
/* ------------------------------------------------------------------
|
|
82
81
|
* turnOff()
|
|
83
82
|
* - Turn off
|
|
84
83
|
*
|
|
@@ -89,26 +88,26 @@ class SwitchbotDeviceWoHumi extends SwitchbotDevice {
|
|
|
89
88
|
* - Promise object
|
|
90
89
|
* Nothing will be passed to the `resolve()`.
|
|
91
90
|
* ---------------------------------------------------------------- */
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
91
|
+
turnOff() {
|
|
92
|
+
return this._operateHumi([0x57, 0x01, 0x02]);
|
|
93
|
+
}
|
|
95
94
|
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
95
|
+
_operateHumi(bytes) {
|
|
96
|
+
return new Promise((resolve, reject) => {
|
|
97
|
+
let req_buf = Buffer.from(bytes);
|
|
98
|
+
this._command(req_buf).then((res_buf) => {
|
|
99
|
+
let code = res_buf.readUInt8(0);
|
|
100
|
+
if (res_buf.length === 3 && (code === 0x01 || code === 0x05)) {
|
|
101
|
+
resolve();
|
|
102
|
+
} else {
|
|
103
|
+
reject(new Error("The device returned an error: 0x" + res_buf.toString("hex")));
|
|
104
|
+
}
|
|
105
|
+
}).catch((error) => {
|
|
106
|
+
reject(error);
|
|
107
|
+
});
|
|
108
|
+
});
|
|
109
|
+
}
|
|
111
110
|
|
|
112
111
|
}
|
|
113
112
|
|
|
114
|
-
|
|
113
|
+
export default SwitchbotDeviceWoHumi;
|
|
@@ -1,9 +1,8 @@
|
|
|
1
|
-
|
|
2
|
-
const SwitchbotDevice = require('./switchbot-device.js');
|
|
1
|
+
import SwitchbotDevice from "./switchbot-device.js";
|
|
3
2
|
|
|
4
3
|
class SwitchbotDeviceWoPresence extends SwitchbotDevice {
|
|
5
4
|
|
|
6
5
|
|
|
7
6
|
}
|
|
8
7
|
|
|
9
|
-
|
|
8
|
+
export default SwitchbotDeviceWoPresence;
|
|
@@ -1,9 +1,8 @@
|
|
|
1
|
-
|
|
2
|
-
const SwitchbotDevice = require('./switchbot-device.js');
|
|
1
|
+
import SwitchbotDevice from "./switchbot-device.js";
|
|
3
2
|
|
|
4
3
|
class SwitchbotDeviceWoSensorTH extends SwitchbotDevice {
|
|
5
4
|
|
|
6
5
|
|
|
7
6
|
}
|
|
8
7
|
|
|
9
|
-
|
|
8
|
+
export default SwitchbotDeviceWoSensorTH;
|