node-switchbot 1.10.0 → 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 -12
  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,488 @@
1
+ import { Buffer } from 'buffer';
2
+ export class ParameterChecker {
3
+ _error;
4
+ static error;
5
+ constructor() {
6
+ this._error = null;
7
+ }
8
+ get error() {
9
+ // ----------------------------------
10
+ // Error
11
+ // {
12
+ // code: 'TYPE_INVALID',
13
+ // message: 'The `age` must be an integer.'
14
+ // name: 'age',
15
+ // }
16
+ // ---------------------------------
17
+ return this._error;
18
+ }
19
+ static isSpecified(value) {
20
+ return value === void 0 ? false : true;
21
+ }
22
+ /* ------------------------------------------------------------------
23
+ * check(obj, rule, required)
24
+ * - Check if the specified object contains valid values
25
+ *
26
+ * [Arguments]
27
+ * - obj | Object | Required | Object including parameters you want to check
28
+ * - rules | Object | Required | Object including rules for the parameters
29
+ * - required | Boolean | Optional | Flag whther the `obj` is required or not.
30
+ * | | | The default is `false`
31
+ *
32
+ * [Return value]
33
+ * - If the value is valid, this method will return `true`.
34
+ * - If the value is invalid, this method will return `false` and
35
+ * an `Error` object will be set to `this._error`.
36
+ *
37
+ * [Usage]
38
+ * const valid = parameterChecker.check(params, {
39
+ * level: {
40
+ * required: false,
41
+ * type: 'integer',
42
+ * max: 100
43
+ * },
44
+ * greeting: {
45
+ * required: true, // But an empty string is allowed.
46
+ * type: 'string',
47
+ * max: 20 // the number of characters must be up to 20.
48
+ * }
49
+ * });
50
+ * if(!valid) {
51
+ * const e = parameterChecker.error.message;
52
+ * throw new Error(message);
53
+ * }
54
+ * ---------------------------------------------------------------- */
55
+ static check(obj, rules, required) {
56
+ this.error;
57
+ if (required) {
58
+ if (!this.isSpecified(obj)) {
59
+ this.error = {
60
+ code: 'MISSING_REQUIRED',
61
+ message: 'The first argument is missing.',
62
+ };
63
+ return false;
64
+ }
65
+ }
66
+ else {
67
+ if (!obj) {
68
+ return true;
69
+ }
70
+ }
71
+ if (!this.isObject(obj, {})) {
72
+ this.error = {
73
+ code: 'MISSING_REQUIRED',
74
+ message: 'The first argument is missing.',
75
+ };
76
+ return false;
77
+ }
78
+ let result = true;
79
+ const name_list = Object.keys(rules);
80
+ for (let i = 0; i < name_list.length; i++) {
81
+ const name = name_list[i];
82
+ const v = obj[name];
83
+ let rule = rules[name];
84
+ if (!rule) {
85
+ rule = {};
86
+ }
87
+ if (!this.isSpecified(v)) {
88
+ if (rule.required) {
89
+ result = false;
90
+ this.error = {
91
+ code: 'MISSING_REQUIRED',
92
+ message: 'The `' + name + '` is required.',
93
+ };
94
+ break;
95
+ }
96
+ else {
97
+ continue;
98
+ }
99
+ }
100
+ if (rule.type === 'float') {
101
+ result = this.isFloat(v, rule, name);
102
+ }
103
+ else if (rule.type === 'integer') {
104
+ result = this.isInteger(v, rule, name);
105
+ }
106
+ else if (rule.type === 'boolean') {
107
+ result = this.isBoolean(v, rule, name);
108
+ }
109
+ else if (rule.type === 'array') {
110
+ result = this.isArray(v, rule, name);
111
+ }
112
+ else if (rule.type === 'object') {
113
+ result = this.isObject(v, rule, name);
114
+ }
115
+ else if (rule.type === 'string') {
116
+ result = this.isString(v, rule, name);
117
+ }
118
+ else {
119
+ result = false;
120
+ this.error = {
121
+ code: 'TYPE_UNKNOWN',
122
+ message: 'The rule specified for the `' +
123
+ name +
124
+ '` includes an unknown type: ' +
125
+ rule.type,
126
+ };
127
+ }
128
+ if (result === false) {
129
+ this.error.name = name;
130
+ break;
131
+ }
132
+ }
133
+ return result;
134
+ }
135
+ /* ------------------------------------------------------------------
136
+ * isFloat(value, rule, name)
137
+ * - Check if the value is a float
138
+ *
139
+ * [Arguments]
140
+ * - value | Any | Required | The value you want to check
141
+ * - rule | Object | Optional |
142
+ * - required | Boolean | Optional | Required or not. Default is `false`.
143
+ * - min | Float | Optional | Minimum number
144
+ * - max | Float | Optional | Maximum number
145
+ * - enum | Array | Optional | list of possible values
146
+ * - name | String | Optional | Parameter name
147
+ *
148
+ * If non-number value is specified to the `min` or `max`,
149
+ * they will be ignored.
150
+ *
151
+ * [Return value]
152
+ * - If the value is valid, this method will return `true`.
153
+ * - If the value is invalid, this method will return `false` and
154
+ * an `Error` object will be set to `this._error`.
155
+ * ---------------------------------------------------------------- */
156
+ static isFloat(value, rule, name = 'value') {
157
+ this.error;
158
+ if (!rule.required && !this.isSpecified(value)) {
159
+ return true;
160
+ }
161
+ if (typeof value !== 'number') {
162
+ this.error = {
163
+ code: 'TYPE_INVALID',
164
+ message: 'The `' + name + '` must be a number (integer or float).',
165
+ };
166
+ return false;
167
+ }
168
+ if (typeof rule.min === 'number') {
169
+ if (value < rule.min) {
170
+ this.error = {
171
+ code: 'VALUE_UNDERFLOW',
172
+ message: 'The `' +
173
+ name +
174
+ '` must be grater than or equal to ' +
175
+ rule.min +
176
+ '.',
177
+ };
178
+ return false;
179
+ }
180
+ }
181
+ if (typeof rule.max === 'number') {
182
+ if (value > rule.max) {
183
+ this.error = {
184
+ code: 'VALUE_OVERFLOW',
185
+ message: 'The `' +
186
+ name +
187
+ '` must be less than or equal to ' +
188
+ rule.max +
189
+ '.',
190
+ };
191
+ return false;
192
+ }
193
+ }
194
+ if (Array.isArray(rule.enum) && rule.enum.length > 0) {
195
+ if (rule.enum.indexOf(value) === -1) {
196
+ this.error = {
197
+ code: 'ENUM_UNMATCH',
198
+ message: 'The `' +
199
+ name +
200
+ '` must be any one of ' +
201
+ JSON.stringify(rule.enum) +
202
+ '.',
203
+ };
204
+ return false;
205
+ }
206
+ }
207
+ return true;
208
+ }
209
+ /* ------------------------------------------------------------------
210
+ * isInteger(value, rule)
211
+ * - Check if the value is an integer
212
+ *
213
+ * [Arguments]
214
+ * - value | Any | Required | The value you want to check
215
+ * - rule | Object | Optional |
216
+ * - required | Boolean | Optional | Required or not. Default is `false`.|
217
+ * - min | Float | Optional | Minimum number
218
+ * - max | Float | Optional | Maximum number
219
+ * - enum | Array | Optional | list of possible values
220
+ * - name | String | Optional | Parameter name
221
+ *
222
+ * If non-number value is specified to the `min` or `max`,
223
+ * they will be ignored.
224
+ *
225
+ * [Return value]
226
+ * - If the value is valid, this method will return `true`.
227
+ * - If the value is invalid, this method will return `false` and
228
+ * an `Error` object will be set to `this._error`.
229
+ * ---------------------------------------------------------------- */
230
+ static isInteger(value, rule, name = 'value') {
231
+ this.error = null;
232
+ if (!rule.required && !this.isSpecified(value)) {
233
+ return true;
234
+ }
235
+ if (this.isFloat(value, rule)) {
236
+ if (value % 1 === 0) {
237
+ return true;
238
+ }
239
+ else {
240
+ this.error = {
241
+ code: 'TYPE_INVALID',
242
+ message: 'The `' + name + '` must be an integer.',
243
+ };
244
+ return false;
245
+ }
246
+ }
247
+ else {
248
+ return false;
249
+ }
250
+ }
251
+ /* ------------------------------------------------------------------
252
+ * isBoolean(value, rule, name)
253
+ * - Check if the value is a boolean.
254
+ *
255
+ * [Arguments]
256
+ * - value | Any | Required | The value you want to check
257
+ * - rule | Object | Optional |
258
+ * - required | Boolean | Optional | Required or not. Default is `false`.
259
+ * - name | String | Optional | Parameter name
260
+ *
261
+ * [Return value]
262
+ * - If the value is valid, this method will return `true`.
263
+ * - If the value is invalid, this method will return `false` and
264
+ * an `Error` object will be set to `this._error`.
265
+ * ---------------------------------------------------------------- */
266
+ static isBoolean(value, rule, name = 'value') {
267
+ this.error = null;
268
+ if (!rule.required && !this.isSpecified(value)) {
269
+ return true;
270
+ }
271
+ if (typeof value !== 'boolean') {
272
+ this.error = {
273
+ code: 'TYPE_INVALID',
274
+ message: 'The `' + name + '` must be boolean.',
275
+ };
276
+ return false;
277
+ }
278
+ return true;
279
+ }
280
+ /* ------------------------------------------------------------------
281
+ * isObject(value)
282
+ * - Check if the value is an object
283
+ *
284
+ * [Arguments]
285
+ * - value | Any | Required | The value you want to check
286
+ * - rule | Object | Optional |
287
+ * - required | Boolean | Optional | Required or not. Default is `false`.
288
+ * - name | String | Optional | Parameter name
289
+ *
290
+ * [Return value]
291
+ * - If the value is valid, this method will return `true`.
292
+ * - If the value is invalid, this method will return `false` and
293
+ * an `Error` object will be set to `this._error`.
294
+ * ---------------------------------------------------------------- */
295
+ static isObject(value, rule, name = 'value') {
296
+ this.error = null;
297
+ if (!rule.required && !this.isSpecified(value)) {
298
+ return true;
299
+ }
300
+ if (typeof value !== 'object' || value === null || Array.isArray(value)) {
301
+ this.error = {
302
+ code: 'TYPE_INVALID',
303
+ message: 'The `' + name + '` must be an object.',
304
+ };
305
+ return false;
306
+ }
307
+ return true;
308
+ }
309
+ /* ------------------------------------------------------------------
310
+ * isArray(value, rule, name)
311
+ * - Check if the value is an `Array` object
312
+ *
313
+ * [Arguments]
314
+ * - value | Any | Required | The value you want to check
315
+ * - rule | Object | Optional |
316
+ * - required | Boolean | Optional | Required or not. Default is `false`.
317
+ * - min | Integer | Optional | Minimum number of elements in the array
318
+ * - max | Integer | Optional | Maximum number of elements in the array
319
+ * - name | String | Optional | Parameter name
320
+ *
321
+ * If non-number value is specified to the `min` or `max`,
322
+ * they will be ignored.
323
+ *
324
+ * [Return value]
325
+ * - If the value is valid, this method will return `true`.
326
+ * - If the value is invalid, this method will return `false` and
327
+ * an `Error` object will be set to `this._error`.
328
+ * ---------------------------------------------------------------- */
329
+ static isArray(value, rule, name = 'value') {
330
+ this.error = null;
331
+ if (!rule.required && !this.isSpecified(value)) {
332
+ return true;
333
+ }
334
+ if (!Array.isArray(value)) {
335
+ this.error = {
336
+ code: 'TYPE_INVALID',
337
+ message: 'The value must be an array.',
338
+ };
339
+ return false;
340
+ }
341
+ if (typeof rule.min === 'number') {
342
+ if (value.length < rule.min) {
343
+ this.error = {
344
+ code: 'LENGTH_UNDERFLOW',
345
+ message: 'The number of characters in the `' +
346
+ name +
347
+ '` must be grater than or equal to ' +
348
+ rule.min +
349
+ '.',
350
+ };
351
+ return false;
352
+ }
353
+ }
354
+ if (typeof rule.max === 'number') {
355
+ if (value.length > rule.max) {
356
+ this.error = {
357
+ code: 'LENGTH_OVERFLOW',
358
+ message: 'The number of characters in the `' +
359
+ name +
360
+ '` must be less than or equal to ' +
361
+ rule.max +
362
+ '.',
363
+ };
364
+ return false;
365
+ }
366
+ }
367
+ return true;
368
+ }
369
+ /* ------------------------------------------------------------------
370
+ * isString(value, rule, name)
371
+ * - Check if the value is an `Array` object
372
+ *
373
+ * [Arguments]
374
+ * - value | Any | Required | The value you want to check
375
+ * - rule | Object | Optional |
376
+ * - required | Boolean | Optional | Required or not. Default is `false`.
377
+ * - min | Integer | Optional | Minimum number of characters in the string
378
+ * - max | Integer | Optional | Maximum number of characters in the string
379
+ * - minBytes | Integer | Optional | Minimum bytes of the string (UTF-8)
380
+ * - maxBytes | Integer | Optional | Maximum bytes of the string (UTF-8)
381
+ * - pattern | RegExp | Optional | Pattern of the string
382
+ * - enum | Array | Optional | list of possible values
383
+ * - name | String | Optional | Parameter name
384
+ *
385
+ * If non-number value is specified to the `min` or `max`,
386
+ * they will be ignored.
387
+ *
388
+ * [Return value]
389
+ * - If the value is valid, this method will return `true`.
390
+ * - If the value is invalid, this method will return `false` and
391
+ * an `Error` object will be set to `this._error`.
392
+ * ---------------------------------------------------------------- */
393
+ static isString(value, rule, name = 'value') {
394
+ this.error = null;
395
+ if (!rule.required && !this.isSpecified(value)) {
396
+ return true;
397
+ }
398
+ if (typeof value !== 'string') {
399
+ this.error = {
400
+ code: 'TYPE_INVALID',
401
+ message: 'The value must be a string.',
402
+ };
403
+ return false;
404
+ }
405
+ if (typeof rule.min === 'number') {
406
+ if (value.length < rule.min) {
407
+ this.error = {
408
+ code: 'LENGTH_UNDERFLOW',
409
+ message: 'The number of characters in the `' +
410
+ name +
411
+ '` must be grater than or equal to ' +
412
+ rule.min +
413
+ '.',
414
+ };
415
+ return false;
416
+ }
417
+ }
418
+ if (typeof rule.max === 'number') {
419
+ if (value.length > rule.max) {
420
+ this.error = {
421
+ code: 'LENGTH_OVERFLOW',
422
+ message: 'The number of characters in the `' +
423
+ name +
424
+ '` must be less than or equal to ' +
425
+ rule.max +
426
+ '.',
427
+ };
428
+ return false;
429
+ }
430
+ }
431
+ if (typeof rule.minBytes === 'number') {
432
+ const blen = Buffer.from(value, 'utf8').length;
433
+ if (blen < rule.minBytes) {
434
+ this.error = {
435
+ code: 'LENGTH_UNDERFLOW',
436
+ message: 'The byte length of the `' +
437
+ name +
438
+ '` (' +
439
+ blen +
440
+ ' bytes) must be grater than or equal to ' +
441
+ rule.minBytes +
442
+ ' bytes.',
443
+ };
444
+ return false;
445
+ }
446
+ }
447
+ if (typeof rule.maxBytes === 'number') {
448
+ const blen = Buffer.from(value, 'utf8').length;
449
+ if (blen > rule.maxBytes) {
450
+ this.error = {
451
+ code: 'LENGTH_OVERFLOW',
452
+ message: 'The byte length of the `' +
453
+ name +
454
+ '` (' +
455
+ blen +
456
+ ' bytes) must be less than or equal to ' +
457
+ rule.maxBytes +
458
+ ' bytes.',
459
+ };
460
+ return false;
461
+ }
462
+ }
463
+ if (rule.pattern instanceof RegExp) {
464
+ if (!rule.pattern.test(value)) {
465
+ this.error = {
466
+ code: 'PATTERN_UNMATCH',
467
+ message: 'The `' + name + '` does not conform with the pattern.',
468
+ };
469
+ return false;
470
+ }
471
+ }
472
+ if (Array.isArray(rule.enum) && rule.enum.length > 0) {
473
+ if (rule.enum.indexOf(value) === -1) {
474
+ this.error = {
475
+ code: 'ENUM_UNMATCH',
476
+ message: 'The `' +
477
+ name +
478
+ '` must be any one of ' +
479
+ JSON.stringify(rule.enum) +
480
+ '.',
481
+ };
482
+ return false;
483
+ }
484
+ }
485
+ return true;
486
+ }
487
+ }
488
+ //# sourceMappingURL=parameter-checker.js.map
@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BACb,SAAS;iBACZ,CAAC;gBACF,OAAO,KAAK,CAAC;YACf,CAAC;QACH,CAAC;QACD,IAAI,IAAI,CAAC,OAAO,YAAY,MAAM,EAAE,CAAC;YACnC,IAAI,CAAC,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,KAAK,CAAC,EAAE,CAAC;gBAC9B,IAAI,CAAC,KAAK,GAAG;oBACX,IAAI,EAAE,iBAAiB;oBACvB,OAAO,EAAE,OAAO,GAAG,IAAI,GAAG,sCAAsC;iBACjE,CAAC;gBACF,OAAO,KAAK,CAAC;YACf,CAAC;QACH,CAAC;QACD,IAAI,KAAK,CAAC,OAAO,CAAC,IAAI,CAAC,IAAI,CAAC,IAAI,IAAI,CAAC,IAAI,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;YACrD,IAAI,IAAI,CAAC,IAAI,CAAC,OAAO,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC;gBACpC,IAAI,CAAC,KAAK,GAAG;oBACX,IAAI,EAAE,cAAc;oBACpB,OAAO,EACL,OAAO;wBACP,IAAI;wBACJ,uBAAuB;wBACvB,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,IAAI,CAAC;wBACzB,GAAG;iBACN,CAAC;gBACF,OAAO,KAAK,CAAC;YACf,CAAC;QACH,CAAC;QAED,OAAO,IAAI,CAAC;IACd,CAAC;CACF"}
@@ -0,0 +1,29 @@
1
+ import { SwitchbotDevice } from './device.js';
2
+ type params = {
3
+ duration?: number;
4
+ model?: string;
5
+ id?: string;
6
+ quick?: false;
7
+ noble?: any;
8
+ };
9
+ export declare class SwitchBot {
10
+ noble: any;
11
+ ondiscover: any;
12
+ onadvertisement: any;
13
+ onlog: any;
14
+ scanning: any;
15
+ DEFAULT_DISCOVERY_DURATION: any;
16
+ PRIMARY_SERVICE_UUID_LIST: any;
17
+ static onlog: any;
18
+ static noble: any;
19
+ constructor(params?: params);
20
+ discover(params?: params): Promise<unknown>;
21
+ _init(): Promise<void>;
22
+ static getDeviceObject(peripheral: any, id: any, model: any): any;
23
+ static filterAdvertising(ad: any, id: any, model: any): boolean;
24
+ startScan(params: any): Promise<void>;
25
+ stopScan(): void;
26
+ static wait(msec: any): Promise<unknown>;
27
+ }
28
+ export { SwitchbotDevice };
29
+ //# sourceMappingURL=switchbot.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"switchbot.d.ts","sourceRoot":"","sources":["../src/switchbot.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,eAAe,EAAE,MAAM,aAAa,CAAC;AAc9C,KAAK,MAAM,GAAG;IACV,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,EAAE,CAAC,EAAE,MAAM,CAAC;IACZ,KAAK,CAAC,EAAE,KAAK,CAAC;IACd,KAAK,CAAC,EAAE,GAAG,CAAC;CACf,CAAA;AAOD,qBAAa,SAAS;IACpB,KAAK,MAAC;IACN,UAAU,MAAC;IACX,eAAe,MAAC;IAChB,KAAK,MAAC;IACN,QAAQ,MAAC;IACT,0BAA0B,MAAC;IAC3B,yBAAyB,MAAC;IAC1B,MAAM,CAAC,KAAK,EAAE,GAAG,CAAC;IAClB,MAAM,CAAC,KAAK,EAAE,GAAG,CAAC;gBAaN,MAAM,GAAE,MAAW;IA2D/B,QAAQ,CAAC,MAAM,GAAE,MAAW;IAgH5B,KAAK;IAuCL,MAAM,CAAC,eAAe,CAAC,UAAU,KAAA,EAAE,EAAE,KAAA,EAAE,KAAK,KAAA;IAyD5C,MAAM,CAAC,iBAAiB,CAAC,EAAE,KAAA,EAAE,EAAE,KAAA,EAAE,KAAK,KAAA;IA6EtC,SAAS,CAAC,MAAM,KAAA;IA4FhB,QAAQ;IAgBR,MAAM,CAAC,IAAI,CAAC,IAAI,KAAA;CAmBjB;AAED,OAAO,EAAE,eAAe,EAAE,CAAC"}