node-switchbot
Advanced tools
Comparing version 1.0.9-beta.4 to 1.1.0
@@ -5,6 +5,14 @@ # Changelog | ||
## [Version 1.0.8](https://github.com/OpenWonderLabs/homebridge-switchbot/releases/tag/v1.0.48) (2021-09-30) | ||
## [Version 1.1.0](https://github.com/OpenWonderLabs/homebridge-switchbot/releases/tag/v1.1.0) (2021-10-26) | ||
### Changes | ||
- Add Contact/Motion Sensor advertisement | ||
- Add Humidifier advertisement | ||
- Correct Model for advertisement | ||
## [Version 1.0.8](https://github.com/OpenWonderLabs/homebridge-switchbot/releases/tag/v1.0.8) (2021-09-30) | ||
### Changes | ||
- fix extra trace of old noble from @abandonware/noble | ||
@@ -97,2 +105,2 @@ | ||
- First public release | ||
- First public release |
@@ -81,2 +81,4 @@ 'use strict'; | ||
sd = this._parseServiceDataForWoHand(buf); | ||
} else if (model === 'e') { // WoHumi | ||
sd = this._parseServiceDataForWoHumi(buf); | ||
} else if (model === 'T') { // WoSensorTH | ||
@@ -86,5 +88,5 @@ sd = this._parseServiceDataForWoSensorTH(buf); | ||
sd = this._parseServiceDataForWoCurtain(buf); | ||
} else if (model === 'P') { // WoPresence | ||
} else if (model === 's') { // WoMotion | ||
sd = this._parseServiceDataForWoPresence(buf); | ||
} else if (model === 'C') { // WoContact | ||
} else if (model === 'd') { // WoContact | ||
sd = this._parseServiceDataForWoContact(buf); | ||
@@ -144,2 +146,27 @@ } else { | ||
_parseServiceDataForWoHumi(buf) { | ||
if (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) { | ||
@@ -178,23 +205,18 @@ if (buf.length !== 6) { | ||
} | ||
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); | ||
const byte1 = buf.readUInt8(1); | ||
const byte2 = buf.readUInt8(2); | ||
const byte3 = buf.readUInt8(3); | ||
const byte4 = buf.readUInt8(4); | ||
const byte5 = buf.readUInt8(5); | ||
let pirState = (byte1 & 0b01000000) ? true : false; // 1 - Movement detected | ||
let battery = byte2 & 0b01111111; // % | ||
let lightLevel = byte5 & 0b00000011; | ||
const motion = byte1 & 0b01000000; // Whether the calibration is completed | ||
const battery = byte2 & 0b01111111; // % | ||
const pir_trigger3 = byte3 & 0b00001111; // | ||
const pir_trigger4 = byte4 & 0b01000000; // | ||
const state = byte5 & 0b01111111; // % | ||
const data = { | ||
let data = { | ||
model: 's', | ||
modelName: 'WoPresence', | ||
motion: motion ? true : false, | ||
modelName: 'WoMotion', | ||
movement: pirState, | ||
battery: battery, | ||
pir_trigger3: pir_trigger3, | ||
pir_trigger4: pir_trigger4, | ||
state: state ? true : false, | ||
lightLevel: (lightLevel == 1) ? 'dark' : ((lightLevel == 2) ? 'bright' : 'unknown'), | ||
}; | ||
@@ -206,35 +228,27 @@ | ||
_parseServiceDataForWoContact(buf) { | ||
if (buf.length !== 6) { | ||
if (buf.length !== 9) { | ||
return null; | ||
} | ||
const byte1 = buf.readUInt8(1); | ||
const byte2 = buf.readUInt8(2); | ||
const byte3 = buf.readUInt8(3); | ||
const byte4 = buf.readUInt8(4); | ||
const byte5 = buf.readUInt8(5); | ||
const byte6 = buf.readUInt8(6); | ||
const byte7 = buf.readUInt8(7); | ||
const byte8 = buf.readUInt8(8); | ||
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 byte6 = buf.readUInt8(6); | ||
// let byte7 = buf.readUInt8(7); | ||
// let byte8 = buf.readUInt8(8); | ||
const motion = byte1 & 0b01000000; // Whether there is motion | ||
const battery = byte2 & 0b01111111; // % | ||
const state = byte3 & 0b01111111; // current state | ||
const pir_trigger4 = byte4 & 0b00001111; // | ||
const pir_trigger5 = byte5 & 0b01000000; // | ||
const hal_trigger6 = byte6 & 0b01111111; // | ||
const hal_trigger7 = byte7 & 0b01111111; // | ||
const act_counter = byte8 & 0b00001111; // | ||
let pirState = (byte1 & 0b01000000) ? true : false; // 1 - Movement detected | ||
let battery = byte2 & 0b01111111; // % | ||
let hallState = (byte3 >> 1) & 0b00000011; | ||
let lightLevel = byte3 & 0b00000001; | ||
const data = { | ||
let data = { | ||
model: 'd', | ||
modelName: 'WoContact', | ||
motion: motion ? true : false, | ||
movement: pirState, | ||
battery: battery, | ||
state: state ? true : false, | ||
pir_trigger4: pir_trigger4, | ||
pir_trigger5: pir_trigger5, | ||
hal_trigger6: hal_trigger6, | ||
hal_trigger7: hal_trigger7, | ||
act_counter: act_counter, | ||
doorState: (hallState == 0) ? 'close' : ((hallState == 1) ? 'open' : 'timeout no closed'), | ||
lightLevel: (lightLevel == 0) ? 'dark' : 'bright', | ||
}; | ||
@@ -254,3 +268,3 @@ | ||
let calibration = byte1 & 0b01000000; // Whether the calibration is completed | ||
let calibration = (byte1 & 0b01000000) ? true : false; // Whether the calibration is completed | ||
let battery = byte2 & 0b01111111; // % | ||
@@ -263,3 +277,3 @@ let currPosition = byte3 & 0b01111111; // current positon % | ||
modelName: 'WoCurtain', | ||
calibration: calibration ? true : false, | ||
calibration: calibration, | ||
battery: battery, | ||
@@ -274,2 +288,2 @@ position: currPosition, | ||
module.exports = new SwitchbotAdvertising(); | ||
module.exports = new SwitchbotAdvertising(); |
@@ -11,2 +11,3 @@ 'use strict'; | ||
const SwitchbotDeviceWoSensorTH = require('./switchbot-device-wosensorth.js'); | ||
const SwitchbotDeviceWoHumi = require('./switchbot-device-wohumi.js'); | ||
@@ -53,8 +54,9 @@ class Switchbot { | ||
* | | | The default value is 5000 (msec). | ||
* - model | String | Optional | "H", "T", "M", "D", or "S". | ||
* - model | String | Optional | "H", "T", "e", "s", "d", or "c". | ||
* | | | If "H" is specified, this method will discover only Bots. | ||
* | | | If "T" is specified, this method will discover only Meters. | ||
* | | | 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 "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. | ||
* - id | String | Optional | If this value is set, this method willl discover | ||
@@ -81,3 +83,3 @@ * | | | only a device whose ID is as same as this value. | ||
duration: { required: false, type: 'integer', min: 1, max: 60000 }, | ||
model: { required: false, type: 'string', enum: ['H', 'h','T', 'P', 'S', 'D', 'C', 'c'] }, | ||
model: { required: false, type: 'string', enum: ['H', 'T', 'e', 's', 'd', 'c'] }, | ||
id: { required: false, type: 'string', min: 12, max: 17 }, | ||
@@ -189,9 +191,12 @@ quick: { required: false, type: 'boolean' } | ||
break; | ||
case 'e': | ||
device = new SwitchbotDeviceWoHumi(peripheral, this.noble); | ||
break; | ||
case 'T': | ||
device = new SwitchbotDeviceWoSensorTH(peripheral, this.noble); | ||
break; | ||
case 'S': | ||
case 's': | ||
device = new SwitchbotDeviceWoPresence(peripheral, this.noble); | ||
break; | ||
case 'D': | ||
case 'd': | ||
device = new SwitchbotDeviceWoContact(peripheral, this.noble); | ||
@@ -236,3 +241,3 @@ break; | ||
* - params | Object | Optional | | ||
* - model | String | Optional | "H", "T", "M", "CS", or "C". | ||
* - model | String | Optional | "H", "T", "e", "s", "d", or "c". | ||
* | | | If "H" is specified, the `onadvertisement` | ||
@@ -244,9 +249,12 @@ * | | | event hander will be called only when advertising | ||
* | | | packets comes from Meters. | ||
* | | | If "S" is specified, the `onadvertisement` | ||
* | | | If "e" is specified, the `onadvertisement` | ||
* | | | event hander will be called only when advertising | ||
* | | | packets comes from Humidifiers. | ||
* | | | If "s" is specified, the `onadvertisement` | ||
* | | | event hander will be called only when advertising | ||
* | | | packets comes from Motion Sensor. | ||
* | | | If "D" is specified, the `onadvertisement` | ||
* | | | If "d" is specified, the `onadvertisement` | ||
* | | | event hander will be called only when advertising | ||
* | | | packets comes from Contact Sensor. | ||
* | | | If "C" is specified, the `onadvertisement` | ||
* | | | If "c" is specified, the `onadvertisement` | ||
* | | | event hander will be called only when advertising | ||
@@ -270,3 +278,3 @@ * | | | packets comes from Curtains. | ||
let valid = parameterChecker.check(params, { | ||
model: { required: false, type: 'string', enum: ['H', 'h','T', 'P', 'S', 'D', 'C', 'c'] }, | ||
model: { required: false, type: 'string', enum: ['H', 'T', 'e', 's', 'd', 'c'] }, | ||
id: { required: false, type: 'string', min: 12, max: 17 }, | ||
@@ -273,0 +281,0 @@ }, false); |
{ | ||
"name": "node-switchbot", | ||
"version": "1.0.9-beta.4", | ||
"description": "The node-switchbot is a Node.js module which allows you to move your Switchbot (Bot)'s arm and Switchbot Curtain(Curtain), also monitor the temperature/humidity from SwitchBot Thermometer & Hygrometer (Meter).", | ||
"main": "./lib/switchbot.js", | ||
"files": [ | ||
"lib" | ||
], | ||
"directories": { | ||
"lib": "./lib" | ||
}, | ||
"scripts": { | ||
"check": "npm install && npm outdated", | ||
"update": "ncu -u && npm update && npm install" | ||
}, | ||
"keywords": [ | ||
"switchbot", | ||
"bot", | ||
"meter", | ||
"temperature", | ||
"humidity", | ||
"curtain", | ||
"BLE", | ||
"Bluetooth Low Energy", | ||
"Bluetooth smart", | ||
"Bluetooth" | ||
], | ||
"homepage": "https://github.com/OpenWonderLabs", | ||
"author": "OpenWonderLabs (https://github.com/OpenWonderLabs)", | ||
"license": "MIT", | ||
"repository": { | ||
"type": "git", | ||
"url": "https://github.com/futomi/node-switchbot.git" | ||
}, | ||
"readmeFilename": "README.md", | ||
"dependencies": { | ||
"@homebridge/noble": "^1.9.3" | ||
}, | ||
"devDependencies": { | ||
"npm-check-updates": "^11.8.5" | ||
} | ||
"name": "node-switchbot", | ||
"version": "1.1.0", | ||
"description": "The node-switchbot is a Node.js module which allows you to move your Switchbot (Bot)'s arm and Switchbot Curtain(Curtain), also monitor the temperature/humidity from SwitchBot Thermometer & Hygrometer (Meter).", | ||
"main": "./lib/switchbot.js", | ||
"files": [ | ||
"lib" | ||
], | ||
"directories": { | ||
"lib": "./lib" | ||
}, | ||
"scripts": { | ||
"check": "npm install && npm outdated", | ||
"update": "ncu -u && npm update && npm install" | ||
}, | ||
"keywords": [ | ||
"switchbot", | ||
"bot", | ||
"meter", | ||
"temperature", | ||
"humidity", | ||
"curtain", | ||
"BLE", | ||
"Bluetooth Low Energy", | ||
"Bluetooth smart", | ||
"Bluetooth" | ||
], | ||
"homepage": "https://github.com/OpenWonderLabs", | ||
"author": "OpenWonderLabs (https://github.com/OpenWonderLabs)", | ||
"license": "MIT", | ||
"repository": { | ||
"type": "git", | ||
"url": "https://github.com/OpenWonderLabs/node-switchbot.git" | ||
}, | ||
"readmeFilename": "README.md", | ||
"dependencies": { | ||
"@homebridge/noble": "^1.9.3" | ||
}, | ||
"devDependencies": { | ||
"npm-check-updates": "^11.8.5" | ||
} | ||
} |
@@ -902,2 +902,2 @@ <span align="center"> | ||
* [Switchbot official global site](https://www.switch-bot.com/) | ||
* [Github - OpenWonderLabs/python-host](https://github.com/OpenWonderLabs/python-host) | ||
* [Github - OpenWonderLabs/python-host](https://github.com/OpenWonderLabs/python-host) |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
Found 1 instance in 1 package
101499
14
1742
0
902