node-switchbot 1.6.0-beta.0 → 1.6.0-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.
@@ -198,8 +198,8 @@ class SwitchbotAdvertising {
198
198
  let byte5 = buf.readUInt8(5);
199
199
 
200
200
  let temp_sign = byte4 & 0b10000000 ? 1 : -1;
201
- let temp_c = temp_sign * ((byte4 & 0b01111111) + byte3 / 10);
202
- let temp_f = (temp_c * 9) / 5 + 32;
201
+ let temp_c = temp_sign * ((byte4 & 0b01111111) + (byte3 & 0b00001111) / 10);
202
+ let temp_f = (temp_c * 9 / 5) + 32;
203
203
  temp_f = Math.round(temp_f * 10) / 10;
204
204
 
205
205
  let data = {
@@ -256,23 +256,35 @@ class SwitchbotAdvertising {
256
256
  }
257
257
  return null;
258
258
  }
259
+
260
+
259
261
  let byte1 = buf.readUInt8(1);
260
262
  let byte2 = buf.readUInt8(2);
261
- // let byte3 = buf.readUInt8(3);
262
- // let byte4 = buf.readUInt8(4);
263
+ //let byte3 = buf.readUInt8(3);
264
+ //let byte4 = buf.readUInt8(4);
263
265
  let byte5 = buf.readUInt8(5);
264
266
 
265
- let pirState = byte1 & 0b01000000 ? true : false; // 1 - Movement detected
266
- let battery = byte2 & 0b01111111; // %
267
- let lightLevel = byte5 & 0b00000011;
267
+
268
+ let tested = byte1 & 0b10000000 ? true : false;
269
+ let movement = byte1 & 0b01000000 ? true : false;
270
+ let battery = byte2 & 0b01111111;
271
+ let led = (byte5 & 0b00100000) >> 5;
272
+ let iot = (byte5 & 0b00010000) >> 4;
273
+ let sense_distance = (byte5 & 0b00001100) >> 2;
274
+ let light_intensity = byte5 & 0b00000011;
275
+ let is_light = byte5 & 0b00000010 ? true : false;
268
276
 
269
277
  let data = {
270
278
  model: "s",
271
279
  modelName: "WoMotion",
272
- movement: pirState,
280
+ tested: tested,
281
+ movement: movement,
273
282
  battery: battery,
274
- lightLevel:
275
- lightLevel == 1 ? "dark" : lightLevel == 2 ? "bright" : "unknown",
283
+ led: led,
284
+ iot: iot,
285
+ sense_distance: sense_distance,
286
+ light_intensity: light_intensity,
287
+ is_light: is_light,
276
288
  };
277
289
 
278
290
  return data;
@@ -295,25 +307,28 @@ class SwitchbotAdvertising {
295
307
  // let byte5 = buf.readUInt8(5);
296
308
  // let byte6 = buf.readUInt8(6);
297
309
  // let byte7 = buf.readUInt8(7);
298
- // let byte8 = buf.readUInt8(8);
310
+ let byte8 = buf.readUInt8(8);
299
311
 
300
- let pirState = byte1 & 0b01000000 ? true : false; // 1 - Movement detected
301
- let battery = byte2 & 0b01111111; // %
302
312
  let hallState = (byte3 >> 1) & 0b00000011;
303
- let lightLevel = byte3 & 0b00000001;
313
+ let tested = byte1 & 0b10000000;
314
+ let movement = byte1 & 0b01000000 ? true : false; // 1 - Movement detected
315
+ let battery = byte2 & 0b01111111; // %
316
+ let contact_open = byte3 & 0b00000010 == 0b00000010;
317
+ let contact_timeout = byte3 & 0b00000100 == 0b00000100;
318
+ let is_light = byte3 & 0b00000001 ? true : false;
319
+ let button_count = (data[8] & 0b00001111);
304
320
 
305
321
  let data = {
306
322
  model: "d",
307
323
  modelName: "WoContact",
308
- movement: pirState,
324
+ movement: movement,
325
+ tested: tested,
309
326
  battery: battery,
310
- doorState:
311
- hallState == 0
312
- ? "close"
313
- : hallState == 1
314
- ? "open"
315
- : "timeout no closed",
316
- lightLevel: lightLevel == 0 ? "dark" : "bright",
327
+ contact_open: contact_open,
328
+ contact_timeout: contact_timeout,
329
+ is_light: is_light,
330
+ button_count: button_count,
331
+ hallState: hallState,
317
332
  };
318
333
 
319
334
  return data;
@@ -332,20 +347,23 @@ class SwitchbotAdvertising {
332
347
  let byte2 = buf.readUInt8(2);
333
348
  let byte3 = buf.readUInt8(3);
334
349
  let byte4 = buf.readUInt8(4);
335
- // let byte5 = buf.readUInt8(5);
336
350
 
337
351
  let calibration = byte1 & 0b01000000 ? true : false; // Whether the calibration is completed
338
352
  let battery = byte2 & 0b01111111; // %
339
- let currPosition = byte3 & 0b01111111; // current positon %
353
+ let inMotion = byte3 & 0b10000000 ? true : false;
354
+ let currPosition = max(min(data[3] & 0b01111111, 100), 0) //byte3 & 0b01111111; // current positon %
340
355
  let lightLevel = (byte4 >> 4) & 0b00001111; // light sensor level (1-10)
356
+ let deviceChain = byte4 & 0b00000111;
341
357
 
342
358
  let data = {
343
359
  model: "c",
344
360
  modelName: "WoCurtain",
345
361
  calibration: calibration,
346
362
  battery: battery,
363
+ inMotion: inMotion,
347
364
  position: currPosition,
348
365
  lightLevel: lightLevel,
366
+ deviceChain: deviceChain,
349
367
  };
350
368
 
351
369
  return data;
@@ -360,40 +378,35 @@ class SwitchbotAdvertising {
360
378
  }
361
379
  return null;
362
380
  }
363
- const byte9 = buf.readUInt8(9); // byte9: color bulb state; 0x00=off, 0x80=on & lightLevel: 1~100%
364
- //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
365
- //const byte11 = buf.readUInt8(11); // byte11: wifi rssi
366
- //const byte12 = buf.readUInt8(12); // byte12: bit7: overload?
367
- //const byte13 = buf.readUInt8(13); // byte12[bit0~6] + byte13: current power value
368
-
369
- const state = byte9 === 0x01 ? "off" : byte9 === 0x80 ? "on" : null;
370
- const lightLevel = byte9 & 0b00000011;
371
- //const delay = !!(byte10 & 0b00000001);
372
- //const networkStatus = !!(byte10 & 0b00000001);
373
- //const statePreset = !!(byte10 & 0b00000010);
374
- //const lightState = !!(byte10 & 0b00000100);
375
- //const wifiRssi = byte11;
376
- //const dynamicRate = !!(byte12 & 0b10000000);
377
- //const loopIndex = (((byte12 & 0b01111111) << 8) + byte13) / 10; // in watt
381
+
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);
387
+
388
+
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;
378
397
 
379
398
  const data = {
380
399
  model: "u",
381
400
  modelName: "WoBulb",
401
+ sequence_number: sequence_number,
382
402
  state: state,
383
- };
384
- /* const data = {
385
- model: "u",
386
- modelName: "WoBulb",
387
- state: state,
388
- lightLevel: lightLevel,
403
+ brightness: brightness,
389
404
  delay: delay,
390
- networkStatus: networkStatus,
391
- statePreset: statePreset,
392
- lightState: lightState,
393
- wifiRssi: wifiRssi,
394
- dynamicRate: dynamicRate,
395
- loopIndex: loopIndex,
396
- };*/
405
+ preset: preset,
406
+ color_mode: color_mode,
407
+ speed: speed,
408
+ loop_index: loop_index,
409
+ };
397
410
 
