node-switchbot 1.2.0 → 1.2.1-beta.2
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/lib/switchbot-advertising.js +165 -32
- package/lib/switchbot.js +42 -7
- package/package.json +40 -40
|
@@ -76,16 +76,26 @@ class SwitchbotAdvertising {
|
|
|
76
76
|
|
|
77
77
|
if (model === 'H') { // WoHand
|
|
78
78
|
sd = this._parseServiceDataForWoHand(buf, onlog);
|
|
79
|
-
} else if (model === 'e') { // WoHumi
|
|
80
|
-
sd = this._parseServiceDataForWoHumi(buf, onlog);
|
|
81
79
|
} else if (model === 'T') { // WoSensorTH
|
|
82
80
|
sd = this._parseServiceDataForWoSensorTH(buf, onlog);
|
|
83
|
-
} else if (model === '
|
|
84
|
-
sd = this.
|
|
81
|
+
} else if (model === 'e') { // WoHumi
|
|
82
|
+
sd = this._parseServiceDataForWoHumi(buf, onlog);
|
|
85
83
|
} else if (model === 's') { // WoMotion
|
|
86
84
|
sd = this._parseServiceDataForWoPresence(buf, onlog);
|
|
87
85
|
} else if (model === 'd') { // WoContact
|
|
88
86
|
sd = this._parseServiceDataForWoContact(buf, onlog);
|
|
87
|
+
} else if (model === 'c') { // WoCurtain
|
|
88
|
+
sd = this._parseServiceDataForWoCurtain(buf, onlog);
|
|
89
|
+
} else if (model === 'u') { // WoColorBulb
|
|
90
|
+
sd = this._parseServiceDataForWoColorBulb(buf, onlog);
|
|
91
|
+
} else if (model === 'g') { // WoPlugMini
|
|
92
|
+
sd = this._parseServiceDataForWoPlugMini(buf, onlog);
|
|
93
|
+
} else if (model === 'o') { // WoSmartLock
|
|
94
|
+
sd = this._parseServiceDataForWoSmartLock(buf, onlog);
|
|
95
|
+
} else if (model === 'i') { // WoMeterPlus
|
|
96
|
+
sd = this._parseServiceDataForWoSensorTHPlus(buf, onlog);
|
|
97
|
+
} else if (model === 'r') { // WoLEDStripLight
|
|
98
|
+
sd = this._parseServiceDataForWoLEDStripLight(buf, onlog);
|
|
89
99
|
} else {
|
|
90
100
|
if (onlog && typeof onlog === 'function') {
|
|
91
101
|
onlog(`[parseAdvertising.${peripheral.id}] return null, model "${model}" not available!`);
|
|
@@ -152,34 +162,6 @@ class SwitchbotAdvertising {
|
|
|
152
162
|
return data;
|
|
153
163
|
}
|
|
154
164
|
|
|
155
|
-
_parseServiceDataForWoHumi(buf, onlog) {
|
|
156
|
-
if (buf.length !== 8) {
|
|
157
|
-
if (onlog && typeof onlog === 'function') {
|
|
158
|
-
onlog(`[_parseServiceDataForWoHumi] Buffer length ${buf.length} !== 8!`);
|
|
159
|
-
}
|
|
160
|
-
return null;
|
|
161
|
-
}
|
|
162
|
-
let byte1 = buf.readUInt8(1);
|
|
163
|
-
// let byte2 = buf.readUInt8(2);
|
|
164
|
-
let byte3 = buf.readUInt8(3);
|
|
165
|
-
let byte4 = buf.readUInt8(4);
|
|
166
|
-
let byte5 = buf.readUInt8(5);
|
|
167
|
-
|
|
168
|
-
let onState = (byte1 & 0b10000000) ? true : false; // 1 - on
|
|
169
|
-
let autoMode = (byte4 & 0b10000000) ? true : false; // 1 - auto
|
|
170
|
-
let percentage = byte4 & 0b01111111; // 0-100%, 101/102/103 - Quick gear 1/2/3
|
|
171
|
-
|
|
172
|
-
let data = {
|
|
173
|
-
model: 'e',
|
|
174
|
-
modelName: 'WoHumi',
|
|
175
|
-
onState: onState,
|
|
176
|
-
autoMode: autoMode,
|
|
177
|
-
percentage: autoMode ? 0 : percentage,
|
|
178
|
-
};
|
|
179
|
-
|
|
180
|
-
return data;
|
|
181
|
-
}
|
|
182
|
-
|
|
183
165
|
_parseServiceDataForWoSensorTH(buf, onlog) {
|
|
184
166
|
if (buf.length !== 6) {
|
|
185
167
|
if (onlog && typeof onlog === 'function') {
|
|
@@ -212,6 +194,34 @@ class SwitchbotAdvertising {
|
|
|
212
194
|
return data;
|
|
213
195
|
}
|
|
214
196
|
|
|
197
|
+
_parseServiceDataForWoHumi(buf, onlog) {
|
|
198
|
+
if (buf.length !== 8) {
|
|
199
|
+
if (onlog && typeof onlog === 'function') {
|
|
200
|
+
onlog(`[_parseServiceDataForWoHumi] Buffer length ${buf.length} !== 8!`);
|
|
201
|
+
}
|
|
202
|
+
return null;
|
|
203
|
+
}
|
|
204
|
+
let byte1 = buf.readUInt8(1);
|
|
205
|
+
// let byte2 = buf.readUInt8(2);
|
|
206
|
+
let byte3 = buf.readUInt8(3);
|
|
207
|
+
let byte4 = buf.readUInt8(4);
|
|
208
|
+
let byte5 = buf.readUInt8(5);
|
|
209
|
+
|
|
210
|
+
let onState = (byte1 & 0b10000000) ? true : false; // 1 - on
|
|
211
|
+
let autoMode = (byte4 & 0b10000000) ? true : false; // 1 - auto
|
|
212
|
+
let percentage = byte4 & 0b01111111; // 0-100%, 101/102/103 - Quick gear 1/2/3
|
|
213
|
+
|
|
214
|
+
let data = {
|
|
215
|
+
model: 'e',
|
|
216
|
+
modelName: 'WoHumi',
|
|
217
|
+
onState: onState,
|
|
218
|
+
autoMode: autoMode,
|
|
219
|
+
percentage: autoMode ? 0 : percentage,
|
|
220
|
+
};
|
|
221
|
+
|
|
222
|
+
return data;
|
|
223
|
+
}
|
|
224
|
+
|
|
215
225
|
_parseServiceDataForWoPresence(buf, onlog) {
|
|
216
226
|
if (buf.length !== 6) {
|
|
217
227
|
if (onlog && typeof onlog === 'function') {
|
|
@@ -303,6 +313,129 @@ class SwitchbotAdvertising {
|
|
|
303
313
|
|
|
304
314
|
return data;
|
|
305
315
|
}
|
|
316
|
+
|
|
317
|
+
_parseServiceDataForWoColorBulb(buf, onlog) {
|
|
318
|
+
if (buf.length !== 6) {
|
|
319
|
+
if (onlog && typeof onlog === 'function') {
|
|
320
|
+
onlog(`[_parseServiceDataForWoColorBulb] Buffer length ${buf.length} !== 6!`);
|
|
321
|
+
}
|
|
322
|
+
return null;
|
|
323
|
+
}
|
|
324
|
+
let byte1 = buf.readUInt8(1);
|
|
325
|
+
let byte2 = buf.readUInt8(2);
|
|
326
|
+
// let byte3 = buf.readUInt8(3);
|
|
327
|
+
// let byte4 = buf.readUInt8(4);
|
|
328
|
+
let byte5 = buf.readUInt8(5);
|
|
329
|
+
|
|
330
|
+
let data = {
|
|
331
|
+
model: 'u',
|
|
332
|
+
modelName: 'WoColorBulb',
|
|
333
|
+
};
|
|
334
|
+
|
|
335
|
+
return data;
|
|
336
|
+
}
|
|
337
|
+
|
|
338
|
+
_parseServiceDataForWoPlugMini(buf, onlog) {
|
|
339
|
+
if (buf.length !== 6) {
|
|
340
|
+
if (onlog && typeof onlog === 'function') {
|
|
341
|
+
onlog(`[_parseServiceDataForWoPlugMini] Buffer length ${buf.length} !== 6!`);
|
|
342
|
+
}
|
|
343
|
+
return null;
|
|
344
|
+
}
|
|
345
|
+
let byte1 = buf.readUInt8(1);
|
|
346
|
+
let byte2 = buf.readUInt8(2);
|
|
347
|
+
// let byte3 = buf.readUInt8(3);
|
|
348
|
+
// let byte4 = buf.readUInt8(4);
|
|
349
|
+
let byte5 = buf.readUInt8(5);
|
|
350
|
+
|
|
351
|
+
let data = {
|
|
352
|
+
model: 'g',
|
|
353
|
+
modelName: 'WoPlugMini',
|
|
354
|
+
};
|
|
355
|
+
|
|
356
|
+
return data;
|
|
357
|
+
}
|
|
358
|
+
|
|
359
|
+
_parseServiceDataForWoSmartLock(buf, onlog) {
|
|
360
|
+
if (buf.length !== 6) {
|
|
361
|
+
if (onlog && typeof onlog === 'function') {
|
|
362
|
+
onlog(`[_parseServiceDataForWoSmartLock] Buffer length ${buf.length} !== 6!`);
|
|
363
|
+
}
|
|
364
|
+
return null;
|
|
365
|
+
}
|
|
366
|
+
let byte1 = buf.readUInt8(1);
|
|
367
|
+
let byte2 = buf.readUInt8(2);
|
|
368
|
+
// let byte3 = buf.readUInt8(3);
|
|
369
|
+
// let byte4 = buf.readUInt8(4);
|
|
370
|
+
let byte5 = buf.readUInt8(5);
|
|
371
|
+
|
|
372
|
+
//let pirState = (byte1 & 0b01000000) ? true : false; // 1 - Movement detected
|
|
373
|
+
let battery = byte2 & 0b01111111; // %
|
|
374
|
+
//let lightLevel = byte5 & 0b00000011;
|
|
375
|
+
|
|
376
|
+
let data = {
|
|
377
|
+
model: 'o',
|
|
378
|
+
modelName: 'WoSmartLock',
|
|
379
|
+
//movement: pirState,
|
|
380
|
+
battery: battery,
|
|
381
|
+
//lightLevel: (lightLevel == 1) ? 'dark' : ((lightLevel == 2) ? 'bright' : 'unknown'),
|
|
382
|
+
};
|
|
383
|
+
|
|
384
|
+
return data;
|
|
385
|
+
}
|
|
386
|
+
|
|
387
|
+
_parseServiceDataForWoSensorTHPlus(buf, onlog) {
|
|
388
|
+
if (buf.length !== 6) {
|
|
389
|
+
if (onlog && typeof onlog === 'function') {
|
|
390
|
+
onlog(`[_parseServiceDataForWoSensorTHPlus] Buffer length ${buf.length} !== 6!`);
|
|
391
|
+
}
|
|
392
|
+
return null;
|
|
393
|
+
}
|
|
394
|
+
let byte2 = buf.readUInt8(2);
|
|
395
|
+
let byte3 = buf.readUInt8(3);
|
|
396
|
+
let byte4 = buf.readUInt8(4);
|
|
397
|
+
let byte5 = buf.readUInt8(5);
|
|
398
|
+
|
|
399
|
+
let temp_sign = (byte4 & 0b10000000) ? 1 : -1;
|
|
400
|
+
let temp_c = temp_sign * ((byte4 & 0b01111111) + (byte3 / 10));
|
|
401
|
+
let temp_f = (temp_c * 9 / 5) + 32;
|
|
402
|
+
temp_f = Math.round(temp_f * 10) / 10;
|
|
403
|
+
|
|
404
|
+
let data = {
|
|
405
|
+
model: 'i',
|
|
406
|
+
modelName: 'WoSensorTHPlus',
|
|
407
|
+
temperature: {
|
|
408
|
+
c: temp_c,
|
|
409
|
+
f: temp_f
|
|
410
|
+
},
|
|
411
|
+
fahrenheit: (byte5 & 0b10000000) ? true : false,
|
|
412
|
+
humidity: byte5 & 0b01111111,
|
|
413
|
+
battery: (byte2 & 0b01111111)
|
|
414
|
+
};
|
|
415
|
+
|
|
416
|
+
return data;
|
|
417
|
+
}
|
|
418
|
+
|
|
419
|
+
_parseServiceDataForWoLEDStripLight(buf, onlog) {
|
|
420
|
+
if (buf.length !== 6) {
|
|
421
|
+
if (onlog && typeof onlog === 'function') {
|
|
422
|
+
onlog(`[_parseServiceDataForWoLEDStripLight] Buffer length ${buf.length} !== 6!`);
|
|
423
|
+
}
|
|
424
|
+
return null;
|
|
425
|
+
}
|
|
426
|
+
let byte1 = buf.readUInt8(1);
|
|
427
|
+
let byte2 = buf.readUInt8(2);
|
|
428
|
+
// let byte3 = buf.readUInt8(3);
|
|
429
|
+
// let byte4 = buf.readUInt8(4);
|
|
430
|
+
let byte5 = buf.readUInt8(5);
|
|
431
|
+
|
|
432
|
+
let data = {
|
|
433
|
+
model: 'r',
|
|
434
|
+
modelName: 'WoLEDStripLight',
|
|
435
|
+
};
|
|
436
|
+
|
|
437
|
+
return data;
|
|
438
|
+
}
|
|
306
439
|
}
|
|
307
440
|
|
|
308
441
|
module.exports = new SwitchbotAdvertising();
|
package/lib/switchbot.js
CHANGED
|
@@ -51,13 +51,18 @@ class Switchbot {
|
|
|
51
51
|
* - duration | Integer | Optional | Duration for discovery process (msec).
|
|
52
52
|
* | | | The value must be in the range of 1 to 60000.
|
|
53
53
|
* | | | The default value is 5000 (msec).
|
|
54
|
-
* - model | String | Optional | "H", "T", "e", "s", "d", or "
|
|
54
|
+
* - model | String | Optional | "H", "T", "e", "s", "d", "c", "u", "g", "o", "i", or "r".
|
|
55
55
|
* | | | If "H" is specified, this method will discover only Bots.
|
|
56
56
|
* | | | If "T" is specified, this method will discover only Meters.
|
|
57
57
|
* | | | If "e" is specified, this method will discover only Humidifiers.
|
|
58
58
|
* | | | If "s" is specified, this method will discover only Motion Sensors.
|
|
59
59
|
* | | | If "d" is specified, this method will discover only Contact Sensors.
|
|
60
60
|
* | | | If "c" is specified, this method will discover only Curtains.
|
|
61
|
+
* | | | If "u" is specified, this method will discover only Color Bulbs.
|
|
62
|
+
* | | | If "g" is specified, this method will discover only Plugs.
|
|
63
|
+
* | | | If "o" is specified, this method will discover only Locks.
|
|
64
|
+
* | | | If "i" is specified, this method will discover only Meter Pluses.
|
|
65
|
+
* | | | If "r" is specified, this method will discover only Locks.
|
|
61
66
|
* - id | String | Optional | If this value is set, this method will discover
|
|
62
67
|
* | | | only a device whose ID is as same as this value.
|
|
63
68
|
* | | | The ID is identical to the MAC address.
|
|
@@ -79,7 +84,7 @@ class Switchbot {
|
|
|
79
84
|
// Check the parameters
|
|
80
85
|
let valid = parameterChecker.check(params, {
|
|
81
86
|
duration: { required: false, type: 'integer', min: 1, max: 60000 },
|
|
82
|
-
model: { required: false, type: 'string', enum: ['H', 'T', 'e', 's', 'd', 'c'] },
|
|
87
|
+
model: { required: false, type: 'string', enum: ['H', 'T', 'e', 's', 'd', 'c', 'u', 'g', 'o', 'i', 'r'] },
|
|
83
88
|
id: { required: false, type: 'string', min: 12, max: 17 },
|
|
84
89
|
quick: { required: false, type: 'boolean' }
|
|
85
90
|
}, false);
|
|
@@ -186,12 +191,12 @@ class Switchbot {
|
|
|
186
191
|
case 'H':
|
|
187
192
|
device = new SwitchbotDeviceWoHand(peripheral, this.noble);
|
|
188
193
|
break;
|
|
189
|
-
case 'e':
|
|
190
|
-
device = new SwitchbotDeviceWoHumi(peripheral, this.noble);
|
|
191
|
-
break;
|
|
192
194
|
case 'T':
|
|
193
195
|
device = new SwitchbotDeviceWoSensorTH(peripheral, this.noble);
|
|
194
196
|
break;
|
|
197
|
+
case 'e':
|
|
198
|
+
device = new SwitchbotDeviceWoHumi(peripheral, this.noble);
|
|
199
|
+
break;
|
|
195
200
|
case 's':
|
|
196
201
|
device = new SwitchbotDeviceWoPresence(peripheral, this.noble);
|
|
197
202
|
break;
|
|
@@ -201,6 +206,21 @@ class Switchbot {
|
|
|
201
206
|
case 'c':
|
|
202
207
|
device = new SwitchbotDeviceWoCurtain(peripheral, this.noble);
|
|
203
208
|
break;
|
|
209
|
+
case 'u':
|
|
210
|
+
device = new SwitchbotDeviceWoColorBulb(peripheral, this.noble);
|
|
211
|
+
break;
|
|
212
|
+
case 'g':
|
|
213
|
+
device = new SwitchbotDeviceWoPlugMini(peripheral, this.noble);
|
|
214
|
+
break;
|
|
215
|
+
case 'o':
|
|
216
|
+
device = new SwitchbotDeviceWoSmartLock(peripheral, this.noble);
|
|
217
|
+
break;
|
|
218
|
+
case 'i':
|
|
219
|
+
device = new SwitchbotDeviceWoSensorTHPlus(peripheral, this.noble);
|
|
220
|
+
break;
|
|
221
|
+
case 'r':
|
|
222
|
+
device = new SwitchbotDeviceWoLEDStripLight(peripheral, this.noble);
|
|
223
|
+
break;
|
|
204
224
|
default: // 'resetting', 'unknown'
|
|
205
225
|
device = new SwitchbotDevice(peripheral, this.noble);
|
|
206
226
|
}
|
|
@@ -235,7 +255,7 @@ class Switchbot {
|
|
|
235
255
|
*
|
|
236
256
|
* [Arguments]
|
|
237
257
|
* - params | Object | Optional |
|
|
238
|
-
* - model | String | Optional | "H", "T", "e", "s", "d", or "
|
|
258
|
+
* - model | String | Optional | "H", "T", "e", "s", "d", "c", "u", "g", "o", "i", or "r".
|
|
239
259
|
* | | | If "H" is specified, the `onadvertisement`
|
|
240
260
|
* | | | event handler will be called only when advertising
|
|
241
261
|
* | | | packets comes from Bots.
|
|
@@ -254,6 +274,21 @@ class Switchbot {
|
|
|
254
274
|
* | | | If "c" is specified, the `onadvertisement`
|
|
255
275
|
* | | | event handler will be called only when advertising
|
|
256
276
|
* | | | packets comes from Curtains.
|
|
277
|
+
* | | | If "u" is specified, the `onadvertisement`
|
|
278
|
+
* | | | event handler will be called only when advertising
|
|
279
|
+
* | | | packets comes from Color Bulb.
|
|
280
|
+
* | | | If "g" is specified, the `onadvertisement`
|
|
281
|
+
* | | | event handler will be called only when advertising
|
|
282
|
+
* | | | packets comes from Plug Mini.
|
|
283
|
+
* | | | If "o" is specified, the `onadvertisement`
|
|
284
|
+
* | | | event handler will be called only when advertising
|
|
285
|
+
* | | | packets comes from Smart Lock.
|
|
286
|
+
* | | | If "i" is specified, the `onadvertisement`
|
|
287
|
+
* | | | event handler will be called only when advertising
|
|
288
|
+
* | | | packets comes from Meter Plus.
|
|
289
|
+
* | | | If "r" is specified, the `onadvertisement`
|
|
290
|
+
* | | | event handler will be called only when advertising
|
|
291
|
+
* | | | packets comes from LED Strip Light.
|
|
257
292
|
* - id | String | Optional | If this value is set, the `onadvertisement`
|
|
258
293
|
* | | | event handler will be called only when advertising
|
|
259
294
|
* | | | packets comes from devices whose ID is as same as
|
|
@@ -270,7 +305,7 @@ class Switchbot {
|
|
|
270
305
|
let promise = new Promise((resolve, reject) => {
|
|
271
306
|
// Check the parameters
|
|
272
307
|
let valid = parameterChecker.check(params, {
|
|
273
|
-
model: { required: false, type: 'string', enum: ['H', 'T', 'e', 's', 'd', 'c'] },
|
|
308
|
+
model: { required: false, type: 'string', enum: ['H', 'T', 'e', 's', 'd', 'c', 'u', 'g', 'o', 'i', 'r'] },
|
|
274
309
|
id: { required: false, type: 'string', min: 12, max: 17 },
|
|
275
310
|
}, false);
|
|
276
311
|
|
package/package.json
CHANGED
|
@@ -1,42 +1,42 @@
|
|
|
1
1
|
{
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
2
|
+
"name": "node-switchbot",
|
|
3
|
+
"version": "1.2.1-beta.2",
|
|
4
|
+
"description": "The node-switchbot is a Node.js module which allows you to move your Switchbot (Bot)'s arm and Switchbot Curtain(Curtain), also monitor the temperature/humidity from SwitchBot Thermometer & Hygrometer (Meter).",
|
|
5
|
+
"main": "./lib/switchbot.js",
|
|
6
|
+
"files": [
|
|
7
|
+
"lib"
|
|
8
|
+
],
|
|
9
|
+
"directories": {
|
|
10
|
+
"lib": "./lib"
|
|
11
|
+
},
|
|
12
|
+
"scripts": {
|
|
13
|
+
"check": "npm install && npm outdated",
|
|
14
|
+
"update": "ncu -u && npm update && npm install"
|
|
15
|
+
},
|
|
16
|
+
"keywords": [
|
|
17
|
+
"switchbot",
|
|
18
|
+
"bot",
|
|
19
|
+
"meter",
|
|
20
|
+
"temperature",
|
|
21
|
+
"humidity",
|
|
22
|
+
"curtain",
|
|
23
|
+
"BLE",
|
|
24
|
+
"Bluetooth Low Energy",
|
|
25
|
+
"Bluetooth smart",
|
|
26
|
+
"Bluetooth"
|
|
27
|
+
],
|
|
28
|
+
"homepage": "https://github.com/OpenWonderLabs",
|
|
29
|
+
"author": "OpenWonderLabs (https://github.com/OpenWonderLabs)",
|
|
30
|
+
"license": "MIT",
|
|
31
|
+
"repository": {
|
|
32
|
+
"type": "git",
|
|
33
|
+
"url": "https://github.com/OpenWonderLabs/node-switchbot.git"
|
|
34
|
+
},
|
|
35
|
+
"readmeFilename": "README.md",
|
|
36
|
+
"dependencies": {
|
|
37
|
+
"@abandonware/noble": "^1.9.2-15"
|
|
38
|
+
},
|
|
39
|
+
"devDependencies": {
|
|
40
|
+
"npm-check-updates": "^12.5.2"
|
|
41
|
+
}
|
|
42
42
|
}
|