node-switchbot 1.3.0 → 1.4.2-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.
- package/CHANGELOG.md +41 -23
- package/LICENSE +1 -1
- package/README.md +322 -258
- package/lib/parameter-checker.js +271 -213
- package/lib/switchbot-advertising.js +305 -171
- package/lib/switchbot-device-wocolorbulb.js +81 -0
- package/lib/switchbot-device-wocontact.js +4 -7
- package/lib/switchbot-device-wocurtain.js +106 -91
- package/lib/switchbot-device-wohand.js +69 -65
- package/lib/switchbot-device-wohumi.js +69 -65
- package/lib/switchbot-device-woplugmini.js +81 -0
- package/lib/switchbot-device-wopresence.js +4 -7
- package/lib/switchbot-device-wosensorth.js +4 -7
- package/lib/switchbot-device.js +188 -149
- package/lib/switchbot.js +271 -233
- package/package.json +40 -40
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
const SwitchbotDevice = require("./switchbot-device.js");
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* @see https://github.com/OpenWonderLabs/SwitchBotAPI-BLE/blob/latest/devicetypes/plugmini.md
|
|
6
|
+
*/
|
|
7
|
+
class SwitchbotDeviceWoPlugMini extends SwitchbotDevice {
|
|
8
|
+
/**
|
|
9
|
+
* @returns {Promise<boolean>} resolves with a boolean that tells whether the plug in ON(true) or OFF(false)
|
|
10
|
+
*/
|
|
11
|
+
readState() {
|
|
12
|
+
return this._operateBot([0x57, 0x0f, 0x51, 0x01]);
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* @private
|
|
17
|
+
*/
|
|
18
|
+
_setState(reqByteArray) {
|
|
19
|
+
const base = [0x57, 0x0f, 0x50, 0x01];
|
|
20
|
+
return this._operateBot([].concat(base, reqByteArray));
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* @returns {Promise<boolean>} resolves with a boolean that tells whether the plug in ON(true) or OFF(false)
|
|
25
|
+
*/
|
|
26
|
+
turnOn() {
|
|
27
|
+
return this._setState([0x01, 0x01]);
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
/**
|
|
31
|
+
* @returns {Promise<boolean>} resolves with a boolean that tells whether the plug in ON(true) or OFF(false)
|
|
32
|
+
*/
|
|
33
|
+
turnOff() {
|
|
34
|
+
return this._setState([0x01, 0x02]);
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
/**
|
|
38
|
+
* @returns {Promise<boolean>} resolves with a boolean that tells whether the plug in ON(true) or OFF(false)
|
|
39
|
+
*/
|
|
40
|
+
toggle() {
|
|
41
|
+
return this._setState([0x02, 0x03]);
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
/**
|
|
45
|
+
* @private
|
|
46
|
+
*/
|
|
47
|
+
_operateBot(bytes) {
|
|
48
|
+
const req_buf = Buffer.from(bytes);
|
|
49
|
+
return new Promise((resolve, reject) => {
|
|
50
|
+
this._command(req_buf)
|
|
51
|
+
.then((res_bytes) => {
|
|
52
|
+
const res_buf = Buffer.from(res_bytes);
|
|
53
|
+
if (res_buf.length === 2) {
|
|
54
|
+
let code = res_buf.readUInt8(1);
|
|
55
|
+
if (code === 0x00 || code === 0x80) {
|
|
56
|
+
const is_on = code === 0x80;
|
|
57
|
+
resolve(is_on);
|
|
58
|
+
} else {
|
|
59
|
+
reject(
|
|
60
|
+
new Error(
|
|
61
|
+
"The device returned an error: 0x" + res_buf.toString("hex")
|
|
62
|
+
)
|
|
63
|
+
);
|
|
64
|
+
}
|
|
65
|
+
} else {
|
|
66
|
+
reject(
|
|
67
|
+
new Error(
|
|
68
|
+
"Expecting a 2-byte response, got instead: 0x" +
|
|
69
|
+
res_buf.toString("hex")
|
|
70
|
+
)
|
|
71
|
+
);
|
|
72
|
+
}
|
|
73
|
+
})
|
|
74
|
+
.catch((error) => {
|
|
75
|
+
reject(error);
|
|
76
|
+
});
|
|
77
|
+
});
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
module.exports = SwitchbotDeviceWoPlugMini;
|
|
@@ -1,9 +1,6 @@
|
|
|
1
|
-
|
|
2
|
-
const SwitchbotDevice = require(
|
|
1
|
+
"use strict";
|
|
2
|
+
const SwitchbotDevice = require("./switchbot-device.js");
|
|
3
3
|
|
|
4
|
-
class SwitchbotDeviceWoContact extends SwitchbotDevice {
|
|
4
|
+
class SwitchbotDeviceWoContact extends SwitchbotDevice {}
|
|
5
5
|
|
|
6
|
-
|
|
7
|
-
}
|
|
8
|
-
|
|
9
|
-
module.exports = SwitchbotDeviceWoContact;
|
|
6
|
+
module.exports = SwitchbotDeviceWoContact;
|
|
@@ -1,102 +1,117 @@
|
|
|
1
|
-
|
|
2
|
-
const SwitchbotDevice = require(
|
|
1
|
+
"use strict";
|
|
2
|
+
const SwitchbotDevice = require("./switchbot-device.js");
|
|
3
3
|
|
|
4
4
|
class SwitchbotDeviceWoCurtain extends SwitchbotDevice {
|
|
5
|
+
/* ------------------------------------------------------------------
|
|
6
|
+
* open()
|
|
7
|
+
* - Open the curtain
|
|
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._operateCurtain([0x57, 0x0f, 0x45, 0x01, 0x05, 0xff, 0x00]);
|
|
18
|
+
}
|
|
5
19
|
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
/* ------------------------------------------------------------------
|
|
22
|
-
* close()
|
|
23
|
-
* - close the curtain
|
|
24
|
-
*
|
|
25
|
-
* [Arguments]
|
|
26
|
-
* - none
|
|
27
|
-
*
|
|
28
|
-
* [Return value]
|
|
29
|
-
* - Promise object
|
|
30
|
-
* Nothing will be passed to the `resolve()`.
|
|
31
|
-
* ---------------------------------------------------------------- */
|
|
32
|
-
close() {
|
|
33
|
-
return this._operateCurtain([0x57, 0x0f, 0x45, 0x01, 0x05, 0xff, 0x64]);
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
/* ------------------------------------------------------------------
|
|
37
|
-
* pause()
|
|
38
|
-
* - pause the curtain
|
|
39
|
-
*
|
|
40
|
-
* [Arguments]
|
|
41
|
-
* - none
|
|
42
|
-
*
|
|
43
|
-
* [Return value]
|
|
44
|
-
* - Promise object
|
|
45
|
-
* Nothing will be passed to the `resolve()`.
|
|
46
|
-
* ---------------------------------------------------------------- */
|
|
47
|
-
pause() {
|
|
48
|
-
return this._operateCurtain([0x57, 0x0f, 0x45, 0x01, 0x00, 0xff]);
|
|
49
|
-
}
|
|
20
|
+
/* ------------------------------------------------------------------
|
|
21
|
+
* close()
|
|
22
|
+
* - close the curtain
|
|
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._operateCurtain([0x57, 0x0f, 0x45, 0x01, 0x05, 0xff, 0x64]);
|
|
33
|
+
}
|
|
50
34
|
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
35
|
+
/* ------------------------------------------------------------------
|
|
36
|
+
* pause()
|
|
37
|
+
* - pause the curtain
|
|
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._operateCurtain([0x57, 0x0f, 0x45, 0x01, 0x00, 0xff]);
|
|
48
|
+
}
|
|
63
49
|
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
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
|
+
});
|
|
83
71
|
}
|
|
84
|
-
|
|
85
|
-
|
|
72
|
+
if (mode == null) {
|
|
73
|
+
mode = 0xff;
|
|
74
|
+
} else {
|
|
75
|
+
if (typeof mode != "number") {
|
|
86
76
|
return new Promise((resolve, reject) => {
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
if (res_buf.length === 3 && code === 0x01) {
|
|
91
|
-
resolve();
|
|
92
|
-
} else {
|
|
93
|
-
reject(new Error('The device returned an error: 0x' + res_buf.toString('hex')));
|
|
94
|
-
}
|
|
95
|
-
}).catch((error) => {
|
|
96
|
-
reject(error);
|
|
97
|
-
});
|
|
77
|
+
reject(
|
|
78
|
+
new Error("The type of running mode is incorrent: " + typeof mode)
|
|
79
|
+
);
|
|
98
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;
|
|
99
90
|
}
|
|
91
|
+
return this._operateCurtain([0x57, 0x0f, 0x45, 0x01, 0x05, mode, percent]);
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
_operateCurtain(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
|
+
}
|
|
100
115
|
}
|
|
101
116
|
|
|
102
|
-
module.exports = SwitchbotDeviceWoCurtain;
|
|
117
|
+
module.exports = SwitchbotDeviceWoCurtain;
|
|
@@ -1,79 +1,78 @@
|
|
|
1
|
-
|
|
2
|
-
const SwitchbotDevice = require(
|
|
1
|
+
"use strict";
|
|
2
|
+
const SwitchbotDevice = require("./switchbot-device.js");
|
|
3
3
|
|
|
4
4
|
class SwitchbotDeviceWoHand extends SwitchbotDevice {
|
|
5
|
-
|
|
6
5
|
/* ------------------------------------------------------------------
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
6
|
+
* press()
|
|
7
|
+
* - Press
|
|
8
|
+
*
|
|
9
|
+
* [Arguments]
|
|
10
|
+
* - none
|
|
11
|
+
*
|
|
12
|
+
* [Return value]
|
|
13
|
+
* - Promise object
|
|
14
|
+
* Nothing will be passed to the `resolve()`.
|
|
15
|
+
* ---------------------------------------------------------------- */
|
|
17
16
|
press() {
|
|
18
17
|
return this._operateBot([0x57, 0x01, 0x00]);
|
|
19
18
|
}
|
|
20
19
|
|
|
21
20
|
/* ------------------------------------------------------------------
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
21
|
+
* turnOn()
|
|
22
|
+
* - Turn on
|
|
23
|
+
*
|
|
24
|
+
* [Arguments]
|
|
25
|
+
* - none
|
|
26
|
+
*
|
|
27
|
+
* [Return value]
|
|
28
|
+
* - Promise object
|
|
29
|
+
* Nothing will be passed to the `resolve()`.
|
|
30
|
+
* ---------------------------------------------------------------- */
|
|
32
31
|
turnOn() {
|
|
33
32
|
return this._operateBot([0x57, 0x01, 0x01]);
|
|
34
33
|
}
|
|
35
34
|
|
|
36
35
|
/* ------------------------------------------------------------------
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
36
|
+
* turnOff()
|
|
37
|
+
* - Turn off
|
|
38
|
+
*
|
|
39
|
+
* [Arguments]
|
|
40
|
+
* - none
|
|
41
|
+
*
|
|
42
|
+
* [Return value]
|
|
43
|
+
* - Promise object
|
|
44
|
+
* Nothing will be passed to the `resolve()`.
|
|
45
|
+
* ---------------------------------------------------------------- */
|
|
47
46
|
turnOff() {
|
|
48
47
|
return this._operateBot([0x57, 0x01, 0x02]);
|
|
49
48
|
}
|
|
50
49
|
|
|
51
50
|
/* ------------------------------------------------------------------
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
51
|
+
* down()
|
|
52
|
+
* - Down
|
|
53
|
+
*
|
|
54
|
+
* [Arguments]
|
|
55
|
+
* - none
|
|
56
|
+
*
|
|
57
|
+
* [Return value]
|
|
58
|
+
* - Promise object
|
|
59
|
+
* Nothing will be passed to the `resolve()`.
|
|
60
|
+
* ---------------------------------------------------------------- */
|
|
62
61
|
down() {
|
|
63
62
|
return this._operateBot([0x57, 0x01, 0x03]);
|
|
64
63
|
}
|
|
65
64
|
|
|
66
65
|
/* ------------------------------------------------------------------
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
66
|
+
* up()
|
|
67
|
+
* - Up
|
|
68
|
+
*
|
|
69
|
+
* [Arguments]
|
|
70
|
+
* - none
|
|
71
|
+
*
|
|
72
|
+
* [Return value]
|
|
73
|
+
* - Promise object
|
|
74
|
+
* Nothing will be passed to the `resolve()`.
|
|
75
|
+
* ---------------------------------------------------------------- */
|
|
77
76
|
up() {
|
|
78
77
|
return this._operateBot([0x57, 0x01, 0x04]);
|
|
79
78
|
}
|
|
@@ -81,19 +80,24 @@ class SwitchbotDeviceWoHand extends SwitchbotDevice {
|
|
|
81
80
|
_operateBot(bytes) {
|
|
82
81
|
return new Promise((resolve, reject) => {
|
|
83
82
|
let req_buf = Buffer.from(bytes);
|
|
84
|
-
this._command(req_buf)
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
83
|
+
this._command(req_buf)
|
|
84
|
+
.then((res_buf) => {
|
|
85
|
+
let code = res_buf.readUInt8(0);
|
|
86
|
+
if (res_buf.length === 3 && (code === 0x01 || code === 0x05)) {
|
|
87
|
+
resolve();
|
|
88
|
+
} else {
|
|
89
|
+
reject(
|
|
90
|
+
new Error(
|
|
91
|
+
"The device returned an error: 0x" + res_buf.toString("hex")
|
|
92
|
+
)
|
|
93
|
+
);
|
|
94
|
+
}
|
|
95
|
+
})
|
|
96
|
+
.catch((error) => {
|
|
97
|
+
reject(error);
|
|
98
|
+
});
|
|
94
99
|
});
|
|
95
100
|
}
|
|
96
|
-
|
|
97
101
|
}
|
|
98
102
|
|
|
99
|
-
module.exports = SwitchbotDeviceWoHand;
|
|
103
|
+
module.exports = SwitchbotDeviceWoHand;
|
|
@@ -1,79 +1,78 @@
|
|
|
1
|
-
|
|
2
|
-
const SwitchbotDevice = require(
|
|
1
|
+
"use strict";
|
|
2
|
+
const SwitchbotDevice = require("./switchbot-device.js");
|
|
3
3
|
|
|
4
4
|
class SwitchbotDeviceWoHumi extends SwitchbotDevice {
|
|
5
|
-
|
|
6
5
|
/* ------------------------------------------------------------------
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
6
|
+
* press()
|
|
7
|
+
* - Press
|
|
8
|
+
*
|
|
9
|
+
* [Arguments]
|
|
10
|
+
* - none
|
|
11
|
+
*
|
|
12
|
+
* [Return value]
|
|
13
|
+
* - Promise object
|
|
14
|
+
* Nothing will be passed to the `resolve()`.
|
|
15
|
+
* ---------------------------------------------------------------- */
|
|
17
16
|
press() {
|
|
18
17
|
return this._operateBot([0x57, 0x01, 0x00]);
|
|
19
18
|
}
|
|
20
19
|
|
|
21
20
|
/* ------------------------------------------------------------------
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
21
|
+
* turnOn()
|
|
22
|
+
* - Turn on
|
|
23
|
+
*
|
|
24
|
+
* [Arguments]
|
|
25
|
+
* - none
|
|
26
|
+
*
|
|
27
|
+
* [Return value]
|
|
28
|
+
* - Promise object
|
|
29
|
+
* Nothing will be passed to the `resolve()`.
|
|
30
|
+
* ---------------------------------------------------------------- */
|
|
32
31
|
turnOn() {
|
|
33
32
|
return this._operateBot([0x57, 0x01, 0x01]);
|
|
34
33
|
}
|
|
35
34
|
|
|
36
35
|
/* ------------------------------------------------------------------
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
36
|
+
* turnOff()
|
|
37
|
+
* - Turn off
|
|
38
|
+
*
|
|
39
|
+
* [Arguments]
|
|
40
|
+
* - none
|
|
41
|
+
*
|
|
42
|
+
* [Return value]
|
|
43
|
+
* - Promise object
|
|
44
|
+
* Nothing will be passed to the `resolve()`.
|
|
45
|
+
* ---------------------------------------------------------------- */
|
|
47
46
|
turnOff() {
|
|
48
47
|
return this._operateBot([0x57, 0x01, 0x02]);
|
|
49
48
|
}
|
|
50
49
|
|
|
51
50
|
/* ------------------------------------------------------------------
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
51
|
+
* down()
|
|
52
|
+
* - Down
|
|
53
|
+
*
|
|
54
|
+
* [Arguments]
|
|
55
|
+
* - none
|
|
56
|
+
*
|
|
57
|
+
* [Return value]
|
|
58
|
+
* - Promise object
|
|
59
|
+
* Nothing will be passed to the `resolve()`.
|
|
60
|
+
* ---------------------------------------------------------------- */
|
|
62
61
|
down() {
|
|
63
62
|
return this._operateBot([0x57, 0x01, 0x03]);
|
|
64
63
|
}
|
|
65
64
|
|
|
66
65
|
/* ------------------------------------------------------------------
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
66
|
+
* up()
|
|
67
|
+
* - Up
|
|
68
|
+
*
|
|
69
|
+
* [Arguments]
|
|
70
|
+
* - none
|
|
71
|
+
*
|
|
72
|
+
* [Return value]
|
|
73
|
+
* - Promise object
|
|
74
|
+
* Nothing will be passed to the `resolve()`.
|
|
75
|
+
* ---------------------------------------------------------------- */
|
|
77
76
|
up() {
|
|
78
77
|
return this._operateBot([0x57, 0x01, 0x04]);
|
|
79
78
|
}
|
|
@@ -81,19 +80,24 @@ class SwitchbotDeviceWoHumi extends SwitchbotDevice {
|
|
|
81
80
|
_operateBot(bytes) {
|
|
82
81
|
return new Promise((resolve, reject) => {
|
|
83
82
|
let req_buf = Buffer.from(bytes);
|
|
84
|
-
this._command(req_buf)
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
83
|
+
this._command(req_buf)
|
|
84
|
+
.then((res_buf) => {
|
|
85
|
+
let code = res_buf.readUInt8(0);
|
|
86
|
+
if (res_buf.length === 3 && (code === 0x01 || code === 0x05)) {
|
|
87
|
+
resolve();
|
|
88
|
+
} else {
|
|
89
|
+
reject(
|
|
90
|
+
new Error(
|
|
91
|
+
"The device returned an error: 0x" + res_buf.toString("hex")
|
|
92
|
+
)
|
|
93
|
+
);
|
|
94
|
+
}
|
|
95
|
+
})
|
|
96
|
+
.catch((error) => {
|
|
97
|
+
reject(error);
|
|
98
|
+
});
|
|
94
99
|
});
|
|
95
100
|
}
|
|
96
|
-
|
|
97
101
|
}
|
|
98
102
|
|
|
99
|
-
module.exports = SwitchbotDeviceWoHumi;
|
|
103
|
+
module.exports = SwitchbotDeviceWoHumi;
|