398
411
  return data;
399
412
  }
@@ -491,14 +504,14 @@ class SwitchbotAdvertising {
491
504
  // let byte4 = buf.readUInt8(4);
492
505
  let byte5 = buf.readUInt8(5);
493
506
 
494
- //let pirState = (byte1 & 0b01000000) ? true : false; // 1 - Movement detected
507
+ //let movement = (byte1 & 0b01000000) ? true : false; // 1 - Movement detected
495
508
  let battery = byte2 & 0b01111111; // %
496
509
  //let lightLevel = byte5 & 0b00000011;
497
510
 
498
511
  let data = {
499
512
  model: "o",
500
513
  modelName: "WoSmartLock",
501
- //movement: pirState,
514
+ //movement: movement,
502
515
  battery: battery,
503
516
  //lightLevel: (lightLevel == 1) ? 'dark' : ((lightLevel == 2) ? 'bright' : 'unknown'),
504
517
  };
@@ -521,8 +534,8 @@ class SwitchbotAdvertising {
521
534
  let byte5 = buf.readUInt8(5);
522
535
 
523
536
  let temp_sign = byte4 & 0b10000000 ? 1 : -1;
524
- let temp_c = temp_sign * ((byte4 & 0b01111111) + byte3 / 10);
525
- let temp_f = (temp_c * 9) / 5 + 32;
537
+ let temp_c = temp_sign * ((byte4 & 0b01111111) + (byte3 & 0b00001111) / 10);
538
+ let temp_f = (temp_c * 9 / 5) + 32;
526
539
  temp_f = Math.round(temp_f * 10) / 10;
527
540
 
528
541
  let data = {
@@ -555,8 +568,8 @@ class SwitchbotAdvertising {
555
568
  const byte9 = buf.readUInt8(9);
556
569
  const byte10 = buf.readUInt8(10);
557
570
 
558
- const isOn = byte7 & 0b10000000;
559
- const brightness = byte7 & 0b01111111;
571
+ const state = byte7 & 0b10000000 ? true : false;
572
+ const lightLevel = byte7 & 0b01111111;
560
573
  const delay = byte8 & 0b10000000;
561
574
  const preset = byte8 & 0b00001000;
562
575
  const color_mode = byte8 & 0b00000111;
@@ -566,8 +579,8 @@ class SwitchbotAdvertising {
566
579
  const data = {
567
580
  model: "r",
568
581
  modelName: "WoStrip",
569
- isOn: isOn,
570
- brightness: brightness,
582
+ state: state,
583
+ lightLevel: lightLevel,
571
584
  delay: delay,
572
585
  preset: preset,
573
586
  color_mode: color_mode,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "node-switchbot",
3
- "version": "1.6.0-beta.0",
3
+ "version": "1.6.0-beta.2",
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": [
@@ -37,6 +37,6 @@
37
37
  "@abandonware/noble": "^1.9.2-15"
38
38
  },
39
39
  "devDependencies": {
40
- "npm-check-updates": "^16.3.8"
40
+ "npm-check-updates": "^16.3.13"
41
41
  }
42
42
  }