node-switchbot 1.6.0-beta.2 → 1.6.0-beta.4

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.
@@ -227,10 +227,8 @@ class SwitchbotAdvertising {
227
227
  return null;
228
228
  }
229
229
  let byte1 = buf.readUInt8(1);
230
- // let byte2 = buf.readUInt8(2);
231
- let byte3 = buf.readUInt8(3);
232
230
  let byte4 = buf.readUInt8(4);
233
- let byte5 = buf.readUInt8(5);
231
+
234
232
 
235
233
  let onState = byte1 & 0b10000000 ? true : false; // 1 - on
236
234
  let autoMode = byte4 & 0b10000000 ? true : false; // 1 - auto
@@ -260,8 +258,6 @@ class SwitchbotAdvertising {
260
258
 
261
259
  let byte1 = buf.readUInt8(1);
262
260
  let byte2 = buf.readUInt8(2);
263
- //let byte3 = buf.readUInt8(3);
264
- //let byte4 = buf.readUInt8(4);
265
261
  let byte5 = buf.readUInt8(5);
266
262
 
267
263
 
@@ -303,10 +299,6 @@ class SwitchbotAdvertising {
303
299
  let byte1 = buf.readUInt8(1);
304
300
  let byte2 = buf.readUInt8(2);
305
301
  let byte3 = buf.readUInt8(3);
306
- // let byte4 = buf.readUInt8(4);
307
- // let byte5 = buf.readUInt8(5);
308
- // let byte6 = buf.readUInt8(6);
309
- // let byte7 = buf.readUInt8(7);
310
302
  let byte8 = buf.readUInt8(8);
311
303
 
312
304
  let hallState = (byte3 >> 1) & 0b00000011;
@@ -316,7 +308,7 @@ class SwitchbotAdvertising {
316
308
  let contact_open = byte3 & 0b00000010 == 0b00000010;
317
309
  let contact_timeout = byte3 & 0b00000100 == 0b00000100;
318
310
  let is_light = byte3 & 0b00000001 ? true : false;
319
- let button_count = (data[8] & 0b00001111);
311
+ let button_count = byte8 & 0b00001111;
320
312
 
321
313
  let data = {
322
314
  model: "d",
@@ -351,7 +343,7 @@ class SwitchbotAdvertising {
351
343
  let calibration = byte1 & 0b01000000 ? true : false; // Whether the calibration is completed
352
344
  let battery = byte2 & 0b01111111; // %
353
345
  let inMotion = byte3 & 0b10000000 ? true : false;
354
- let currPosition = max(min(data[3] & 0b01111111, 100), 0) //byte3 & 0b01111111; // current positon %
346
+ let currPosition = max(min(byte3 & 0b01111111, 100), 0) //byte3 & 0b01111111; // current positon %
355
347
  let lightLevel = (byte4 >> 4) & 0b00001111; // light sensor level (1-10)
356
348
  let deviceChain = byte4 & 0b00000111;
357
349
 
@@ -379,23 +371,23 @@ class SwitchbotAdvertising {
379
371
  return null;
380
372
  }
381
373
 
382
- const byte6 = buf.readUInt8(6);
383
- const byte7 = buf.readUInt8(7);
384
- const byte8 = buf.readUInt8(8);
385
- const byte9 = buf.readUInt8(9);
386
- const byte10 = buf.readUInt8(10);
374
+ let byte6 = buf.readUInt8(6);
375
+ let byte7 = buf.readUInt8(7);
376
+ let byte8 = buf.readUInt8(8);
377
+ let byte9 = buf.readUInt8(9);
378
+ let byte10 = buf.readUInt8(10);
387
379
 
388
380
 
389
- const sequence_number = byte6;
390
- const state = byte7 & 0b01111111 ? true : false;
391
- const brightness = byte7 & 0b01111111;
392
- const delay = byte8 & 0b10000000;
393
- const preset = byte8 & 0b00001000;
394
- const color_mode = byte8 & 0b00000111;
395
- const speed = byte9 & 0b01111111;
396
- const loop_index = byte10 & 0b11111110;
381
+ let sequence_number = byte6;
382
+ let state = byte7 & 0b01111111 ? true : false;
383
+ let brightness = byte7 & 0b01111111;
384
+ let delay = byte8 & 0b10000000;
385
+ let preset = byte8 & 0b00001000;
386
+ let color_mode = byte8 & 0b00000111;
387
+ let speed = byte9 & 0b01111111;
388
+ let loop_index = byte10 & 0b11111110;
397
389
 
398
- const data = {
390
+ let data = {
399
391
  model: "u",
400
392
  modelName: "WoBulb",
401
393
  sequence_number: sequence_number,
@@ -420,22 +412,22 @@ class SwitchbotAdvertising {
420
412
  }
421
413
  return null;
422
414
  }
423
- const byte9 = buf.readUInt8(9); // byte9: plug mini state; 0x00=off, 0x80=on
424
- const byte10 = buf.readUInt8(10); // byte10: bit0: 0=no delay,1=delay, bit1:0=no timer, 1=timer; bit2:0=no sync time, 1=sync'ed time
425
- const byte11 = buf.readUInt8(11); // byte11: wifi rssi
426
- const byte12 = buf.readUInt8(12); // byte12: bit7: overload?
427
- const byte13 = buf.readUInt8(13); // byte12[bit0~6] + byte13: current power value
428
-
429
- const state = byte9 === 0x00 ? "off" : byte9 === 0x80 ? "on" : null;
430
- const delay = !!(byte10 & 0b00000001);
431
- const timer = !!(byte10 & 0b00000010);
432
- const syncUtcTime = !!(byte10 & 0b00000100);
433
- const wifiRssi = byte11;
434
- const overload = !!(byte12 & 0b10000000);
435
- const currentPower = (((byte12 & 0b01111111) << 8) + byte13) / 10; // in watt
415
+ let byte9 = buf.readUInt8(9); // byte9: plug mini state; 0x00=off, 0x80=on
416
+ let byte10 = buf.readUInt8(10); // byte10: bit0: 0=no delay,1=delay, bit1:0=no timer, 1=timer; bit2:0=no sync time, 1=sync'ed time
417
+ let byte11 = buf.readUInt8(11); // byte11: wifi rssi
418
+ let byte12 = buf.readUInt8(12); // byte12: bit7: overload?
419
+ let byte13 = buf.readUInt8(13); // byte12[bit0~6] + byte13: current power value
420
+
421
+ let state = byte9 === 0x00 ? "off" : byte9 === 0x80 ? "on" : null;
422
+ let delay = !!(byte10 & 0b00000001);
423
+ let timer = !!(byte10 & 0b00000010);
424
+ let syncUtcTime = !!(byte10 & 0b00000100);
425
+ let wifiRssi = byte11;
426
+ let overload = !!(byte12 & 0b10000000);
427
+ let currentPower = (((byte12 & 0b01111111) << 8) + byte13) / 10; // in watt
436
428
  // TODO: voltage ???
437
429
 
438
- const data = {
430
+ let data = {
439
431
  model: "g",
440
432
  modelName: "WoPlugMini",
441
433
  state: state,
@@ -459,22 +451,22 @@ class SwitchbotAdvertising {
459
451
  }
460
452
  return null;
461
453
  }
462
- const byte9 = buf.readUInt8(9); // byte9: plug mini state; 0x00=off, 0x80=on
463
- const byte10 = buf.readUInt8(10); // byte10: bit0: 0=no delay,1=delay, bit1:0=no timer, 1=timer; bit2:0=no sync time, 1=sync'ed time
464
- const byte11 = buf.readUInt8(11); // byte11: wifi rssi
465
- const byte12 = buf.readUInt8(12); // byte12: bit7: overload?
466
- const byte13 = buf.readUInt8(13); // byte12[bit0~6] + byte13: current power value
467
-
468
- const state = byte9 === 0x00 ? "off" : byte9 === 0x80 ? "on" : null;
469
- const delay = !!(byte10 & 0b00000001);
470
- const timer = !!(byte10 & 0b00000010);
471
- const syncUtcTime = !!(byte10 & 0b00000100);
472
- const wifiRssi = byte11;
473
- const overload = !!(byte12 & 0b10000000);
474
- const currentPower = (((byte12 & 0b01111111) << 8) + byte13) / 10; // in watt
454
+ let byte9 = buf.readUInt8(9); // byte9: plug mini state; 0x00=off, 0x80=on
455
+ let byte10 = buf.readUInt8(10); // byte10: bit0: 0=no delay,1=delay, bit1:0=no timer, 1=timer; bit2:0=no sync time, 1=sync'ed time
456
+ let byte11 = buf.readUInt8(11); // byte11: wifi rssi
457
+ let byte12 = buf.readUInt8(12); // byte12: bit7: overload?
458
+ let byte13 = buf.readUInt8(13); // byte12[bit0~6] + byte13: current power value
459
+
460
+ let state = byte9 === 0x00 ? "off" : byte9 === 0x80 ? "on" : null;
461
+ let delay = !!(byte10 & 0b00000001);
462
+ let timer = !!(byte10 & 0b00000010);
463
+ let syncUtcTime = !!(byte10 & 0b00000100);
464
+ let wifiRssi = byte11;
465
+ let overload = !!(byte12 & 0b10000000);
466
+ let currentPower = (((byte12 & 0b01111111) << 8) + byte13) / 10; // in watt
475
467
  // TODO: voltage ???
476
468
 
477
- const data = {
469
+ let data = {
478
470
  model: "j",
479
471
  modelName: "WoPlugMini",
480
472
  state: state,
@@ -500,20 +492,15 @@ class SwitchbotAdvertising {
500
492
  }
501
493
  let byte1 = buf.readUInt8(1);
502
494
  let byte2 = buf.readUInt8(2);
503
- // let byte3 = buf.readUInt8(3);
504
- // let byte4 = buf.readUInt8(4);
505
- let byte5 = buf.readUInt8(5);
506
495
 
507
- //let movement = (byte1 & 0b01000000) ? true : false; // 1 - Movement detected
496
+ let movement = (byte1 & 0b01000000) ? true : false; // 1 - Movement detected
508
497
  let battery = byte2 & 0b01111111; // %
509
- //let lightLevel = byte5 & 0b00000011;
510
498
 
511
499
  let data = {
512
500
  model: "o",
513
501
  modelName: "WoSmartLock",
514
- //movement: movement,
515
502
  battery: battery,
516
- //lightLevel: (lightLevel == 1) ? 'dark' : ((lightLevel == 2) ? 'bright' : 'unknown'),
503
+ movement: movement,
517
504
  };
518
505
 
519
506
  return data;
@@ -563,20 +550,20 @@ class SwitchbotAdvertising {
563
550
  return null;
564
551
  }
565
552
 
566
- const byte7 = buf.readUInt8(7);
567
- const byte8 = buf.readUInt8(8);
568
- const byte9 = buf.readUInt8(9);
569
- const byte10 = buf.readUInt8(10);
553
+ let byte7 = buf.readUInt8(7);
554
+ let byte8 = buf.readUInt8(8);
555
+ let byte9 = buf.readUInt8(9);
556
+ let byte10 = buf.readUInt8(10);
570
557
 
571
- const state = byte7 & 0b10000000 ? true : false;
572
- const lightLevel = byte7 & 0b01111111;
573
- const delay = byte8 & 0b10000000;
574
- const preset = byte8 & 0b00001000;
575
- const color_mode = byte8 & 0b00000111;
576
- const speed = byte9 & 0b01111111;
577
- const loop_index = byte10 & 0b11111110;
558
+ let state = byte7 & 0b10000000 ? true : false;
559
+ let lightLevel = byte7 & 0b01111111;
560
+ let delay = byte8 & 0b10000000;
561
+ let preset = byte8 & 0b00001000;
562
+ let color_mode = byte8 & 0b00000111;
563
+ let speed = byte9 & 0b01111111;
564
+ let loop_index = byte10 & 0b11111110;
578
565
 
579
- const data = {
566
+ let data = {
580
567
  model: "r",
581
568
  modelName: "WoStrip",
582
569
  state: state,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "node-switchbot",
3
- "version": "1.6.0-beta.2",
3
+ "version": "1.6.0-beta.4",
4
4
  "description": "The node-switchbot is a Node.js module which allows you to control your Switchbot Devices through Bluetooth (BLE).",
5
5
  "main": "./lib/switchbot.js",
6
6
  "files": [