Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
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
17 changes: 17 additions & 0 deletions .github/workflows/dependabot.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
name: AutoDependabot

on:
pull_request:
push:
branches:
- beta

jobs:
automerge:
name: Auto-merge dependabot updates
runs-on: ubuntu-latest
steps:
- uses: mitto98/dependabot-automerge-action@master
with:
token: ${{ github.token }}
merge: true
3 changes: 0 additions & 3 deletions .github/workflows/nodejs-beta.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,8 @@ jobs:

publish-npm:
if: github.repository == 'OpenWonderLabs/node-switchbot'

needs: build

runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v3
- uses: actions/setup-node@v3
Expand Down
3 changes: 0 additions & 3 deletions .github/workflows/nodejs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,8 @@ jobs:
publish-npm:
# publish only if we are on our own repo, event was 'release' (a tag was created) and the tag starts with "v" (aka version tag)
if: github.repository == 'OpenWonderLabs/node-switchbot' && github.event_name == 'release' && startsWith(github.ref, 'refs/tags/v')

needs: build # only run if build succeeds

runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v3
- uses: actions/setup-node@v3
Expand Down
9 changes: 9 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,15 @@

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

## [Version 1.3.0](https://github.com/OpenWonderLabs/node-switchbot/releases/tag/v1.2.0) (2022-06-25)

### Changes

- Added more Device Types, not all supported though.
- Housekeeping and update dependencies

**Full Changelog**: https://github.com/OpenWonderLabs/node-switchbot/compare/v1.2.0...v1.3.0

## [Version 1.2.0](https://github.com/OpenWonderLabs/node-switchbot/releases/tag/v1.2.0) (2022-03-04)

