node-switchbot 1.9.2-beta.2 → 2.0.0-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.
Files changed (94) 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/errros.log +13 -0
  79. package/package.json +19 -11
  80. package/lib/parameter-checker.js +0 -524
  81. package/lib/switchbot-advertising.js +0 -713
  82. package/lib/switchbot-device-woblindtilt.js +0 -120
  83. package/lib/switchbot-device-wobulb.js +0 -188
  84. package/lib/switchbot-device-wocontact.js +0 -6
  85. package/lib/switchbot-device-wocurtain.js +0 -117
  86. package/lib/switchbot-device-wohand.js +0 -106
  87. package/lib/switchbot-device-wohumi.js +0 -106
  88. package/lib/switchbot-device-woiosensorth.js +0 -6
  89. package/lib/switchbot-device-woplugmini.js +0 -84
  90. package/lib/switchbot-device-wopresence.js +0 -6
  91. package/lib/switchbot-device-wosensorth.js +0 -6
  92. package/lib/switchbot-device-wostrip.js +0 -182
  93. package/lib/switchbot-device.js +0 -536
  94. package/lib/switchbot.js +0 -496
@@ -0,0 +1,461 @@
1
+ import { ParameterChecker } from './parameter-checker.js';
2
+ import { Advertising } from './advertising.js';
3
+ import { SwitchbotDevice } from './device.js';
4
+ import { WoHand } from './device/wohand.js';
5
+ import { WoCurtain } from './device/wocurtain.js';
6
+ import { WoBlindTilt } from './device/woblindtilt.js';
7
+ import { WoPresence } from './device/wopresence.js';
8
+ import { WoContact } from './device/wocontact.js';
9
+ import { WoSensorTH } from './device/wosensorth.js';
10
+ import { WoIOSensorTH } from './device/woiosensorth.js';
11
+ import { WoHumi } from './device/wohumi.js';
12
+ import { WoPlugMini } from './device/woplugmini.js';
13
+ import { WoBulb } from './device/wobulb.js';
14
+ import { WoStrip } from './device/wostrip.js';
15
+ export class SwitchBot {
16
+ noble;
17
+ ondiscover;
18
+ onadvertisement;
19
+ onlog;
20
+ scanning;
21
+ DEFAULT_DISCOVERY_DURATION;
22
+ PRIMARY_SERVICE_UUID_LIST;
23
+ static onlog;
24
+ static noble;
25
+ /* ------------------------------------------------------------------
26
+ * Constructor
27
+ *
28
+ * [Arguments]
29
+ * - params | Object | Optional |
30
+ * - noble | Noble | Optional | The Noble object created by the noble module.
31
+ * | | | This parameter is optional.
32
+ * | | | If you don't specify this parameter, this
33
+ * | | | module automatically creates it.
34
+ * ---------------------------------------------------------------- */
35
+ constructor(params = {}) {
36
+ // Check parameters
37
+ let noble = null;
38
+ if (params && params.noble) {
39
+ noble = params.noble;
40
+ }
41
+ else {
42
+ noble = require('@abandonware/noble');
43
+ }
44
+ // Public properties
45
+ this.noble = noble;
46
+ this.ondiscover = null;
47
+ this.onadvertisement = null;
48
+ this.onlog = null;
49
+ // Private properties
50
+ this.scanning = false;
51
+ this.DEFAULT_DISCOVERY_DURATION = 5000;
52
+ this.PRIMARY_SERVICE_UUID_LIST = [];
53
+ }
54
+ /* ------------------------------------------------------------------
55
+ * discover([params])
56
+ * - Discover switchbot devices
57
+ *
58
+ * [Arguments]
59
+ * - params | Object | Optional |
60
+ * - duration | Integer | Optional | Duration for discovery process (msec).
61
+ * | | | The value must be in the range of 1 to 60000.
62
+ * | | | The default value is 5000 (msec).
63
+ * - model | String | Optional | "H", "T", "e", "s", "d", "c", "{", "u", "g", "o", "i", or "r".
64
+ * | | | If "H" is specified, this method will discover only Bots.
65
+ * | | | If "T" is specified, this method will discover only Meters.
66
+ * | | | If "e" is specified, this method will discover only Humidifiers.
67
+ * | | | If "s" is specified, this method will discover only Motion Sensors.
68
+ * | | | If "d" is specified, this method will discover only Contact Sensors.
69
+ * | | | If "c" is specified, this method will discover only Curtains.
70
+ * | | | If "{" is specified, this method will discover only Curtain 3.
71
+ * | | | If "u" is specified, this method will discover only Color Bulbs.
72
+ * | | | If "g" is specified, this method will discover only Plugs.
73
+ * | | | If "o" is specified, this method will discover only Locks.
74
+ * | | | If "i" is specified, this method will discover only Meter Pluses.
75
+ * | | | If "r" is specified, this method will discover only Locks.
76
+ * - id | String | Optional | If this value is set, this method will discover
77
+ * | | | only a device whose ID is as same as this value.
78
+ * | | | The ID is identical to the MAC address.
79
+ * | | | This parameter is case-insensitive, and
80
+ * | | | colons are ignored.
81
+ * - quick | Boolean | Optional | If this value is true, this method finishes
82
+ * | | | the discovery process when the first device
83
+ * | | | is found, then calls the resolve() function
84
+ * | | | without waiting the specified duration.
85
+ * | | | The default value is false.
86
+ *
87
+ * [Return value]
88
+ * - Promise object
89
+ * An array will be passed to the `resolve()`, which includes
90
+ * `SwitchbotDevice` objects representing the found devices.
91
+ * ---------------------------------------------------------------- */
92
+ discover(params = {}) {
93
+ const promise = new Promise((resolve, reject) => {
94
+ // Check the parameters
95
+ const valid = ParameterChecker.check(params, {
96
+ duration: { required: false, type: 'integer', min: 1, max: 60000 },
97
+ model: {
98
+ required: false,
99
+ type: 'string',
100
+ enum: [
101
+ 'H',
102
+ 'T',
103
+ 'e',
104
+ 's',
105
+ 'd',
106
+ 'c',
107
+ '{',
108
+ 'u',
109
+ 'g',
110
+ 'j',
111
+ 'o',
112
+ 'i',
113
+ 'r',
114
+ 'x',
115
+ 'w',
116
+ ],
117
+ },
118
+ id: { required: false, type: 'string', min: 12, max: 17 },
119
+ quick: { required: false, type: 'boolean' },
120
+ }, false);
121
+ if (!valid) {
122
+ reject(new Error(ParameterChecker.error.message));
123
+ return;
124
+ }
125
+ if (!params) {
126
+ params = {};
127
+ }
128
+ // Determine the values of the parameters
129
+ const p = {
130
+ duration: params.duration || this.DEFAULT_DISCOVERY_DURATION,
131
+ model: params.model || '',
132
+ id: params.id || '',
133
+ quick: params.quick ? true : false,
134
+ };
135
+ // Initialize the noble object
136
+ this._init()
137
+ .then(() => {
138
+ const peripherals = {};
139
+ let timer = setTimeout(() => { }, 0);
140
+ const finishDiscovery = () => {
141
+ if (timer) {
142
+ clearTimeout(timer);
143
+ }
144
+ this.noble.removeAllListeners('discover');
145
+ this.noble.stopScanning();
146
+ const device_list = [];
147
+ for (const addr in peripherals) {
148
+ device_list.push(peripherals[addr]);
149
+ }
150
+ if (device_list.length) {
151
+ resolve(device_list);
152
+ }
153
+ };
154
+ // Set a handler for the 'discover' event
155
+ this.noble.on('discover', (peripheral) => {
156
+ const device = SwitchBot.getDeviceObject(peripheral, p.id, p.model);
157
+ if (!device) {
158
+ return;
159
+ }
160
+ const id = device.id;
161
+ peripherals[id] = device;
162
+ if (this.ondiscover && typeof this.ondiscover === 'function') {
163
+ this.ondiscover(device);
164
+ }
165
+ if (p.quick) {
166
+ finishDiscovery();
167
+ return;
168
+ }
169
+ });
170
+ // Start scanning
171
+ this.noble.startScanning(this.PRIMARY_SERVICE_UUID_LIST, false, (error) => {
172
+ if (error) {
173
+ reject(error);
174
+ return;
175
+ }
176
+ timer = setTimeout(() => {
177
+ finishDiscovery();
178
+ }, p.duration);
179
+ });
180
+ })
181
+ .catch((error) => {
182
+ reject(error);
183
+ });
184
+ });
185
+ return promise;
186
+ }
187
+ _init() {
188
+ const promise = new Promise((resolve, reject) => {
189
+ let err;
190
+ if (this.noble.state === 'poweredOn') {
191
+ resolve();
192
+ return;
193
+ }
194
+ this.noble.once('stateChange', state => {
195
+ switch (state) {
196
+ case 'unsupported':
197
+ case 'unauthorized':
198
+ case 'poweredOff':
199
+ err = new Error('Failed to initialize the Noble object: ' + this.noble.state);
200
+ reject(err);
201
+ return;
202
+ case 'resetting':
203
+ case 'unknown':
204
+ err = new Error('Adapter is not ready: ' + this.noble.state);
205
+ reject(err);
206
+ return;
207
+ case 'poweredOn':
208
+ resolve();
209
+ return;
210
+ default:
211
+ err = new Error('Uknown state: ' + this.noble.state);
212
+ reject(err);
213
+ return;
214
+ }
215
+ });
216
+ });
217
+ return promise;
218
+ }
219
+ static getDeviceObject(peripheral, id, model) {
220
+ const ad = Advertising.parse(peripheral, this.onlog);
221
+ if (this.filterAdvertising(ad, id, model)) {
222
+ let device;
223
+ if (ad && ad.serviceData && ad.serviceData.model) {
224
+ switch (ad.serviceData.model) {
225
+ case 'H':
226
+ device = new WoHand(peripheral, this.noble);
227
+ break;
228
+ case 'T':
229
+ device = new WoSensorTH(peripheral, this.noble);
230
+ break;
231
+ case 'e':
232
+ device = new WoHumi(peripheral, this.noble);
233
+ break;
234
+ case 's':
235
+ device = new WoPresence(peripheral, this.noble);
236
+ break;
237
+ case 'd':
238
+ device = new WoContact(peripheral, this.noble);
239
+ break;
240
+ case 'c':
241
+ case '{':
242
+ device = new WoCurtain(peripheral, this.noble);
243
+ break;
244
+ case 'x':
245
+ device = new WoBlindTilt(peripheral, this.noble);
246
+ break;
247
+ case 'u':
248
+ device = new WoBulb(peripheral, this.noble);
249
+ break;
250
+ case 'g':
251
+ case 'j':
252
+ device = new WoPlugMini(peripheral, this.noble);
253
+ break;
254
+ case 'o':
255
+ //device = new SwitchbotDeviceWoSmartLock(peripheral, this.noble);
256
+ break;
257
+ case 'i':
258
+ device = new WoSensorTH(peripheral, this.noble);
259
+ break;
260
+ case 'w':
261
+ device = new WoIOSensorTH(peripheral, this.noble);
262
+ break;
263
+ case 'r':
264
+ device = new WoStrip(peripheral, this.noble);
265
+ break;
266
+ default: // 'resetting', 'unknown'
267
+ device = new SwitchbotDevice(peripheral, this.noble);
268
+ }
269
+ }
270
+ return device;
271
+ }
272
+ else {
273
+ return null;
274
+ }
275
+ }
276
+ static filterAdvertising(ad, id, model) {
277
+ if (!ad) {
278
+ return false;
279
+ }
280
+ if (id) {
281
+ id = id.toLowerCase().replace(/:/g, '');
282
+ const ad_id = ad.address.toLowerCase().replace(/[^a-z0-9]/g, '');
283
+ if (ad_id !== id) {
284
+ return false;
285
+ }
286
+ }
287
+ if (model) {
288
+ if (ad.serviceData.model !== model) {
289
+ return false;
290
+ }
291
+ }
292
+ return true;
293
+ }
294
+ /* ------------------------------------------------------------------
295
+ * startScan([params])
296
+ * - Start to monitor advertising packets coming from switchbot devices
297
+ *
298
+ * [Arguments]
299
+ * - params | Object | Optional |
300
+ * - model | String | Optional | "H", "T", "e", "s", "d", "c", "{", "u", "g", "o", "i", "x", or "r".
301
+ * | | | If "H" is specified, the `onadvertisement`
302
+ * | | | event handler will be called only when advertising
303
+ * | | | packets comes from Bots.
304
+ * | | | If "T" is specified, the `onadvertisement`
305
+ * | | | event handler will be called only when advertising
306
+ * | | | packets comes from Meters.
307
+ * | | | If "e" is specified, the `onadvertisement`
308
+ * | | | event handler will be called only when advertising
309
+ * | | | packets comes from Humidifiers.
310
+ * | | | If "s" is specified, the `onadvertisement`
311
+ * | | | event handler will be called only when advertising
312
+ * | | | packets comes from Motion Sensor.
313
+ * | | | If "d" is specified, the `onadvertisement`
314
+ * | | | event handler will be called only when advertising
315
+ * | | | packets comes from Contact Sensor.
316
+ * | | | If "c" is specified, the `onadvertisement`
317
+ * | | | event handler will be called only when advertising
318
+ * | | | packets comes from Curtains.
319
+ * | | | If "{" is specified, the `onadvertisement`
320
+ * | | | event handler will be called only when advertising
321
+ * | | | packets comes from Curtain 3.
322
+ * | | | If "x" is specified, the `onadvertisement`
323
+ * | | | event handler will be called only when advertising
324
+ * | | | packets comes from BlindTilt.
325
+ * | | | If "u" is specified, the `onadvertisement`
326
+ * | | | event handler will be called only when advertising
327
+ * | | | packets comes from Color Bulb.
328
+ * | | | If "g" is specified, the `onadvertisement`
329
+ * | | | event handler will be called only when advertising
330
+ * | | | packets comes from Plug Mini.
331
+ * | | | If "o" is specified, the `onadvertisement`
332
+ * | | | event handler will be called only when advertising
333
+ * | | | packets comes from Smart Lock.
334
+ * | | | If "i" is specified, the `onadvertisement`
335
+ * | | | event handler will be called only when advertising
336
+ * | | | packets comes from Meter Plus.
337
+ * | | | If "r" is specified, the `onadvertisement`
338
+ * | | | event handler will be called only when advertising
339
+ * | | | packets comes from LED Strip Light.
340
+ * - id | String | Optional | If this value is set, the `onadvertisement`
341
+ * | | | event handler will be called only when advertising
342
+ * | | | packets comes from devices whose ID is as same as
343
+ * | | | this value.
344
+ * | | | The ID is identical to the MAC address.
345
+ * | | | This parameter is case-insensitive, and
346
+ * | | | colons are ignored.
347
+ *
348
+ * [Return value]
349
+ * - Promise object
350
+ * Nothing will be passed to the `resolve()`.
351
+ * ---------------------------------------------------------------- */
352
+ startScan(params) {
353
+ const promise = new Promise((resolve, reject) => {
354
+ // Check the parameters
355
+ const valid = ParameterChecker.check(params, {
356
+ model: {
357
+ required: false,
358
+ type: 'string',
359
+ enum: [
360
+ 'H',
361
+ 'T',
362
+ 'e',
363
+ 's',
364
+ 'd',
365
+ 'c',
366
+ '{',
367
+ 'u',
368
+ 'g',
369
+ 'j',
370
+ 'o',
371
+ 'i',
372
+ 'r',
373
+ 'x',
374
+ 'w',
375
+ ],
376
+ },
377
+ id: { required: false, type: 'string', min: 12, max: 17 },
378
+ }, false);
379
+ if (!valid) {
380
+ reject(new Error(ParameterChecker.error.message));
381
+ return;
382
+ }
383
+ if (!params) {
384
+ params = {};
385
+ }
386
+ // Initialize the noble object
387
+ this._init()
388
+ .then(() => {
389
+ // Determine the values of the parameters
390
+ const p = {
391
+ model: params.model || '',
392
+ id: params.id || '',
393
+ };
394
+ // Set a handler for the 'discover' event
395
+ this.noble.on('discover', (peripheral) => {
396
+ const ad = Advertising.parse(peripheral, this.onlog);
397
+ if (SwitchBot.filterAdvertising(ad, p.id, p.model)) {
398
+ if (this.onadvertisement &&
399
+ typeof this.onadvertisement === 'function') {
400
+ this.onadvertisement(ad);
401
+ }
402
+ }
403
+ });
404
+ // Start scanning
405
+ this.noble.startScanning(this.PRIMARY_SERVICE_UUID_LIST, true, (error) => {
406
+ if (error) {
407
+ reject(error);
408
+ }
409
+ else {
410
+ resolve();
411
+ }
412
+ });
413
+ })
414
+ .catch((error) => {
415
+ reject(error);
416
+ });
417
+ });
418
+ return promise;
419
+ }
420
+ /* ------------------------------------------------------------------
421
+ * stopScan()
422
+ * - Stop to monitor advertising packets coming from switchbot devices
423
+ *
424
+ * [Arguments]
425
+ * - none
426
+ *
427
+ * [Return value]
428
+ * - none
429
+ * ---------------------------------------------------------------- */
430
+ stopScan() {
431
+ this.noble.removeAllListeners('discover');
432
+ this.noble.stopScanning();
433
+ }
434
+ /* ------------------------------------------------------------------
435
+ * wait(msec) {
436
+ * - Wait for the specified time (msec)
437
+ *
438
+ * [Arguments]
439
+ * - msec | Integer | Required | Msec.
440
+ *
441
+ * [Return value]
442
+ * - Promise object
443
+ * Nothing will be passed to the `resolve()`.
444
+ * ---------------------------------------------------------------- */
445
+ static wait(msec) {
446
+ return new Promise((resolve, reject) => {
447
+ // Check the parameters
448
+ const valid = ParameterChecker.check({ msec: msec }, {
449
+ msec: { required: true, type: 'integer', min: 0 },
450
+ }, {});
451
+ if (!valid) {
452
+ reject(new Error(ParameterChecker.error.message));
453
+ return;
454
+ }
455
+ // Set a timer
456
+ setTimeout(resolve, msec);
457
+ });
458
+ }
459
+ }
460
+ export { SwitchbotDevice };
461
+ //# sourceMappingURL=switchbot.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"switchbot.js","sourceRoot":"","sources":["../src/switchbot.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAAE,MAAM,wBAAwB,CAAC;AAC1D,OAAO,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAC;AAC/C,OAAO,EAAE,eAAe,EAAE,MAAM,aAAa,CAAC;AAE9C,OAAO,EAAE,MAAM,EAAE,MAAM,oBAAoB,CAAC;AAC5C,OAAO,EAAE,SAAS,EAAE,MAAM,uBAAuB,CAAC;AAClD,OAAO,EAAE,WAAW,EAAE,MAAM,yBAAyB,CAAC;AACtD,OAAO,EAAE,UAAU,EAAE,MAAM,wBAAwB,CAAC;AACpD,OAAO,EAAE,SAAS,EAAE,MAAM,uBAAuB,CAAC;AAClD,OAAO,EAAE,UAAU,EAAE,MAAM,wBAAwB,CAAC;AACpD,OAAO,EAAE,YAAY,EAAE,MAAM,0BAA0B,CAAC;AACxD,OAAO,EAAE,MAAM,EAAE,MAAM,oBAAoB,CAAC;AAC5C,OAAO,EAAE,UAAU,EAAE,MAAM,wBAAwB,CAAC;AACpD,OAAO,EAAE,MAAM,EAAE,MAAM,oBAAoB,CAAC;AAC5C,OAAO,EAAE,OAAO,EAAE,MAAM,qBAAqB,CAAC;AAe9C,MAAM,OAAO,SAAS;IACpB,KAAK,CAAC;IACN,UAAU,CAAC;IACX,eAAe,CAAC;IAChB,KAAK,CAAC;IACN,QAAQ,CAAC;IACT,0BAA0B,CAAC;IAC3B,yBAAyB,CAAC;IAC1B,MAAM,CAAC,KAAK,CAAM;IAClB,MAAM,CAAC,KAAK,CA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E;IACxE,MAAM,CAAC,IAAI,CAAC,IAAI;QACd,OAAO,IAAI,OAAO,CAAC,CAAC,OAAO,EAAE,MAAM,EAAE,EAAE;YACrC,uBAAuB;YACvB,MAAM,KAAK,GAAG,gBAAgB,CAAC,KAAK,CAClC,EAAE,IAAI,EAAE,IAAI,EAAE,EACd;gBACE,IAAI,EAAE,EAAE,QAAQ,EAAE,IAAI,EAAE,IAAI,EAAE,SAAS,EAAE,GAAG,EAAE,CAAC,EAAE;aAClD,EACD,EAAE,CACH,CAAC;YAEF,IAAI,CAAC,KAAK,EAAE,CAAC;gBACX,MAAM,CAAC,IAAI,KAAK,CAAC,gBAAgB,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC;gBAClD,OAAO;YACT,CAAC;YACD,cAAc;YACd,UAAU,CAAC,OAAO,EAAE,IAAI,CAAC,CAAC;QAC5B,CAAC,CAAC,CAAC;IACL,CAAC;CACF;AAED,OAAO,EAAE,eAAe,EAAE,CAAC"}
package/errros.log ADDED
@@ -0,0 +1,13 @@
1
+
2
+ /usr/local/lib/node_modules/@switchbot/homebridge-switchbot/node_modules/node-switchbot/node_modules/@abandonware/noble/lib/noble.js:137
3
+ this._bindings.startScanning(serviceUuids, allowDuplicates);
4
+ ^
5
+ TypeError: A string was expected
6
+ at Noble.scan (/usr/local/lib/node_modules/@switchbot/homebridge-switchbot/node_modules/node-switchbot/node_modules/@abandonware/noble/lib/noble.js:137:22)
7
+ at Noble.startScanning (/usr/local/lib/node_modules/@switchbot/homebridge-switchbot/node_modules/node-switchbot/node_modules/@abandonware/noble/lib/noble.js:149:10)
8
+ at /usr/local/lib/node_modules/@switchbot/homebridge-switchbot/node_modules/node-switchbot/node_modules/@abandonware/noble/lib/noble.js:155:44
9
+ at node:internal/util:364:7
10
+ at new Promise (<anonymous>)
11
+ at node:internal/util:350:12
12
+ at Noble.startScanningAsync (/usr/local/lib/node_modules/@switchbot/homebridge-switchbot/node_modules/node-switchbot/node_modules/@abandonware/noble/lib/noble.js:155:99)
13
+ at /usr/local/lib/node_modules/@switchbot/homebridge-switchbot/node_modules/node-switchbot/lib/switchbot.js:374:22
package/package.json CHANGED
@@ -1,18 +1,18 @@
1
1
  {
2
2
  "name": "node-switchbot",
3
- "version": "1.9.2-beta.2",
3
+ "version": "2.0.0-beta.0",
4
4
  "description": "The node-switchbot is a Node.js module which allows you to control your Switchbot Devices through Bluetooth (BLE).",
5
- "main": "./lib/switchbot.js",
6
- "files": [
7
- "lib"
8
- ],
9
- "directories": {
10
- "lib": "./lib"
11
- },
5
+ "main": "dist/index.js",
6
+ "type": "module",
12
7
  "scripts": {
13
8
  "check": "npm install && npm outdated",
14
9
  "update": "ncu -u && npm update && npm install",
15
- "lint": "eslint . --ext .js"
10
+ "lint": "eslint src/**.ts",
11
+ "build": "rimraf ./dist && tsc",
12
+ "prepublishOnly": "npm run lint && npm run build",
13
+ "postpublish": "npm run clean",
14
+ "clean": "rimraf ./dist",
15
+ "test": "eslint src/**.ts"
16
16
  },
17
17
  "keywords": [
18
18
  "switchbot",
@@ -42,7 +42,15 @@
42
42
  "@abandonware/bluetooth-hci-socket": "^0.5.3-10"
43
43
  },
44
44
  "devDependencies": {
45
- "eslint": "^8.54.0",
46
- "npm-check-updates": "^16.14.11"
45
+ "@types/node": "^20.11.5",
46
+ "@typescript-eslint/eslint-plugin": "^6.19.1",
47
+ "@typescript-eslint/parser": "^6.19.1",
48
+ "eslint": "^8.56.0",
49
+ "homebridge": "^1.7.0",
50
+ "nodemon": "^3.0.3",
51
+ "npm-check-updates": "^16.14.12",
52
+ "rimraf": "^5.0.5",
53
+ "ts-node": "^10.9.2",
54
+ "typescript": "^5.3.3"
47
55
  }
48
56
  }