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,84 +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/plugmini.md
|
|
9
|
-
*/
|
|
10
|
-
class SwitchbotDeviceWoPlugMini 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, 0x51, 0x01]);
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
/**
|
|
19
|
-
* @private
|
|
20
|
-
*/
|
|
21
|
-
_setState(reqByteArray) {
|
|
22
|
-
const base = [0x57, 0x0f, 0x50, 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, 0x80]);
|
|
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, 0x00]);
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
/**
|
|
41
|
-
* @returns {Promise<boolean>} resolves with a boolean that tells whether the plug in ON(true) or OFF(false)
|
|
42
|
-
*/
|
|
43
|
-
toggle() {
|
|
44
|
-
return this._setState([0x02, 0x80]);
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
/**
|
|
48
|
-
* @private
|
|
49
|
-
*/
|
|
50
|
-
_operateBot(bytes) {
|
|
51
|
-
const req_buf = Buffer.from(bytes);
|
|
52
|
-
return new Promise((resolve, reject) => {
|
|
53
|
-
this._command(req_buf)
|
|
54
|
-
.then((res_bytes) => {
|
|
55
|
-
const res_buf = Buffer.from(res_bytes);
|
|
56
|
-
if (res_buf.length === 2) {
|
|
57
|
-
const code = res_buf.readUInt8(1);
|
|
58
|
-
if (code === 0x00 || code === 0x80) {
|
|
59
|
-
const is_on = code === 0x80;
|
|
60
|
-
resolve(is_on);
|
|
61
|
-
} else {
|
|
62
|
-
reject(
|
|
63
|
-
new Error(
|
|
64
|
-
"The device returned an error: 0x" + res_buf.toString("hex")
|
|
65
|
-
)
|
|
66
|
-
);
|
|
67
|
-
}
|
|
68
|
-
} else {
|
|
69
|
-
reject(
|
|
70
|
-
new Error(
|
|
71
|
-
"Expecting a 2-byte response, got instead: 0x" +
|
|
72
|
-
res_buf.toString("hex")
|
|
73
|
-
)
|
|
74
|
-
);
|
|
75
|
-
}
|
|
76
|
-
})
|
|
77
|
-
.catch((error) => {
|
|
78
|
-
reject(error);
|
|
79
|
-
});
|
|
80
|
-
});
|
|
81
|
-
}
|
|
82
|
-
}
|
|
83
|
-
|
|
84
|
-
module.exports = SwitchbotDeviceWoPlugMini;
|
|
@@ -1,182 +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 SwitchbotDeviceWoStrip 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, 0x4A, 0x01]);
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
/**
|
|
19
|
-
* @private
|
|
20
|
-
*/
|
|
21
|
-
_setState(reqByteArray) {
|
|
22
|
-
const base = [0x57, 0x0f, 0x49, 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 color temperature
|
|
64
|
-
*/
|
|
65
|
-
setColorTemperature(color_temperature) {
|
|
66
|
-
if (color_temperature) {
|
|
67
|
-
return new Promise((resolve, reject) => {
|
|
68
|
-
reject(
|
|
69
|
-
new Error(
|
|
70
|
-
"Strip Light Doesn't Support Color temperature: " +
|
|
71
|
-
typeof color_temperature
|
|
72
|
-
)
|
|
73
|
-
);
|
|
74
|
-
});
|
|
75
|
-
}
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
/**
|
|
79
|
-
* @returns {Promise<number>} resolves with brightness + rgb
|
|
80
|
-
*/
|
|
81
|
-
setRGB(brightness, red, green, blue) {
|
|
82
|
-
if (typeof brightness != "number") {
|
|
83
|
-
return new Promise((resolve, reject) => {
|
|
84
|
-
reject(
|
|
85
|
-
new Error(
|
|
86
|
-
"The type of target brightness percentage is incorrent: " +
|
|
87
|
-
typeof brightness
|
|
88
|
-
)
|
|
89
|
-
);
|
|
90
|
-
});
|
|
91
|
-
}
|
|
92
|
-
if (typeof red != "number") {
|
|
93
|
-
return new Promise((resolve, reject) => {
|
|
94
|
-
reject(
|
|
95
|
-
new Error(
|
|
96
|
-
"The type of target red is incorrent: " +
|
|
97
|
-
typeof red
|
|
98
|
-
)
|
|
99
|
-
);
|
|
100
|
-
});
|
|
101
|
-
}
|
|
102
|
-
if (typeof green != "number") {
|
|
103
|
-
return new Promise((resolve, reject) => {
|
|
104
|
-
reject(
|
|
105
|
-
new Error(
|
|
106
|
-
"The type of target green is incorrent: " +
|
|
107
|
-
typeof green
|
|
108
|
-
)
|
|
109
|
-
);
|
|
110
|
-
});
|
|
111
|
-
}
|
|
112
|
-
if (typeof blue != "number") {
|
|
113
|
-
return new Promise((resolve, reject) => {
|
|
114
|
-
reject(
|
|
115
|
-
new Error(
|
|
116
|
-
"The type of target blue is incorrent: " +
|
|
117
|
-
typeof blue
|
|
118
|
-
)
|
|
119
|
-
);
|
|
120
|
-
});
|
|
121
|
-
}
|
|
122
|
-
if (brightness > 100) {
|
|
123
|
-
brightness = 100;
|
|
124
|
-
} else if (brightness < 0) {
|
|
125
|
-
brightness = 0;
|
|
126
|
-
}
|
|
127
|
-
if (red > 255) {
|
|
128
|
-
red = 255;
|
|
129
|
-
} else if (red < 0) {
|
|
130
|
-
red = 0;
|
|
131
|
-
}
|
|
132
|
-
if (green > 255) {
|
|
133
|
-
green = 255;
|
|
134
|
-
} else if (green < 0) {
|
|
135
|
-
green = 0;
|
|
136
|
-
}
|
|
137
|
-
if (blue > 255) {
|
|
138
|
-
blue = 255;
|
|
139
|
-
} else if (blue < 0) {
|
|
140
|
-
blue = 0;
|
|
141
|
-
}
|
|
142
|
-
return this._setState([0x02, 0x12, brightness, red, green, blue]);
|
|
143
|
-
}
|
|
144
|
-
|
|
145
|
-
/**
|
|
146
|
-
* @private
|
|
147
|
-
*/
|
|
148
|
-
_operateBot(bytes) {
|
|
149
|
-
const req_buf = Buffer.from(bytes);
|
|
150
|
-
return new Promise((resolve, reject) => {
|
|
151
|
-
this._command(req_buf)
|
|
152
|
-
.then((res_bytes) => {
|
|
153
|
-
const res_buf = Buffer.from(res_bytes);
|
|
154
|
-
if (res_buf.length === 2) {
|
|
155
|
-
const code = res_buf.readUInt8(1);
|
|
156
|
-
if (code === 0x00 || code === 0x80) {
|
|
157
|
-
const is_on = code === 0x80;
|
|
158
|
-
resolve(is_on);
|
|
159
|
-
} else {
|
|
160
|
-
reject(
|
|
161
|
-
new Error(
|
|
162
|
-
"The device returned an error: 0x" + res_buf.toString("hex")
|
|
163
|
-
)
|
|
164
|
-
);
|
|
165
|
-
}
|
|
166
|
-
} else {
|
|
167
|
-
reject(
|
|
168
|
-
new Error(
|
|
169
|
-
"Expecting a 2-byte response, got instead: 0x" +
|
|
170
|
-
res_buf.toString("hex")
|
|
171
|
-
)
|
|
172
|
-
);
|
|
173
|
-
}
|
|
174
|
-
})
|
|
175
|
-
.catch((error) => {
|
|
176
|
-
reject(error);
|
|
177
|
-
});
|
|
178
|
-
});
|
|
179
|
-
}
|
|
180
|
-
}
|
|
181
|
-
|
|
182
|
-
module.exports = SwitchbotDeviceWoStrip;
|