### Changes
Expand Down
197 changes: 165 additions & 32 deletions lib/switchbot-advertising.js
Original file line number Diff line number Diff line change
Expand Up @@ -76,16 +76,26 @@ class SwitchbotAdvertising {

if (model === 'H') { // WoHand
sd = this._parseServiceDataForWoHand(buf, onlog);
} else if (model === 'e') { // WoHumi
sd = this._parseServiceDataForWoHumi(buf, onlog);
} else if (model === 'T') { // WoSensorTH
sd = this._parseServiceDataForWoSensorTH(buf, onlog);
} else if (model === 'c') { // WoCurtain
sd = this._parseServiceDataForWoCurtain(buf, onlog);
} else if (model === 'e') { // WoHumi
sd = this._parseServiceDataForWoHumi(buf, onlog);
} else if (model === 's') { // WoMotion
sd = this._parseServiceDataForWoPresence(buf, onlog);
} else if (model === 'd') { // WoContact
sd = this._parseServiceDataForWoContact(buf, onlog);
} else if (model === 'c') { // WoCurtain
sd = this._parseServiceDataForWoCurtain(buf, onlog);
} else if (model === 'u') { // WoColorBulb
sd = this._parseServiceDataForWoColorBulb(buf, onlog);
} else if (model === 'g') { // WoPlugMini
sd = this._parseServiceDataForWoPlugMini(buf, onlog);
} else if (model === 'o') { // WoSmartLock
sd = this._parseServiceDataForWoSmartLock(buf, onlog);
} else if (model === 'i') { // WoMeterPlus
sd = this._parseServiceDataForWoSensorTHPlus(buf, onlog);
} else if (model === 'r') { // WoLEDStripLight
sd = this._parseServiceDataForWoLEDStripLight(buf, onlog);
} else {
if (onlog && typeof onlog === 'function') {
onlog(`[parseAdvertising.${peripheral.id}] return null, model "${model}" not available!`);
Expand Down Expand Up @@ -152,34 +162,6 @@ class SwitchbotAdvertising {
return data;
}

_parseServiceDataForWoHumi(buf, onlog) {
if (buf.length !== 8) {
if (onlog && typeof onlog === 'function') {
onlog(`[_parseServiceDataForWoHumi] Buffer length ${buf.length} !== 8!`);
}
return null;
}
let byte1 = buf.readUInt8(1);
// let byte2 = buf.readUInt8(2);
let byte3 = buf.readUInt8(3);
let byte4 = buf.readUInt8(4);
let byte5 = buf.readUInt8(5);

let onState = (byte1 & 0b10000000) ? true : false; // 1 - on
let autoMode = (byte4 & 0b10000000) ? true : false; // 1 - auto
let percentage = byte4 & 0b01111111; // 0-100%, 101/102/103 - Quick gear 1/2/3

let data = {
model: 'e',
modelName: 'WoHumi',
onState: onState,
autoMode: autoMode,
percentage: autoMode ? 0 : percentage,
};

return data;
}

_parseServiceDataForWoSensorTH(buf, onlog) {
if (buf.length !== 6) {
if (onlog && typeof onlog === 'function') {
Expand Down Expand Up @@ -212,6 +194,34 @@ class SwitchbotAdvertising {
return data;
}

_parseServiceDataForWoHumi(buf, onlog) {
if (buf.length !== 8) {
if (onlog && typeof onlog === 'function') {
onlog(`[_parseServiceDataForWoHumi] Buffer length ${buf.length} !== 8!`);
}
return null;
}
let byte1 = buf.readUInt8(1);
// let byte2 = buf.readUInt8(2);
let byte3 = buf.readUInt8(3);
let byte4 = buf.readUInt8(4);
let byte5 = buf.readUInt8(5);

let onState = (byte1 & 0b10000000) ? true : false; // 1 - on
let autoMode = (byte4 & 0b10000000) ? true : false; // 1 - auto
let percentage = byte4 & 0b01111111; // 0-100%, 101/102/103 - Quick gear 1/2/3

let data = {
model: 'e',
modelName: 'WoHumi',
onState: onState,
autoMode: autoMode,
percentage: autoMode ? 0 : percentage,
};

return data;
}

_parseServiceDataForWoPresence(buf, onlog) {
if (buf.length !== 6) {
if (onlog && typeof onlog === 'function') {
Expand Down Expand Up @@ -303,6 +313,129 @@ class SwitchbotAdvertising {

return data;
}

_parseServiceDataForWoColorBulb(buf, onlog) {
if (buf.length !== 6) {
if (onlog && typeof onlog === 'function') {
onlog(`[_parseServiceDataForWoColorBulb] Buffer length ${buf.length} !== 6!`);
}
return null;
}
let byte1 = buf.readUInt8(1);
let byte2 = buf.readUInt8(2);
// let byte3 = buf.readUInt8(3);
// let byte4 = buf.readUInt8(4);
let byte5 = buf.readUInt8(5);

let data = {
model: 'u',
modelName: 'WoColorBulb',
};

return data;
}

_parseServiceDataForWoPlugMini(buf, onlog) {
if (buf.length !== 6) {
if (onlog && typeof onlog === 'function') {
onlog(`[_parseServiceDataForWoPlugMini] Buffer length ${buf.length} !== 6!`);
}
return null;
}
let byte1 = buf.readUInt8(1);
let byte2 = buf.readUInt8(2);
// let byte3 = buf.readUInt8(3);
// let byte4 = buf.readUInt8(4);
let byte5 = buf.readUInt8(5);

let data = {
model: 'g',
modelName: 'WoPlugMini',
};

return data;
}

_parseServiceDataForWoSmartLock(buf, onlog) {
if (buf.length !== 6) {
if (onlog && typeof onlog === 'function') {
onlog(`[_parseServiceDataForWoSmartLock] Buffer length ${buf.length} !== 6!`);
}
return null;
}
let byte1 = buf.readUInt8(1);
let byte2 = buf.readUInt8(2);
// let byte3 = buf.readUInt8(3);
// let byte4 = buf.readUInt8(4);
let byte5 = buf.readUInt8(5);

//let pirState = (byte1 & 0b01000000) ? true : false; // 1 - Movement detected
let battery = byte2 & 0b01111111; // %
//let lightLevel = byte5 & 0b00000011;

let data = {
model: 'o',
modelName: 'WoSmartLock',
//movement: pirState,
battery: battery,
//lightLevel: (lightLevel == 1) ? 'dark' : ((lightLevel == 2) ? 'bright' : 'unknown'),
};

return data;
}

_parseServiceDataForWoSensorTHPlus(buf, onlog) {
if (buf.length !== 6) {
if (onlog && typeof onlog === 'function') {
onlog(`[_parseServiceDataForWoSensorTHPlus] Buffer length ${buf.length} !== 6!`);
}
return null;
}
let byte2 = buf.readUInt8(2);
let byte3 = buf.readUInt8(3);
let byte4 = buf.readUInt8(4);
let byte5 = buf.readUInt8(5);

let temp_sign = (byte4 & 0b10000000) ? 1 : -1;
let temp_c = temp_sign * ((byte4 & 0b01111111) + (byte3 / 10));
let temp_f = (temp_c * 9 / 5) + 32;
temp_f = Math.round(temp_f * 10) / 10;

let data = {
model: 'i',
modelName: 'WoSensorTHPlus',
temperature: {
c: temp_c,
f: temp_f
},
fahrenheit: (byte5 & 0b10000000) ? true : false,
humidity: byte5 & 0b01111111,
battery: (byte2 & 0b01111111)
};

return data;
}

_parseServiceDataForWoLEDStripLight(buf, onlog) {
if (buf.length !== 6) {
if (onlog && typeof onlog === 'function') {
onlog(`[_parseServiceDataForWoLEDStripLight] Buffer length ${buf.length} !== 6!`);
}
return null;
}
let byte1 = buf.readUInt8(1);
let byte2 = buf.readUInt8(2);
// let byte3 = buf.readUInt8(3);
// let byte4 = buf.readUInt8(4);
let byte5 = buf.readUInt8(5);

let data = {
model: 'r',
modelName: 'WoLEDStripLight',
};

return data;
}
}

module.exports = new SwitchbotAdvertising();
49 changes: 42 additions & 7 deletions lib/switchbot.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,13 +51,18 @@ class Switchbot {
* - duration | Integer | Optional | Duration for discovery process (msec).
* | | | The value must be in the range of 1 to 60000.
* | | | The default value is 5000 (msec).
* - model | String | Optional | "H", "T", "e", "s", "d", or "c".
* - model | String | Optional | "H", "T", "e", "s", "d", "c", "u", "g", "o", "i", or "r".
* | | | If "H" is specified, this method will discover only Bots.
* | | | If "T" is specified, this method will discover only Meters.
* | | | If "e" is specified, this method will discover only Humidifiers.
* | | | If "s" is specified, this method will discover only Motion Sensors.
* | | | If "d" is specified, this method will discover only Contact Sensors.
* | | | If "c" is specified, this method will discover only Curtains.
* | | | If "u" is specified, this method will discover only Color Bulbs.
* | | | If "g" is specified, this method will discover only Plugs.
* | | | If "o" is specified, this method will discover only Locks.
* | | | If "i" is specified, this method will discover only Meter Pluses.
* | | | If "r" is specified, this method will discover only Locks.
* - id | String | Optional | If this value is set, this method will discover
* | | | only a device whose ID is as same as this value.
* | | | The ID is identical to the MAC address.
Expand All @@ -79,7 +84,7 @@ class Switchbot {
// Check the parameters
let valid = parameterChecker.check(params, {
duration: { required: false, type: 'integer', min: 1, max: 60000 },
model: { required: false, type: 'string', enum: ['H', 'T', 'e', 's', 'd', 'c'] },
model: { required: false, type: 'string', enum: ['H', 'T', 'e', 's', 'd', 'c', 'u', 'g', 'o', 'i', 'r'] },
id: { required: false, type: 'string', min: 12, max: 17 },
quick: { required: false, type: 'boolean' }
}, false);
Expand Down Expand Up @@ -186,12 +191,12 @@ class Switchbot {
case 'H':
device = new SwitchbotDeviceWoHand(peripheral, this.noble);
break;
case 'e':
device = new SwitchbotDeviceWoHumi(peripheral, this.noble);
break;
case 'T':
device = new SwitchbotDeviceWoSensorTH(peripheral, this.noble);
break;
case 'e':
device = new SwitchbotDeviceWoHumi(peripheral, this.noble);
break;
case 's':
device = new SwitchbotDeviceWoPresence(peripheral, this.noble);
break;
Expand All @@ -201,6 +206,21 @@ class Switchbot {
case 'c':
device = new SwitchbotDeviceWoCurtain(peripheral, this.noble);
break;
case 'u':
device = new SwitchbotDeviceWoColorBulb(peripheral, this.noble);
break;
case 'g':
device = new SwitchbotDeviceWoPlugMini(peripheral, this.noble);
break;
case 'o':
device = new SwitchbotDeviceWoSmartLock(peripheral, this.noble);
break;
case 'i':
device = new SwitchbotDeviceWoSensorTHPlus(peripheral, this.noble);
break;
case 'r':
device = new SwitchbotDeviceWoLEDStripLight(peripheral, this.noble);
break;
default: // 'resetting', 'unknown'
device = new SwitchbotDevice(peripheral, this.noble);
}
Expand Down Expand Up @@ -235,7 +255,7 @@ class Switchbot {
*
* [Arguments]
* - params | Object | Optional |
* - model | String | Optional | "H", "T", "e", "s", "d", or "c".
* - model | String | Optional | "H", "T", "e", "s", "d", "c", "u", "g", "o", "i", or "r".
* | | | If "H" is specified, the `onadvertisement`
* | | | event handler will be called only when advertising
* | | | packets comes from Bots.
Expand All @@ -254,6 +274,21 @@ class Switchbot {
* | | | If "c" is specified, the `onadvertisement`
* | | | event handler will be called only when advertising
* | | | packets comes from Curtains.
* | | | If "u" is specified, the `onadvertisement`
* | | | event handler will be called only when advertising
* | | | packets comes from Color Bulb.
* | | | If "g" is specified, the `onadvertisement`
* | | | event handler will be called only when advertising
* | | | packets comes from Plug Mini.
* | | | If "o" is specified, the `onadvertisement`
* | | | event handler will be called only when advertising
* | | | packets comes from Smart Lock.
* | | | If "i" is specified, the `onadvertisement`
* | | | event handler will be called only when advertising
* | | | packets comes from Meter Plus.
* | | | If "r" is specified, the `onadvertisement`
* | | | event handler will be called only when advertising
* | | | packets comes from LED Strip Light.
* - id | String | Optional | If this value is set, the `onadvertisement`
* | | | event handler will be called only when advertising
* | | | packets comes from devices whose ID is as same as
Expand All @@ -270,7 +305,7 @@ class Switchbot {
let promise = new Promise((resolve, reject) => {
// Check the parameters
let valid = parameterChecker.check(params, {
model: { required: false, type: 'string', enum: ['H', 'T', 'e', 's', 'd', 'c'] },
model: { required: false, type: 'string', enum: ['H', 'T', 'e', 's', 'd', 'c', 'u', 'g', 'o', 'i', 'r'] },
id: { required: false, type: 'string', min: 12, max: 17 },
}, false);

Expand Down
Loading