Skip to content

Commit d8a25e8

Browse files
v1.7.0 (#169)
## [Version 1.7.0](https://github.com/OpenWonderLabs/node-switchbot/releases/tag/v1.7.0) (2022-12-08) ## What's Changed - Add Read-only Support for Smart Lock. **Full Changelog**: v1.6.1...v1.7.0
1 parent c38eba8 commit d8a25e8

File tree

4 files changed

+605
-351
lines changed

4 files changed

+605
-351
lines changed

CHANGELOG.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,14 @@
22

33
All notable changes to this project will be documented in this file. This project uses [Semantic Versioning](https://semver.org/)
44

5+
## [Version 1.7.0](https://github.com/OpenWonderLabs/node-switchbot/releases/tag/v1.7.0) (2022-12-08)
6+
7+
## What's Changed
8+
9+
- Add Read-only Support for Smart Lock.
10+
11+
**Full Changelog**: https://github.com/OpenWonderLabs/node-switchbot/compare/v1.6.1...v1.7.0
12+
513
## [Version 1.6.1](https://github.com/OpenWonderLabs/node-switchbot/releases/tag/v1.6.1) (2022-10-18)
614

715
## What's Changed

lib/switchbot-advertising.js

Lines changed: 63 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ class SwitchbotAdvertising {
101101
} else if (model === "j") {
102102
sd = this._parseServiceDataForWoPlugMiniJP(manufacturerData, onlog);// WoPlugMini (JP)
103103
} else if (model === "o") {
104-
sd = this._parseServiceDataForWoSmartLock(buf, onlog);// WoSmartLock
104+
sd = this._parseServiceDataForWoSmartLock(manufacturerData, onlog);// WoSmartLock
105105
} else if (model === "i") {
106106
sd = this._parseServiceDataForWoSensorTHPlus(buf, onlog);// WoMeterPlus
107107
} else if (model === "r") {
@@ -365,25 +365,25 @@ class SwitchbotAdvertising {
365365
return data;
366366
}
367367

368-
_parseServiceDataForWoBulb(buf, onlog) {
369-
if (buf.length !== 13) {
368+
_parseServiceDataForWoBulb(manufacturerData, onlog) {
369+
if (manufacturerData.length !== 13) {
370370
if (onlog && typeof onlog === "function") {
371371
onlog(
372-
`[_parseServiceDataForWoBulb] Buffer length ${buf.length} !== 13!`
372+
`[_parseServiceDataForWoBulb] Buffer length ${manufacturerData.length} !== 13!`
373373
);
374374
}
375375
return null;
376376
}
377-
let byte1 = buf.readUInt8(1);//power and light status
378-
let byte2 = buf.readUInt8(2);//bulb brightness
379-
let byte3 = buf.readUInt8(3);//bulb R
380-
let byte4 = buf.readUInt8(4);//bulb G
381-
let byte5 = buf.readUInt8(5);//bulb B
382-
let byte6 = buf.readUInt8(6);//bulb temperature
383-
let byte7 = buf.readUInt8(7);
384-
let byte8 = buf.readUInt8(8);
385-
let byte9 = buf.readUInt8(9);
386-
let byte10 = buf.readUInt8(10);//bulb mode
377+
let byte1 = manufacturerData.readUInt8(1);//power and light status
378+
let byte2 = manufacturerData.readUInt8(2);//bulb brightness
379+
let byte3 = manufacturerData.readUInt8(3);//bulb R
380+
let byte4 = manufacturerData.readUInt8(4);//bulb G
381+
let byte5 = manufacturerData.readUInt8(5);//bulb B
382+
let byte6 = manufacturerData.readUInt8(6);//bulb temperature
383+
let byte7 = manufacturerData.readUInt8(7);
384+
let byte8 = manufacturerData.readUInt8(8);
385+
let byte9 = manufacturerData.readUInt8(9);
386+
let byte10 = manufacturerData.readUInt8(10);//bulb mode
387387

388388
let power = byte1;
389389
let red = byte3;
@@ -418,20 +418,20 @@ class SwitchbotAdvertising {
418418
return data;
419419
}
420420

421-
_parseServiceDataForWoPlugMiniUS(buf, onlog) {
422-
if (buf.length !== 14) {
421+
_parseServiceDataForWoPlugMiniUS(manufacturerData, onlog) {
422+
if (manufacturerData.length !== 14) {
423423
if (onlog && typeof onlog === "function") {
424424
onlog(
425-
`[_parseServiceDataForWoPlugMiniUS] Buffer length ${buf.length} should be 14`
425+
`[_parseServiceDataForWoPlugMiniUS] Buffer length ${manufacturerData.length} should be 14`
426426
);
427427
}
428428
return null;
429429
}
430-
let byte9 = buf.readUInt8(9); // byte9: plug mini state; 0x00=off, 0x80=on
431-
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
432-
let byte11 = buf.readUInt8(11); // byte11: wifi rssi
433-
let byte12 = buf.readUInt8(12); // byte12: bit7: overload?
434-
let byte13 = buf.readUInt8(13); // byte12[bit0~6] + byte13: current power value
430+
let byte9 = manufacturerData.readUInt8(9); // byte9: plug mini state; 0x00=off, 0x80=on
431+
let byte10 = manufacturerData.readUInt8(10); // byte10: bit0: 0=no delay,1=delay, bit1:0=no timer, 1=timer; bit2:0=no sync time, 1=sync'ed time
432+
let byte11 = manufacturerData.readUInt8(11); // byte11: wifi rssi
433+
let byte12 = manufacturerData.readUInt8(12); // byte12: bit7: overload?
434+
let byte13 = manufacturerData.readUInt8(13); // byte12[bit0~6] + byte13: current power value
435435

436436
let state = byte9 === 0x00 ? "off" : byte9 === 0x80 ? "on" : null;
437437
let delay = !!(byte10 & 0b00000001);
@@ -457,20 +457,20 @@ class SwitchbotAdvertising {
457457
return data;
458458
}
459459

460-
_parseServiceDataForWoPlugMiniJP(buf, onlog) {
461-
if (buf.length !== 14) {
460+
_parseServiceDataForWoPlugMiniJP(manufacturerData, onlog) {
461+
if (manufacturerData.length !== 14) {
462462
if (onlog && typeof onlog === "function") {
463463
onlog(
464-
`[_parseServiceDataForWoPlugMiniJP] Buffer length ${buf.length} should be 14`
464+
`[_parseServiceDataForWoPlugMiniJP] Buffer length ${manufacturerData.length} should be 14`
465465
);
466466
}
467467
return null;
468468
}
469-
let byte9 = buf.readUInt8(9); // byte9: plug mini state; 0x00=off, 0x80=on
470-
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
471-
let byte11 = buf.readUInt8(11); // byte11: wifi rssi
472-
let byte12 = buf.readUInt8(12); // byte12: bit7: overload?
473-
let byte13 = buf.readUInt8(13); // byte12[bit0~6] + byte13: current power value
469+
let byte9 = manufacturerData.readUInt8(9); // byte9: plug mini state; 0x00=off, 0x80=on
470+
let byte10 = manufacturerData.readUInt8(10); // byte10: bit0: 0=no delay,1=delay, bit1:0=no timer, 1=timer; bit2:0=no sync time, 1=sync'ed time
471+
let byte11 = manufacturerData.readUInt8(11); // byte11: wifi rssi
472+
let byte12 = manufacturerData.readUInt8(12); // byte12: bit7: overload?
473+
let byte13 = manufacturerData.readUInt8(13); // byte12[bit0~6] + byte13: current power value
474474

475475
let state = byte9 === 0x00 ? "off" : byte9 === 0x80 ? "on" : null;
476476
let delay = !!(byte10 & 0b00000001);
@@ -496,26 +496,52 @@ class SwitchbotAdvertising {
496496
return data;
497497
}
498498

499-
_parseServiceDataForWoSmartLock(buf, onlog) {
500-
if (buf.length !== 6) {
499+
_parseServiceDataForWoSmartLock(manufacturerData, onlog) {
500+
if (manufacturerData.length !== 6) {
501501
if (onlog && typeof onlog === "function") {
502502
onlog(
503-
`[_parseServiceDataForWoSmartLock] Buffer length ${buf.length} !== 6!`
503+
`[_parseServiceDataForWoSmartLock] Buffer length ${manufacturerData.length} !== 6!`
504504
);
505505
}
506506
return null;
507507
}
508-
let byte1 = buf.readUInt8(1);
509-
let byte2 = buf.readUInt8(2);
508+
let byte2 = manufacturerData.readUInt8(2);
509+
let byte7 = manufacturerData.readUInt8(7);
510+
let byte8 = manufacturerData.readUInt8(8);
511+
512+
513+
let LockStatus = {
514+
LOCKED: 0b0000000,
515+
UNLOCKED: 0b0010000,
516+
LOCKING: 0b0100000,
517+
UNLOCKING: 0b0110000,
518+
LOCKING_STOP: 0b1000000,
519+
UNLOCKING_STOP: 0b1010000,
520+
NOT_FULLY_LOCKED: 0b1100000, //Only EU lock type
521+
}
510522

511-
let movement = (byte1 & 0b01000000) ? true : false; // 1 - Movement detected
512523
let battery = byte2 & 0b01111111; // %
524+
let calibration = byte7 & 0b10000000 ? true : false;
525+
let status = LockStatus(byte7 & 0b01110000);
526+
let update_from_secondary_lock = byte7 & 0b00001000 ? true : false;
527+
let door_open = byte7 & 0b00000100 ? true : false;
528+
let double_lock_mode = byte8 & 0b10000000 ? true : false;
529+
let unclosed_alarm = byte8 & 0b00100000 ? true : false;
530+
let unlocked_alarm = byte8 & 0b00010000 ? true : false;
531+
let auto_lock_paused = byte8 & 0b00000010 ? true : false;
513532

514533
let data = {
515534
model: "o",
516535
modelName: "WoSmartLock",
517536
battery: battery,
518-
movement: movement,
537+
calibration: calibration,
538+
status: status,
539+
update_from_secondary_lock: update_from_secondary_lock,
540+
door_open: door_open,
541+
double_lock_mode: double_lock_mode,
542+
unclosed_alarm: unclosed_alarm,
543+
unlocked_alarm: unlocked_alarm,
544+
auto_lock_paused: auto_lock_paused,
519545
};
520546

521547
return data;

0 commit comments

Comments
 (0)