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.
Files changed (93) hide show
  1. package/.gitattributes +2 -0
  2. package/.github/dependabot.yml +17 -0
  3. package/.github/labeler.yml +38 -0
  4. package/.github/npm-version-script.cjs +81 -0
  5. package/.github/workflows/beta-release.yml +31 -0
  6. package/.github/workflows/build.yml +18 -0
  7. package/.github/workflows/changerelease.yml +13 -0
  8. package/.github/workflows/dependabot.yml +17 -0
  9. package/.github/workflows/labeler.yml +16 -0
  10. package/.github/workflows/release-drafter.yml +14 -0
  11. package/.github/workflows/release.yml +24 -0
  12. package/.github/workflows/stale.yml +12 -0
  13. package/CHANGELOG.md +308 -0
  14. package/dist/advertising.d.ts +172 -0
  15. package/dist/advertising.d.ts.map +1 -0
  16. package/dist/advertising.js +620 -0
  17. package/dist/advertising.js.map +1 -0
  18. package/dist/device/woblindtilt.d.ts +9 -0
  19. package/dist/device/woblindtilt.d.ts.map +1 -0
  20. package/dist/device/woblindtilt.js +108 -0
  21. package/dist/device/woblindtilt.js.map +1 -0
  22. package/dist/device/wobulb.d.ts +39 -0
  23. package/dist/device/wobulb.d.ts.map +1 -0
  24. package/dist/device/wobulb.js +156 -0
  25. package/dist/device/wobulb.js.map +1 -0
  26. package/dist/device/wocontact.d.ts +4 -0
  27. package/dist/device/wocontact.d.ts.map +1 -0
  28. package/dist/device/wocontact.js +8 -0
  29. package/dist/device/wocontact.js.map +1 -0
  30. package/dist/device/wocurtain.d.ts +9 -0
  31. package/dist/device/wocurtain.d.ts.map +1 -0
  32. package/dist/device/wocurtain.js +104 -0
  33. package/dist/device/wocurtain.js.map +1 -0
  34. package/dist/device/wohand.d.ts +10 -0
  35. package/dist/device/wohand.d.ts.map +1 -0
  36. package/dist/device/wohand.js +93 -0
  37. package/dist/device/wohand.js.map +1 -0
  38. package/dist/device/wohumi.d.ts +10 -0
  39. package/dist/device/wohumi.d.ts.map +1 -0
  40. package/dist/device/wohumi.js +93 -0
  41. package/dist/device/wohumi.js.map +1 -0
  42. package/dist/device/woiosensorth.d.ts +4 -0
  43. package/dist/device/woiosensorth.d.ts.map +1 -0
  44. package/dist/device/woiosensorth.js +4 -0
  45. package/dist/device/woiosensorth.js.map +1 -0
  46. package/dist/device/woplugmini.d.ts +31 -0
  47. package/dist/device/woplugmini.d.ts.map +1 -0
  48. package/dist/device/woplugmini.js +68 -0
  49. package/dist/device/woplugmini.js.map +1 -0
  50. package/dist/device/wopresence.d.ts +4 -0
  51. package/dist/device/wopresence.d.ts.map +1 -0
  52. package/dist/device/wopresence.js +4 -0
  53. package/dist/device/wopresence.js.map +1 -0
  54. package/dist/device/wosensorth.d.ts +4 -0
  55. package/dist/device/wosensorth.d.ts.map +1 -0
  56. package/dist/device/wosensorth.js +4 -0
  57. package/dist/device/wosensorth.js.map +1 -0
  58. package/dist/device/wostrip.d.ts +39 -0
  59. package/dist/device/wostrip.d.ts.map +1 -0
  60. package/dist/device/wostrip.js +145 -0
  61. package/dist/device/wostrip.js.map +1 -0
  62. package/dist/device.d.ts +46 -0
  63. package/dist/device.d.ts.map +1 -0
  64. package/dist/device.js +498 -0
  65. package/dist/device.js.map +1 -0
  66. package/dist/index.d.ts +2 -0
  67. package/dist/index.d.ts.map +1 -0
  68. package/dist/index.js +6 -0
  69. package/dist/index.js.map +1 -0
  70. package/dist/parameter-checker.d.ts +25 -0
  71. package/dist/parameter-checker.d.ts.map +1 -0
  72. package/dist/parameter-checker.js +488 -0
  73. package/dist/parameter-checker.js.map +1 -0
  74. package/dist/switchbot.d.ts +29 -0
  75. package/dist/switchbot.d.ts.map +1 -0
  76. package/dist/switchbot.js +461 -0
  77. package/dist/switchbot.js.map +1 -0
  78. package/package.json +19 -12
  79. package/lib/parameter-checker.js +0 -524
  80. package/lib/switchbot-advertising.js +0 -713
  81. package/lib/switchbot-device-woblindtilt.js +0 -120
  82. package/lib/switchbot-device-wobulb.js +0 -188
  83. package/lib/switchbot-device-wocontact.js +0 -6
  84. package/lib/switchbot-device-wocurtain.js +0 -117
  85. package/lib/switchbot-device-wohand.js +0 -106
  86. package/lib/switchbot-device-wohumi.js +0 -106
  87. package/lib/switchbot-device-woiosensorth.js +0 -6
  88. package/lib/switchbot-device-woplugmini.js +0 -84
  89. package/lib/switchbot-device-wopresence.js +0 -6
  90. package/lib/switchbot-device-wosensorth.js +0 -6
  91. package/lib/switchbot-device-wostrip.js +0 -182
  92. package/lib/switchbot-device.js +0 -536
  93. 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,6 +0,0 @@
1
- "use strict";
2
- const SwitchbotDevice = require("./switchbot-device.js");
3
-
4
- class SwitchbotDeviceWoPresence extends SwitchbotDevice {}
5
-
6
- module.exports = SwitchbotDeviceWoPresence;
@@ -1,6 +0,0 @@
1
- "use strict";
2
- const SwitchbotDevice = require("./switchbot-device.js");
3
-
4
- class SwitchbotDeviceWoSensorTH extends SwitchbotDevice {}
5
-
6
- module.exports = SwitchbotDeviceWoSensorTH;
@@ -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;