node-switchbot 1.10.0 → 2.0.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/.gitattributes +2 -0
- package/.github/dependabot.yml +17 -0
- package/.github/labeler.yml +38 -0
- package/.github/npm-version-script.cjs +81 -0
- package/.github/workflows/beta-release.yml +31 -0
- package/.github/workflows/build.yml +18 -0
- package/.github/workflows/changerelease.yml +13 -0
- package/.github/workflows/dependabot.yml +17 -0
- package/.github/workflows/labeler.yml +16 -0
- package/.github/workflows/release-drafter.yml +14 -0
- package/.github/workflows/release.yml +24 -0
- package/.github/workflows/stale.yml +12 -0
- package/CHANGELOG.md +308 -0
- package/dist/advertising.d.ts +172 -0
- package/dist/advertising.d.ts.map +1 -0
- package/dist/advertising.js +620 -0
- package/dist/advertising.js.map +1 -0
- package/dist/device/woblindtilt.d.ts +9 -0
- package/dist/device/woblindtilt.d.ts.map +1 -0
- package/dist/device/woblindtilt.js +108 -0
- package/dist/device/woblindtilt.js.map +1 -0
- package/dist/device/wobulb.d.ts +39 -0
- package/dist/device/wobulb.d.ts.map +1 -0
- package/dist/device/wobulb.js +156 -0
- package/dist/device/wobulb.js.map +1 -0
- package/dist/device/wocontact.d.ts +4 -0
- package/dist/device/wocontact.d.ts.map +1 -0
- package/dist/device/wocontact.js +8 -0
- package/dist/device/wocontact.js.map +1 -0
- package/dist/device/wocurtain.d.ts +9 -0
- package/dist/device/wocurtain.d.ts.map +1 -0
- package/dist/device/wocurtain.js +104 -0
- package/dist/device/wocurtain.js.map +1 -0
- package/dist/device/wohand.d.ts +10 -0
- package/dist/device/wohand.d.ts.map +1 -0
- package/dist/device/wohand.js +93 -0
- package/dist/device/wohand.js.map +1 -0
- package/dist/device/wohumi.d.ts +10 -0
- package/dist/device/wohumi.d.ts.map +1 -0
- package/dist/device/wohumi.js +93 -0
- package/dist/device/wohumi.js.map +1 -0
- package/dist/device/woiosensorth.d.ts +4 -0
- package/dist/device/woiosensorth.d.ts.map +1 -0
- package/dist/device/woiosensorth.js +4 -0
- package/dist/device/woiosensorth.js.map +1 -0
- package/dist/device/woplugmini.d.ts +31 -0
- package/dist/device/woplugmini.d.ts.map +1 -0
- package/dist/device/woplugmini.js +68 -0
- package/dist/device/woplugmini.js.map +1 -0
- package/dist/device/wopresence.d.ts +4 -0
- package/dist/device/wopresence.d.ts.map +1 -0
- package/dist/device/wopresence.js +4 -0
- package/dist/device/wopresence.js.map +1 -0
- package/dist/device/wosensorth.d.ts +4 -0
- package/dist/device/wosensorth.d.ts.map +1 -0
- package/dist/device/wosensorth.js +4 -0
- package/dist/device/wosensorth.js.map +1 -0
- package/dist/device/wostrip.d.ts +39 -0
- package/dist/device/wostrip.d.ts.map +1 -0
- package/dist/device/wostrip.js +145 -0
- package/dist/device/wostrip.js.map +1 -0
- package/dist/device.d.ts +46 -0
- package/dist/device.d.ts.map +1 -0
- package/dist/device.js +498 -0
- package/dist/device.js.map +1 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +6 -0
- package/dist/index.js.map +1 -0
- package/dist/parameter-checker.d.ts +25 -0
- package/dist/parameter-checker.d.ts.map +1 -0
- package/dist/parameter-checker.js +488 -0
- package/dist/parameter-checker.js.map +1 -0
- package/dist/switchbot.d.ts +29 -0
- package/dist/switchbot.d.ts.map +1 -0
- package/dist/switchbot.js +461 -0
- package/dist/switchbot.js.map +1 -0
- package/package.json +19 -12
- package/lib/parameter-checker.js +0 -524
- package/lib/switchbot-advertising.js +0 -713
- package/lib/switchbot-device-woblindtilt.js +0 -120
- package/lib/switchbot-device-wobulb.js +0 -188
- package/lib/switchbot-device-wocontact.js +0 -6
- package/lib/switchbot-device-wocurtain.js +0 -117
- package/lib/switchbot-device-wohand.js +0 -106
- package/lib/switchbot-device-wohumi.js +0 -106
- package/lib/switchbot-device-woiosensorth.js +0 -6
- package/lib/switchbot-device-woplugmini.js +0 -84
- package/lib/switchbot-device-wopresence.js +0 -6
- package/lib/switchbot-device-wosensorth.js +0 -6
- package/lib/switchbot-device-wostrip.js +0 -182
- package/lib/switchbot-device.js +0 -536
- package/lib/switchbot.js +0 -496
|
@@ -1,120 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
const { Buffer } = require('buffer');
|
|
4
|
-
|
|
5
|
-
let SwitchbotDevice = require("./switchbot-device.js");
|
|
6
|
-
|
|
7
|
-
class SwitchbotDeviceWoBlindTilt extends SwitchbotDevice {
|
|
8
|
-
/* ------------------------------------------------------------------
|
|
9
|
-
* open()
|
|
10
|
-
* - Open the blindtilt
|
|
11
|
-
*
|
|
12
|
-
* [Arguments]
|
|
13
|
-
* - none
|
|
14
|
-
*
|
|
15
|
-
* [Return value]
|
|
16
|
-
* - Promise object
|
|
17
|
-
* Nothing will be passed to the `resolve()`.
|
|
18
|
-
* ---------------------------------------------------------------- */
|
|
19
|
-
open() {
|
|
20
|
-
return this._operateBlindTilt([0x57, 0x0f, 0x45, 0x01, 0x05, 0xff, 0x00]);
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
/* ------------------------------------------------------------------
|
|
24
|
-
* close()
|
|
25
|
-
* - close the blindtilt
|
|
26
|
-
*
|
|
27
|
-
* [Arguments]
|
|
28
|
-
* - none
|
|
29
|
-
*
|
|
30
|
-
* [Return value]
|
|
31
|
-
* - Promise object
|
|
32
|
-
* Nothing will be passed to the `resolve()`.
|
|
33
|
-
* ---------------------------------------------------------------- */
|
|
34
|
-
close() {
|
|
35
|
-
return this._operateBlindTilt([0x57, 0x0f, 0x45, 0x01, 0x05, 0xff, 0x64]);
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
/* ------------------------------------------------------------------
|
|
39
|
-
* pause()
|
|
40
|
-
* - pause the blindtilt
|
|
41
|
-
*
|
|
42
|
-
* [Arguments]
|
|
43
|
-
* - none
|
|
44
|
-
*
|
|
45
|
-
* [Return value]
|
|
46
|
-
* - Promise object
|
|
47
|
-
* Nothing will be passed to the `resolve()`.
|
|
48
|
-
* ---------------------------------------------------------------- */
|
|
49
|
-
pause() {
|
|
50
|
-
return this._operateBlindTilt([0x57, 0x0f, 0x45, 0x01, 0x00, 0xff]);
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
/* ------------------------------------------------------------------
|
|
54
|
-
* runToPos()
|
|
55
|
-
* - run to the targe position
|
|
56
|
-
*
|
|
57
|
-
* [Arguments]
|
|
58
|
-
* - percent | number | Required | the percentage of target position
|
|
59
|
-
*
|
|
60
|
-
* [Return value]
|
|
61
|
-
* - Promise object
|
|
62
|
-
* Nothing will be passed to the `resolve()`.
|
|
63
|
-
* ---------------------------------------------------------------- */
|
|
64
|
-
runToPos(percent, mode) {
|
|
65
|
-
if (typeof percent != "number") {
|
|
66
|
-
return new Promise((resolve, reject) => {
|
|
67
|
-
reject(
|
|
68
|
-
new Error(
|
|
69
|
-
"The type of target position percentage is incorrent: " +
|
|
70
|
-
typeof percent
|
|
71
|
-
)
|
|
72
|
-
);
|
|
73
|
-
});
|
|
74
|
-
}
|
|
75
|
-
if (mode == null) {
|
|
76
|
-
mode = 0xff;
|
|
77
|
-
} else {
|
|
78
|
-
if (typeof mode != "number") {
|
|
79
|
-
return new Promise((resolve, reject) => {
|
|
80
|
-
reject(
|
|
81
|
-
new Error("The type of running mode is incorrent: " + typeof mode)
|
|
82
|
-
);
|
|
83
|
-
});
|
|
84
|
-
}
|
|
85
|
-
if (mode > 1) {
|
|
86
|
-
mode = 0xff;
|
|
87
|
-
}
|
|
88
|
-
}
|
|
89
|
-
if (percent > 100) {
|
|
90
|
-
percent = 100;
|
|
91
|
-
} else if (percent < 0) {
|
|
92
|
-
percent = 0;
|
|
93
|
-
}
|
|
94
|
-
return this._operateBlindTilt([0x57, 0x0f, 0x45, 0x01, 0x05, mode, percent]);
|
|
95
|
-
}
|
|
96
|
-
|
|
97
|
-
_operateBlindTilt(bytes) {
|
|
98
|
-
return new Promise((resolve, reject) => {
|
|
99
|
-
let req_buf = Buffer.from(bytes);
|
|
100
|
-
this._command(req_buf)
|
|
101
|
-
.then((res_buf) => {
|
|
102
|
-
let code = res_buf.readUInt8(0);
|
|
103
|
-
if (res_buf.length === 3 && code === 0x01) {
|
|
104
|
-
resolve();
|
|
105
|
-
} else {
|
|
106
|
-
reject(
|
|
107
|
-
new Error(
|
|
108
|
-
"The device returned an error: 0x" + res_buf.toString("hex")
|
|
109
|
-
)
|
|
110
|
-
);
|
|
111
|
-
}
|
|
112
|
-
})
|
|
113
|
-
.catch((error) => {
|
|
114
|
-
reject(error);
|
|
115
|
-
});
|
|
116
|
-
});
|
|
117
|
-
}
|
|
118
|
-
}
|
|
119
|
-
|
|
120
|
-
module.exports = SwitchbotDeviceWoBlindTilt;
|
|
@@ -1,188 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
const { Buffer } = require('buffer');
|
|
4
|
-
|
|
5
|
-
const SwitchbotDevice = require("./switchbot-device.js");
|
|
6
|
-
|
|
7
|
-
/**
|
|
8
|
-
* @see https://github.com/OpenWonderLabs/SwitchBotAPI-BLE/blob/latest/devicetypes/colorbulb.md
|
|
9
|
-
*/
|
|
10
|
-
class SwitchbotDeviceWoBulb extends SwitchbotDevice {
|
|
11
|
-
/**
|
|
12
|
-
* @returns {Promise<boolean>} resolves with a boolean that tells whether the plug in ON(true) or OFF(false)
|
|
13
|
-
*/
|
|
14
|
-
readState() {
|
|
15
|
-
return this._operateBot([0x57, 0x0f, 0x48, 0x01]);
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
/**
|
|
19
|
-
* @private
|
|
20
|
-
*/
|
|
21
|
-
_setState(reqByteArray) {
|
|
22
|
-
const base = [0x57, 0x0f, 0x47, 0x01];
|
|
23
|
-
return this._operateBot([].concat(base, reqByteArray));
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
/**
|
|
27
|
-
* @returns {Promise<boolean>} resolves with a boolean that tells whether the plug in ON(true) or OFF(false)
|
|
28
|
-
*/
|
|
29
|
-
turnOn() {
|
|
30
|
-
return this._setState([0x01, 0x01]);
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
/**
|
|
34
|
-
* @returns {Promise<boolean>} resolves with a boolean that tells whether the plug in ON(true) or OFF(false)
|
|
35
|
-
*/
|
|
36
|
-
turnOff() {
|
|
37
|
-
return this._setState([0x01, 0x02]);
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
/**
|
|
41
|
-
* @returns {Promise<number>} resolves with brightness percent
|
|
42
|
-
*/
|
|
43
|
-
setBrightness(brightness) {
|
|
44
|
-
if (typeof brightness != "number") {
|
|
45
|
-
return new Promise((resolve, reject) => {
|
|
46
|
-
reject(
|
|
47
|
-
new Error(
|
|
48
|
-
"The type of target brightness percentage is incorrent: " +
|
|
49
|
-
typeof brightness
|
|
50
|
-
)
|
|
51
|
-
);
|
|
52
|
-
});
|
|
53
|
-
}
|
|
54
|
-
if (brightness > 100) {
|
|
55
|
-
brightness = 100;
|
|
56
|
-
} else if (brightness < 0) {
|
|
57
|
-
brightness = 0;
|
|
58
|
-
}
|
|
59
|
-
return this._setState([0x02, 0x14]);
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
/**
|
|
63
|
-
* @returns {Promise<number>} resolves with brightness percent
|
|
64
|
-
*/
|
|
65
|
-
setColorTemperature(color_temperature) {
|
|
66
|
-
if (typeof color_temperature != "number") {
|
|
67
|
-
return new Promise((resolve, reject) => {
|
|
68
|
-
reject(
|
|
69
|
-
new Error(
|
|
70
|
-
"The type of target brightness percentage is incorrent: " +
|
|
71
|
-
typeof brightness
|
|
72
|
-
)
|
|
73
|
-
);
|
|
74
|
-
});
|
|
75
|
-
}
|
|
76
|
-
if (color_temperature > 100) {
|
|
77
|
-
color_temperature = 100;
|
|
78
|
-
} else if (color_temperature < 0) {
|
|
79
|
-
color_temperature = 0;
|
|
80
|
-
}
|
|
81
|
-
return this._setState([0x02, 0x17, color_temperature]);
|
|
82
|
-
}
|
|
83
|
-
|
|
84
|
-
/**
|
|
85
|
-
* @returns {Promise<number>} resolves with brightness percent
|
|
86
|
-
*/
|
|
87
|
-
setRGB(brightness, red, green, blue) {
|
|
88
|
-
if (typeof brightness != "number") {
|
|
89
|
-
return new Promise((resolve, reject) => {
|
|
90
|
-
reject(
|
|
91
|
-
new Error(
|
|
92
|
-
"The type of target brightness percentage is incorrent: " +
|
|
93
|
-
typeof brightness
|
|
94
|
-
)
|
|
95
|
-
);
|
|
96
|
-
});
|
|
97
|
-
}
|
|
98
|
-
if (typeof red != "number") {
|
|
99
|
-
return new Promise((resolve, reject) => {
|
|
100
|
-
reject(
|
|
101
|
-
new Error(
|
|
102
|
-
"The type of target red is incorrent: " +
|
|
103
|
-
typeof red
|
|
104
|
-
)
|
|
105
|
-
);
|
|
106
|
-
});
|
|
107
|
-
}
|
|
108
|
-
if (typeof green != "number") {
|
|
109
|
-
return new Promise((resolve, reject) => {
|
|
110
|
-
reject(
|
|
111
|
-
new Error(
|
|
112
|
-
"The type of target green is incorrent: " +
|
|
113
|
-
typeof green
|
|
114
|
-
)
|
|
115
|
-
);
|
|
116
|
-
});
|
|
117
|
-
}
|
|
118
|
-
if (typeof blue != "number") {
|
|
119
|
-
return new Promise((resolve, reject) => {
|
|
120
|
-
reject(
|
|
121
|
-
new Error(
|
|
122
|
-
"The type of target blue is incorrent: " +
|
|
123
|
-
typeof blue
|
|
124
|
-
)
|
|
125
|
-
);
|
|
126
|
-
});
|
|
127
|
-
}
|
|
128
|
-
if (brightness > 100) {
|
|
129
|
-
brightness = 100;
|
|
130
|
-
} else if (brightness < 0) {
|
|
131
|
-
brightness = 0;
|
|
132
|
-
}
|
|
133
|
-
if (red > 255) {
|
|
134
|
-
red = 255;
|
|
135
|
-
} else if (red < 0) {
|
|
136
|
-
red = 0;
|
|
137
|
-
}
|
|
138
|
-
if (green > 255) {
|
|
139
|
-
green = 255;
|
|
140
|
-
} else if (green < 0) {
|
|
141
|
-
green = 0;
|
|
142
|
-
}
|
|
143
|
-
if (blue > 255) {
|
|
144
|
-
blue = 255;
|
|
145
|
-
} else if (blue < 0) {
|
|
146
|
-
blue = 0;
|
|
147
|
-
}
|
|
148
|
-
return this._setState([0x02, 0x12, brightness, red, green, blue]);
|
|
149
|
-
}
|
|
150
|
-
|
|
151
|
-
/**
|
|
152
|
-
* @private
|
|
153
|
-
*/
|
|
154
|
-
_operateBot(bytes) {
|
|
155
|
-
const req_buf = Buffer.from(bytes);
|
|
156
|
-
return new Promise((resolve, reject) => {
|
|
157
|
-
this._command(req_buf)
|
|
158
|
-
.then((res_bytes) => {
|
|
159
|
-
const res_buf = Buffer.from(res_bytes);
|
|
160
|
-
if (res_buf.length === 2) {
|
|
161
|
-
const code = res_buf.readUInt8(1);
|
|
162
|
-
if (code === 0x00 || code === 0x80) {
|
|
163
|
-
const is_on = code === 0x80;
|
|
164
|
-
resolve(is_on);
|
|
165
|
-
} else {
|
|
166
|
-
reject(
|
|
167
|
-
new Error(
|
|
168
|
-
"The device returned an error: 0x" + res_buf.toString("hex")
|
|
169
|
-
)
|
|
170
|
-
);
|
|
171
|
-
}
|
|
172
|
-
} else {
|
|
173
|
-
reject(
|
|
174
|
-
new Error(
|
|
175
|
-
"Expecting a 2-byte response, got instead: 0x" +
|
|
176
|
-
res_buf.toString("hex")
|
|
177
|
-
)
|
|
178
|
-
);
|
|
179
|
-
}
|
|
180
|
-
})
|
|
181
|
-
.catch((error) => {
|
|
182
|
-
reject(error);
|
|
183
|
-
});
|
|
184
|
-
});
|
|
185
|
-
}
|
|
186
|
-
}
|
|
187
|
-
|
|
188
|
-
module.exports = SwitchbotDeviceWoBulb;
|
|
@@ -1,117 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
const { Buffer } = require('buffer');
|
|
4
|
-
|
|
5
|
-
const SwitchbotDevice = require("./switchbot-device.js");
|
|
6
|
-
|
|
7
|
-
class SwitchbotDeviceWoCurtain extends SwitchbotDevice {
|
|
8
|
-
/* ------------------------------------------------------------------
|
|
9
|
-
* open()
|
|
10
|
-
* - Open the curtain
|
|
11
|
-
*
|
|
12
|
-
* [Arguments]
|
|
13
|
-
* - mode | number | Opetional | runing mode (0x01 = QuietDrift, 0xff = Default)
|
|
14
|
-
*
|
|
15
|
-
* [Return value]
|
|
16
|
-
* - Promise object
|
|
17
|
-
* Nothing will be passed to the `resolve()`.
|
|
18
|
-
* ---------------------------------------------------------------- */
|
|
19
|
-
open(mode) {
|
|
20
|
-
return this.runToPos(0, mode);
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
/* ------------------------------------------------------------------
|
|
24
|
-
* close()
|
|
25
|
-
* - close the curtain
|
|
26
|
-
*
|
|
27
|
-
* [Arguments]
|
|
28
|
-
* - mode | number | Opetional | runing mode (0x01 = QuietDrift, 0xff = Default)
|
|
29
|
-
*
|
|
30
|
-
* [Return value]
|
|
31
|
-
* - Promise object
|
|
32
|
-
* Nothing will be passed to the `resolve()`.
|
|
33
|
-
* ---------------------------------------------------------------- */
|
|
34
|
-
close(mode) {
|
|
35
|
-
return this.runToPos(100, mode);
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
/* ------------------------------------------------------------------
|
|
39
|
-
* pause()
|
|
40
|
-
* - pause the curtain
|
|
41
|
-
*
|
|
42
|
-
* [Arguments]
|
|
43
|
-
* - none
|
|
44
|
-
*
|
|
45
|
-
* [Return value]
|
|
46
|
-
* - Promise object
|
|
47
|
-
* Nothing will be passed to the `resolve()`.
|
|
48
|
-
* ---------------------------------------------------------------- */
|
|
49
|
-
pause() {
|
|
50
|
-
return this._operateCurtain([0x57, 0x0f, 0x45, 0x01, 0x00, 0xff]);
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
/* ------------------------------------------------------------------
|
|
54
|
-
* runToPos()
|
|
55
|
-
* - run to the target position
|
|
56
|
-
*
|
|
57
|
-
* [Arguments]
|
|
58
|
-
* - percent | number | Required | the percentage of target position
|
|
59
|
-
* - mode | number | Opetional | runing mode (0x01 = QuietDrift, 0xff = Default)
|
|
60
|
-
*
|
|
61
|
-
* [Return value]
|
|
62
|
-
* - Promise object
|
|
63
|
-
* Nothing will be passed to the `resolve()`.
|
|
64
|
-
* ---------------------------------------------------------------- */
|
|
65
|
-
runToPos(percent, mode = 0xff) {
|
|
66
|
-
if (typeof percent != "number") {
|
|
67
|
-
return new Promise((resolve, reject) => {
|
|
68
|
-
reject(
|
|
69
|
-
new Error(
|
|
70
|
-
"The type of target position percentage is incorrect: " +
|
|
71
|
-
typeof percent
|
|
72
|
-
)
|
|
73
|
-
);
|
|
74
|
-
});
|
|
75
|
-
}
|
|
76
|
-
if (typeof mode != "number") {
|
|
77
|
-
return new Promise((resolve, reject) => {
|
|
78
|
-
reject(
|
|
79
|
-
new Error("The type of running mode is incorrect: " + typeof mode)
|
|
80
|
-
);
|
|
81
|
-
});
|
|
82
|
-
}
|
|
83
|
-
if (mode > 1) {
|
|
84
|
-
mode = 0xff;
|
|
85
|
-
}
|
|
86
|
-
if (percent > 100) {
|
|
87
|
-
percent = 100;
|
|
88
|
-
} else if (percent < 0) {
|
|
89
|
-
percent = 0;
|
|
90
|
-
}
|
|
91
|
-
return this._operateCurtain([0x57, 0x0f, 0x45, 0x01, 0x05, mode, percent]);
|
|
92
|
-
}
|
|
93
|
-
|
|
94
|
-
_operateCurtain(bytes) {
|
|
95
|
-
return new Promise((resolve, reject) => {
|
|
96
|
-
const req_buf = Buffer.from(bytes);
|
|
97
|
-
this._command(req_buf)
|
|
98
|
-
.then((res_buf) => {
|
|
99
|
-
const 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 = SwitchbotDeviceWoCurtain;
|
|
@@ -1,106 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
const { Buffer } = require('buffer');
|
|
4
|
-
|
|
5
|
-
const SwitchbotDevice = require("./switchbot-device.js");
|
|
6
|
-
|
|
7
|
-
class SwitchbotDeviceWoHand extends SwitchbotDevice {
|
|
8
|
-
/* ------------------------------------------------------------------
|
|
9
|
-
* press()
|
|
10
|
-
* - Press
|
|
11
|
-
*
|
|
12
|
-
* [Arguments]
|
|
13
|
-
* - none
|
|
14
|
-
*
|
|
15
|
-
* [Return value]
|
|
16
|
-
* - Promise object
|
|
17
|
-
* Nothing will be passed to the `resolve()`.
|
|
18
|
-
* ---------------------------------------------------------------- */
|
|
19
|
-
press() {
|
|
20
|
-
return this._operateBot([0x57, 0x01, 0x00]);
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
/* ------------------------------------------------------------------
|
|
24
|
-
* turnOn()
|
|
25
|
-
* - Turn on
|
|
26
|
-
*
|
|
27
|
-
* [Arguments]
|
|
28
|
-
* - none
|
|
29
|
-
*
|
|
30
|
-
* [Return value]
|
|
31
|
-
* - Promise object
|
|
32
|
-
* Nothing will be passed to the `resolve()`.
|
|
33
|
-
* ---------------------------------------------------------------- */
|
|
34
|
-
turnOn() {
|
|
35
|
-
return this._operateBot([0x57, 0x01, 0x01]);
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
/* ------------------------------------------------------------------
|
|
39
|
-
* turnOff()
|
|
40
|
-
* - Turn off
|
|
41
|
-
*
|
|
42
|
-
* [Arguments]
|
|
43
|
-
* - none
|
|
44
|
-
*
|
|
45
|
-
* [Return value]
|
|
46
|
-
* - Promise object
|
|
47
|
-
* Nothing will be passed to the `resolve()`.
|
|
48
|
-
* ---------------------------------------------------------------- */
|
|
49
|
-
turnOff() {
|
|
50
|
-
return this._operateBot([0x57, 0x01, 0x02]);
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
/* ------------------------------------------------------------------
|
|
54
|
-
* down()
|
|
55
|
-
* - Down
|
|
56
|
-
*
|
|
57
|
-
* [Arguments]
|
|
58
|
-
* - none
|
|
59
|
-
*
|
|
60
|
-
* [Return value]
|
|
61
|
-
* - Promise object
|
|
62
|
-
* Nothing will be passed to the `resolve()`.
|
|
63
|
-
* ---------------------------------------------------------------- */
|
|
64
|
-
down() {
|
|
65
|
-
return this._operateBot([0x57, 0x01, 0x03]);
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
/* ------------------------------------------------------------------
|
|
69
|
-
* up()
|
|
70
|
-
* - Up
|
|
71
|
-
*
|
|
72
|
-
* [Arguments]
|
|
73
|
-
* - none
|
|
74
|
-
*
|
|
75
|
-
* [Return value]
|
|
76
|
-
* - Promise object
|
|
77
|
-
* Nothing will be passed to the `resolve()`.
|
|
78
|
-
* ---------------------------------------------------------------- */
|
|
79
|
-
up() {
|
|
80
|
-
return this._operateBot([0x57, 0x01, 0x04]);
|
|
81
|
-
}
|
|
82
|
-
|
|
83
|
-
_operateBot(bytes) {
|
|
84
|
-
return new Promise((resolve, reject) => {
|
|
85
|
-
const req_buf = Buffer.from(bytes);
|
|
86
|
-
this._command(req_buf)
|
|
87
|
-
.then((res_buf) => {
|
|
88
|
-
const code = res_buf.readUInt8(0);
|
|
89
|
-
if (res_buf.length === 3 && (code === 0x01 || code === 0x05)) {
|
|
90
|
-
resolve();
|
|
91
|
-
} else {
|
|
92
|
-
reject(
|
|
93
|
-
new Error(
|
|
94
|
-
"The device returned an error: 0x" + res_buf.toString("hex")
|
|
95
|
-
)
|
|
96
|
-
);
|
|
97
|
-
}
|
|
98
|
-
})
|
|
99
|
-
.catch((error) => {
|
|
100
|
-
reject(error);
|
|
101
|
-
});
|
|
102
|
-
});
|
|
103
|
-
}
|
|
104
|
-
}
|
|
105
|
-
|
|
106
|
-
module.exports = SwitchbotDeviceWoHand;
|
|
@@ -1,106 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
const { Buffer } = require('buffer');
|
|
4
|
-
|
|
5
|
-
const SwitchbotDevice = require("./switchbot-device.js");
|
|
6
|
-
|
|
7
|
-
class SwitchbotDeviceWoHumi extends SwitchbotDevice {
|
|
8
|
-
/* ------------------------------------------------------------------
|
|
9
|
-
* press()
|
|
10
|
-
* - Press
|
|
11
|
-
*
|
|
12
|
-
* [Arguments]
|
|
13
|
-
* - none
|
|
14
|
-
*
|
|
15
|
-
* [Return value]
|
|
16
|
-
* - Promise object
|
|
17
|
-
* Nothing will be passed to the `resolve()`.
|
|
18
|
-
* ---------------------------------------------------------------- */
|
|
19
|
-
press() {
|
|
20
|
-
return this._operateBot([0x57, 0x01, 0x00]);
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
/* ------------------------------------------------------------------
|
|
24
|
-
* turnOn()
|
|
25
|
-
* - Turn on
|
|
26
|
-
*
|
|
27
|
-
* [Arguments]
|
|
28
|
-
* - none
|
|
29
|
-
*
|
|
30
|
-
* [Return value]
|
|
31
|
-
* - Promise object
|
|
32
|
-
* Nothing will be passed to the `resolve()`.
|
|
33
|
-
* ---------------------------------------------------------------- */
|
|
34
|
-
turnOn() {
|
|
35
|
-
return this._operateBot([0x57, 0x01, 0x01]);
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
/* ------------------------------------------------------------------
|
|
39
|
-
* turnOff()
|
|
40
|
-
* - Turn off
|
|
41
|
-
*
|
|
42
|
-
* [Arguments]
|
|
43
|
-
* - none
|
|
44
|
-
*
|
|
45
|
-
* [Return value]
|
|
46
|
-
* - Promise object
|
|
47
|
-
* Nothing will be passed to the `resolve()`.
|
|
48
|
-
* ---------------------------------------------------------------- */
|
|
49
|
-
turnOff() {
|
|
50
|
-
return this._operateBot([0x57, 0x01, 0x02]);
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
/* ------------------------------------------------------------------
|
|
54
|
-
* down()
|
|
55
|
-
* - Down
|
|
56
|
-
*
|
|
57
|
-
* [Arguments]
|
|
58
|
-
* - none
|
|
59
|
-
*
|
|
60
|
-
* [Return value]
|
|
61
|
-
* - Promise object
|
|
62
|
-
* Nothing will be passed to the `resolve()`.
|
|
63
|
-
* ---------------------------------------------------------------- */
|
|
64
|
-
down() {
|
|
65
|
-
return this._operateBot([0x57, 0x01, 0x03]);
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
/* ------------------------------------------------------------------
|
|
69
|
-
* up()
|
|
70
|
-
* - Up
|
|
71
|
-
*
|
|
72
|
-
* [Arguments]
|
|
73
|
-
* - none
|
|
74
|
-
*
|
|
75
|
-
* [Return value]
|
|
76
|
-
* - Promise object
|
|
77
|
-
* Nothing will be passed to the `resolve()`.
|
|
78
|
-
* ---------------------------------------------------------------- */
|
|
79
|
-
up() {
|
|
80
|
-
return this._operateBot([0x57, 0x01, 0x04]);
|
|
81
|
-
}
|
|
82
|
-
|
|
83
|
-
_operateBot(bytes) {
|
|
84
|
-
return new Promise((resolve, reject) => {
|
|
85
|
-
const req_buf = Buffer.from(bytes);
|
|
86
|
-
this._command(req_buf)
|
|
87
|
-
.then((res_buf) => {
|
|
88
|
-
const code = res_buf.readUInt8(0);
|
|
89
|
-
if (res_buf.length === 3 && (code === 0x01 || code === 0x05)) {
|
|
90
|
-
resolve();
|
|
91
|
-
} else {
|
|
92
|
-
reject(
|
|
93
|
-
new Error(
|
|
94
|
-
"The device returned an error: 0x" + res_buf.toString("hex")
|
|
95
|
-
)
|
|
96
|
-
);
|
|
97
|
-
}
|
|
98
|
-
})
|
|
99
|
-
.catch((error) => {
|
|
100
|
-
reject(error);
|
|
101
|
-
});
|
|
102
|
-
});
|
|
103
|
-
}
|
|
104
|
-
}
|
|
105
|
-
|
|
106
|
-
module.exports = SwitchbotDeviceWoHumi;
|