Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,14 @@

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

## [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**: https://github.com/OpenWonderLabs/node-switchbot/compare/v1.6.1...v1.7.0

## [Version 1.6.1](https://github.com/OpenWonderLabs/node-switchbot/releases/tag/v1.6.1) (2022-10-18)

## What's Changed
Expand Down
100 changes: 63 additions & 37 deletions lib/switchbot-advertising.js
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ class SwitchbotAdvertising {
} else if (model === "j") {
sd = this._parseServiceDataForWoPlugMiniJP(manufacturerData, onlog);// WoPlugMini (JP)
} else if (model === "o") {
sd = this._parseServiceDataForWoSmartLock(buf, onlog);// WoSmartLock
sd = this._parseServiceDataForWoSmartLock(manufacturerData, onlog);// WoSmartLock
} else if (model === "i") {
sd = this._parseServiceDataForWoSensorTHPlus(buf, onlog);// WoMeterPlus
} else if (model === "r") {
Expand Down Expand Up @@ -365,25 +365,25 @@ class SwitchbotAdvertising {
return data;
}

_parseServiceDataForWoBulb(buf, onlog) {
if (buf.length !== 13) {
_parseServiceDataForWoBulb(manufacturerData, onlog) {
if (manufacturerData.length !== 13) {
if (onlog && typeof onlog === "function") {
onlog(
`[_parseServiceDataForWoBulb] Buffer length ${buf.length} !== 13!`
`[_parseServiceDataForWoBulb] Buffer length ${manufacturerData.length} !== 13!`
);
}
return null;
}
let byte1 = buf.readUInt8(1);//power and light status
let byte2 = buf.readUInt8(2);//bulb brightness
let byte3 = buf.readUInt8(3);//bulb R
let byte4 = buf.readUInt8(4);//bulb G
let byte5 = buf.readUInt8(5);//bulb B
let byte6 = buf.readUInt8(6);//bulb temperature
let byte7 = buf.readUInt8(7);
let byte8 = buf.readUInt8(8);
let byte9 = buf.readUInt8(9);
let byte10 = buf.readUInt8(10);//bulb mode
let byte1 = manufacturerData.readUInt8(1);//power and light status
let byte2 = manufacturerData.readUInt8(2);//bulb brightness
let byte3 = manufacturerData.readUInt8(3);//bulb R
let byte4 = manufacturerData.readUInt8(4);//bulb G
let byte5 = manufacturerData.readUInt8(5);//bulb B
let byte6 = manufacturerData.readUInt8(6);//bulb temperature
let byte7 = manufacturerData.readUInt8(7);
let byte8 = manufacturerData.readUInt8(8);
let byte9 = manufacturerData.readUInt8(9);
let byte10 = manufacturerData.readUInt8(10);//bulb mode

let power = byte1;
let red = byte3;
Expand Down Expand Up @@ -418,20 +418,20 @@ class SwitchbotAdvertising {
return data;
}

_parseServiceDataForWoPlugMiniUS(buf, onlog) {
if (buf.length !== 14) {
_parseServiceDataForWoPlugMiniUS(manufacturerData, onlog) {
if (manufacturerData.length !== 14) {
if (onlog && typeof onlog === "function") {
onlog(
`[_parseServiceDataForWoPlugMiniUS] Buffer length ${buf.length} should be 14`
`[_parseServiceDataForWoPlugMiniUS] Buffer length ${manufacturerData.length} should be 14`
);
}
return null;
}
let byte9 = buf.readUInt8(9); // byte9: plug mini state; 0x00=off, 0x80=on
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
let byte11 = buf.readUInt8(11); // byte11: wifi rssi
let byte12 = buf.readUInt8(12); // byte12: bit7: overload?
let byte13 = buf.readUInt8(13); // byte12[bit0~6] + byte13: current power value
let byte9 = manufacturerData.readUInt8(9); // byte9: plug mini state; 0x00=off, 0x80=on
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
let byte11 = manufacturerData.readUInt8(11); // byte11: wifi rssi
let byte12 = manufacturerData.readUInt8(12); // byte12: bit7: overload?
let byte13 = manufacturerData.readUInt8(13); // byte12[bit0~6] + byte13: current power value

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

_parseServiceDataForWoPlugMiniJP(buf, onlog) {
if (buf.length !== 14) {
_parseServiceDataForWoPlugMiniJP(manufacturerData, onlog) {
if (manufacturerData.length !== 14) {
if (onlog && typeof onlog === "function") {
onlog(
`[_parseServiceDataForWoPlugMiniJP] Buffer length ${buf.length} should be 14`
`[_parseServiceDataForWoPlugMiniJP] Buffer length ${manufacturerData.length} should be 14`
);
}
return null;
}
let byte9 = buf.readUInt8(9); // byte9: plug mini state; 0x00=off, 0x80=on
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
let byte11 = buf.readUInt8(11); // byte11: wifi rssi
let byte12 = buf.readUInt8(12); // byte12: bit7: overload?
let byte13 = buf.readUInt8(13); // byte12[bit0~6] + byte13: current power value
let byte9 = manufacturerData.readUInt8(9); // byte9: plug mini state; 0x00=off, 0x80=on
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
let byte11 = manufacturerData.readUInt8(11); // byte11: wifi rssi
let byte12 = manufacturerData.readUInt8(12); // byte12: bit7: overload?
let byte13 = manufacturerData.readUInt8(13); // byte12[bit0~6] + byte13: current power value

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

_parseServiceDataForWoSmartLock(buf, onlog) {
if (buf.length !== 6) {
_parseServiceDataForWoSmartLock(manufacturerData, onlog) {
if (manufacturerData.length !== 6) {
if (onlog && typeof onlog === "function") {
onlog(
`[_parseServiceDataForWoSmartLock] Buffer length ${buf.length} !== 6!`
`[_parseServiceDataForWoSmartLock] Buffer length ${manufacturerData.length} !== 6!`
);
}
return null;
}
let byte1 = buf.readUInt8(1);
let byte2 = buf.readUInt8(2);
let byte2 = manufacturerData.readUInt8(2);
let byte7 = manufacturerData.readUInt8(7);
let byte8 = manufacturerData.readUInt8(8);


let LockStatus = {
LOCKED: 0b0000000,
UNLOCKED: 0b0010000,
LOCKING: 0b0100000,
UNLOCKING: 0b0110000,
LOCKING_STOP: 0b1000000,
UNLOCKING_STOP: 0b1010000,
NOT_FULLY_LOCKED: 0b1100000, //Only EU lock type
}

let movement = (byte1 & 0b01000000) ? true : false; // 1 - Movement detected
let battery = byte2 & 0b01111111; // %
let calibration = byte7 & 0b10000000 ? true : false;
let status = LockStatus(byte7 & 0b01110000);
let update_from_secondary_lock = byte7 & 0b00001000 ? true : false;
let door_open = byte7 & 0b00000100 ? true : false;
let double_lock_mode = byte8 & 0b10000000 ? true : false;
let unclosed_alarm = byte8 & 0b00100000 ? true : false;
let unlocked_alarm = byte8 & 0b00010000 ? true : false;
let auto_lock_paused = byte8 & 0b00000010 ? true : false;

let data = {
model: "o",
modelName: "WoSmartLock",
battery: battery,
movement: movement,
calibration: calibration,
status: status,
update_from_secondary_lock: update_from_secondary_lock,
door_open: door_open,
double_lock_mode: double_lock_mode,
unclosed_alarm: unclosed_alarm,
unlocked_alarm: unlocked_alarm,
auto_lock_paused: auto_lock_paused,
};

return data;
Expand Down
Loading