node-switchbot 1.0.9-beta.1 → 1.1.0
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.
- package/CHANGELOG.md +10 -2
- package/README.md +1 -1
- package/lib/switchbot-advertising.js +52 -19
- package/lib/switchbot.js +17 -13
- package/package.json +40 -40
package/CHANGELOG.md
CHANGED
|
@@ -2,7 +2,15 @@
|
|
|
2
2
|
|
|
3
3
|
All notable changes to this project will be documented in this file. This project uses [Semantic Versioning](https://semver.org/)
|
|
4
4
|
|
|
5
|
-
## [Version 1.0
|
|
5
|
+
## [Version 1.1.0](https://github.com/OpenWonderLabs/homebridge-switchbot/releases/tag/v1.1.0) (2021-10-26)
|
|
6
|
+
|
|
7
|
+
### Changes
|
|
8
|
+
|
|
9
|
+
- Add Contact/Motion Sensor advertisement
|
|
10
|
+
- Add Humidifier advertisement
|
|
11
|
+
- Correct Model for advertisement
|
|
12
|
+
|
|
13
|
+
## [Version 1.0.8](https://github.com/OpenWonderLabs/homebridge-switchbot/releases/tag/v1.0.8) (2021-09-30)
|
|
6
14
|
|
|
7
15
|
### Changes
|
|
8
16
|
|
|
@@ -93,4 +101,4 @@ All notable changes to this project will be documented in this file. This projec
|
|
|
93
101
|
|
|
94
102
|
### Changes
|
|
95
103
|
|
|
96
|
-
- First public release
|
|
104
|
+
- First public release
|
package/README.md
CHANGED
|
@@ -899,4 +899,4 @@ Property | Type | Description
|
|
|
899
899
|
## References
|
|
900
900
|
|
|
901
901
|
* [Switchbot official global site](https://www.switch-bot.com/)
|
|
902
|
-
* [Github - OpenWonderLabs/python-host](https://github.com/OpenWonderLabs/python-host)
|
|
902
|
+
* [Github - OpenWonderLabs/python-host](https://github.com/OpenWonderLabs/python-host)
|
|
@@ -78,15 +78,15 @@ class SwitchbotAdvertising {
|
|
|
78
78
|
|
|
79
79
|
if (model === 'H') { // WoHand
|
|
80
80
|
sd = this._parseServiceDataForWoHand(buf);
|
|
81
|
-
} else if (model === '
|
|
81
|
+
} else if (model === 'e') { // WoHumi
|
|
82
82
|
sd = this._parseServiceDataForWoHumi(buf);
|
|
83
83
|
} else if (model === 'T') { // WoSensorTH
|
|
84
84
|
sd = this._parseServiceDataForWoSensorTH(buf);
|
|
85
85
|
} else if (model === 'c') { // WoCurtain
|
|
86
86
|
sd = this._parseServiceDataForWoCurtain(buf);
|
|
87
|
-
} else if (model === '
|
|
87
|
+
} else if (model === 's') { // WoMotion
|
|
88
88
|
sd = this._parseServiceDataForWoPresence(buf);
|
|
89
|
-
} else if (model === '
|
|
89
|
+
} else if (model === 'd') { // WoContact
|
|
90
90
|
sd = this._parseServiceDataForWoContact(buf);
|
|
91
91
|
} else {
|
|
92
92
|
return null;
|
|
@@ -142,20 +142,25 @@ class SwitchbotAdvertising {
|
|
|
142
142
|
}
|
|
143
143
|
|
|
144
144
|
_parseServiceDataForWoHumi(buf) {
|
|
145
|
-
if (buf.length !==
|
|
145
|
+
if (buf.length !== 8) {
|
|
146
146
|
return null;
|
|
147
147
|
}
|
|
148
148
|
let byte1 = buf.readUInt8(1);
|
|
149
|
-
let byte2 = buf.readUInt8(2);
|
|
149
|
+
// let byte2 = buf.readUInt8(2);
|
|
150
|
+
let byte3 = buf.readUInt8(3);
|
|
151
|
+
let byte4 = buf.readUInt8(4);
|
|
152
|
+
let byte5 = buf.readUInt8(5);
|
|
150
153
|
|
|
151
|
-
let
|
|
152
|
-
let
|
|
154
|
+
let onState = (byte1 & 0b10000000) ? true : false; // 1 - on
|
|
155
|
+
let autoMode = (byte4 & 0b10000000) ? true : false; // 1 - auto
|
|
156
|
+
let percentage = byte4 & 0b01111111; // 0-100%, 101/102/103 - Quick gear 1/2/3
|
|
153
157
|
|
|
154
158
|
let data = {
|
|
155
|
-
model: '
|
|
159
|
+
model: 'e',
|
|
156
160
|
modelName: 'WoHumi',
|
|
157
|
-
|
|
158
|
-
|
|
161
|
+
onState: onState,
|
|
162
|
+
autoMode: autoMode,
|
|
163
|
+
percentage: autoMode ? 0 : percentage,
|
|
159
164
|
};
|
|
160
165
|
|
|
161
166
|
return data;
|
|
@@ -194,25 +199,53 @@ class SwitchbotAdvertising {
|
|
|
194
199
|
if (buf.length !== 6) {
|
|
195
200
|
return null;
|
|
196
201
|
}
|
|
202
|
+
let byte1 = buf.readUInt8(1);
|
|
203
|
+
let byte2 = buf.readUInt8(2);
|
|
204
|
+
// let byte3 = buf.readUInt8(3);
|
|
205
|
+
// let byte4 = buf.readUInt8(4);
|
|
206
|
+
let byte5 = buf.readUInt8(5);
|
|
207
|
+
|
|
208
|
+
let pirState = (byte1 & 0b01000000) ? true : false; // 1 - Movement detected
|
|
209
|
+
let battery = byte2 & 0b01111111; // %
|
|
210
|
+
let lightLevel = byte5 & 0b00000011;
|
|
197
211
|
|
|
198
212
|
let data = {
|
|
199
|
-
model: '
|
|
200
|
-
modelName: '
|
|
201
|
-
|
|
213
|
+
model: 's',
|
|
214
|
+
modelName: 'WoMotion',
|
|
215
|
+
movement: pirState,
|
|
216
|
+
battery: battery,
|
|
217
|
+
lightLevel: (lightLevel == 1) ? 'dark' : ((lightLevel == 2) ? 'bright' : 'unknown'),
|
|
202
218
|
};
|
|
203
219
|
|
|
204
220
|
return data;
|
|
205
221
|
}
|
|
206
222
|
|
|
207
223
|
_parseServiceDataForWoContact(buf) {
|
|
208
|
-
if (buf.length !==
|
|
224
|
+
if (buf.length !== 9) {
|
|
209
225
|
return null;
|
|
210
226
|
}
|
|
211
227
|
|
|
228
|
+
let byte1 = buf.readUInt8(1);
|
|
229
|
+
let byte2 = buf.readUInt8(2);
|
|
230
|
+
let byte3 = buf.readUInt8(3);
|
|
231
|
+
// let byte4 = buf.readUInt8(4);
|
|
232
|
+
// let byte5 = buf.readUInt8(5);
|
|
233
|
+
// let byte6 = buf.readUInt8(6);
|
|
234
|
+
// let byte7 = buf.readUInt8(7);
|
|
235
|
+
// let byte8 = buf.readUInt8(8);
|
|
236
|
+
|
|
237
|
+
let pirState = (byte1 & 0b01000000) ? true : false; // 1 - Movement detected
|
|
238
|
+
let battery = byte2 & 0b01111111; // %
|
|
239
|
+
let hallState = (byte3 >> 1) & 0b00000011;
|
|
240
|
+
let lightLevel = byte3 & 0b00000001;
|
|
241
|
+
|
|
212
242
|
let data = {
|
|
213
|
-
model: '
|
|
243
|
+
model: 'd',
|
|
214
244
|
modelName: 'WoContact',
|
|
215
|
-
|
|
245
|
+
movement: pirState,
|
|
246
|
+
battery: battery,
|
|
247
|
+
doorState: (hallState == 0) ? 'close' : ((hallState == 1) ? 'open' : 'timeout no closed'),
|
|
248
|
+
lightLevel: (lightLevel == 0) ? 'dark' : 'bright',
|
|
216
249
|
};
|
|
217
250
|
|
|
218
251
|
return data;
|
|
@@ -227,7 +260,7 @@ class SwitchbotAdvertising {
|
|
|
227
260
|
let byte3 = buf.readUInt8(3);
|
|
228
261
|
let byte4 = buf.readUInt8(4);
|
|
229
262
|
|
|
230
|
-
let calibration = byte1 & 0b01000000; // Whether the calibration is completed
|
|
263
|
+
let calibration = (byte1 & 0b01000000) ? true : false; // Whether the calibration is completed
|
|
231
264
|
let battery = byte2 & 0b01111111; // %
|
|
232
265
|
let currPosition = byte3 & 0b01111111; // current positon %
|
|
233
266
|
let lightLevel = (byte4 >> 4) & 0b00001111; // light sensor level (1-10)
|
|
@@ -235,7 +268,7 @@ class SwitchbotAdvertising {
|
|
|
235
268
|
let data = {
|
|
236
269
|
model: 'c',
|
|
237
270
|
modelName: 'WoCurtain',
|
|
238
|
-
calibration: calibration
|
|
271
|
+
calibration: calibration,
|
|
239
272
|
battery: battery,
|
|
240
273
|
position: currPosition,
|
|
241
274
|
lightLevel: lightLevel
|
|
@@ -245,4 +278,4 @@ class SwitchbotAdvertising {
|
|
|
245
278
|
}
|
|
246
279
|
}
|
|
247
280
|
|
|
248
|
-
module.exports = new SwitchbotAdvertising();
|
|
281
|
+
module.exports = new SwitchbotAdvertising();
|
package/lib/switchbot.js
CHANGED
|
@@ -50,12 +50,13 @@ class Switchbot {
|
|
|
50
50
|
* - duration | Integer | Optional | Duration for discovery process (msec).
|
|
51
51
|
* | | | The value must be in the range of 1 to 60000.
|
|
52
52
|
* | | | The default value is 5000 (msec).
|
|
53
|
-
* - model | String | Optional | "H", "T", "
|
|
53
|
+
* - model | String | Optional | "H", "T", "e", "s", "d", or "c".
|
|
54
54
|
* | | | If "H" is specified, this method will discover only Bots.
|
|
55
55
|
* | | | If "T" is specified, this method will discover only Meters.
|
|
56
|
-
* | | | If "
|
|
57
|
-
* | | | If "
|
|
58
|
-
* | | | If "
|
|
56
|
+
* | | | If "e" is specified, this method will discover only Humidifiers.
|
|
57
|
+
* | | | If "s" is specified, this method will discover only Motion Sensors.
|
|
58
|
+
* | | | If "d" is specified, this method will discover only Contact Sensors.
|
|
59
|
+
* | | | If "c" is specified, this method will discover only Curtains.
|
|
59
60
|
* - id | String | Optional | If this value is set, this method willl discover
|
|
60
61
|
* | | | only a device whose ID is as same as this value.
|
|
61
62
|
* | | | The ID is identical to the MAC address.
|
|
@@ -77,7 +78,7 @@ class Switchbot {
|
|
|
77
78
|
// Check the parameters
|
|
78
79
|
let valid = parameterChecker.check(params, {
|
|
79
80
|
duration: { required: false, type: 'integer', min: 1, max: 60000 },
|
|
80
|
-
model: { required: false, type: 'string', enum: ['H', '
|
|
81
|
+
model: { required: false, type: 'string', enum: ['H', 'T', 'e', 's', 'd', 'c'] },
|
|
81
82
|
id: { required: false, type: 'string', min: 12, max: 17 },
|
|
82
83
|
quick: { required: false, type: 'boolean' }
|
|
83
84
|
}, false);
|
|
@@ -184,16 +185,16 @@ class Switchbot {
|
|
|
184
185
|
case 'H':
|
|
185
186
|
device = new SwitchbotDeviceWoHand(peripheral, this.noble);
|
|
186
187
|
break;
|
|
187
|
-
case '
|
|
188
|
+
case 'e':
|
|
188
189
|
device = new SwitchbotDeviceWoHumi(peripheral, this.noble);
|
|
189
190
|
break;
|
|
190
191
|
case 'T':
|
|
191
192
|
device = new SwitchbotDeviceWoSensorTH(peripheral, this.noble);
|
|
192
193
|
break;
|
|
193
|
-
case '
|
|
194
|
+
case 's':
|
|
194
195
|
device = new SwitchbotDeviceWoPresence(peripheral, this.noble);
|
|
195
196
|
break;
|
|
196
|
-
case '
|
|
197
|
+
case 'd':
|
|
197
198
|
device = new SwitchbotDeviceWoContact(peripheral, this.noble);
|
|
198
199
|
break;
|
|
199
200
|
case 'c':
|
|
@@ -233,20 +234,23 @@ class Switchbot {
|
|
|
233
234
|
*
|
|
234
235
|
* [Arguments]
|
|
235
236
|
* - params | Object | Optional |
|
|
236
|
-
* - model | String | Optional | "H", "T", "
|
|
237
|
+
* - model | String | Optional | "H", "T", "e", "s", "d", or "c".
|
|
237
238
|
* | | | If "H" is specified, the `onadvertisement`
|
|
238
239
|
* | | | event hander will be called only when advertising
|
|
239
240
|
* | | | packets comes from Bots.
|
|
240
241
|
* | | | If "T" is specified, the `onadvertisement`
|
|
241
242
|
* | | | event hander will be called only when advertising
|
|
242
243
|
* | | | packets comes from Meters.
|
|
243
|
-
* | | | If "
|
|
244
|
+
* | | | If "e" is specified, the `onadvertisement`
|
|
245
|
+
* | | | event hander will be called only when advertising
|
|
246
|
+
* | | | packets comes from Humidifiers.
|
|
247
|
+
* | | | If "s" is specified, the `onadvertisement`
|
|
244
248
|
* | | | event hander will be called only when advertising
|
|
245
249
|
* | | | packets comes from Motion Sensor.
|
|
246
|
-
* | | | If "
|
|
250
|
+
* | | | If "d" is specified, the `onadvertisement`
|
|
247
251
|
* | | | event hander will be called only when advertising
|
|
248
252
|
* | | | packets comes from Contact Sensor.
|
|
249
|
-
* | | | If "
|
|
253
|
+
* | | | If "c" is specified, the `onadvertisement`
|
|
250
254
|
* | | | event hander will be called only when advertising
|
|
251
255
|
* | | | packets comes from Curtains.
|
|
252
256
|
* - id | String | Optional | If this value is set, the `onadvertisement`
|
|
@@ -265,7 +269,7 @@ class Switchbot {
|
|
|
265
269
|
let promise = new Promise((resolve, reject) => {
|
|
266
270
|
// Check the parameters
|
|
267
271
|
let valid = parameterChecker.check(params, {
|
|
268
|
-
model: { required: false, type: 'string', enum: ['H', '
|
|
272
|
+
model: { required: false, type: 'string', enum: ['H', 'T', 'e', 's', 'd', 'c'] },
|
|
269
273
|
id: { required: false, type: 'string', min: 12, max: 17 },
|
|
270
274
|
}, false);
|
|
271
275
|
|
package/package.json
CHANGED
|
@@ -1,42 +1,42 @@
|
|
|
1
1
|
{
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
2
|
+
"name": "node-switchbot",
|
|
3
|
+
"version": "1.1.0",
|
|
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).",
|
|
5
|
+
"main": "./lib/switchbot.js",
|
|
6
|
+
"files": [
|
|
7
|
+
"lib"
|
|
8
|
+
],
|
|
9
|
+
"directories": {
|
|
10
|
+
"lib": "./lib"
|
|
11
|
+
},
|
|
12
|
+
"scripts": {
|
|
13
|
+
"check": "npm install && npm outdated",
|
|
14
|
+
"update": "ncu -u && npm update && npm install"
|
|
15
|
+
},
|
|
16
|
+
"keywords": [
|
|
17
|
+
"switchbot",
|
|
18
|
+
"bot",
|
|
19
|
+
"meter",
|
|
20
|
+
"temperature",
|
|
21
|
+
"humidity",
|
|
22
|
+
"curtain",
|
|
23
|
+
"BLE",
|
|
24
|
+
"Bluetooth Low Energy",
|
|
25
|
+
"Bluetooth smart",
|
|
26
|
+
"Bluetooth"
|
|
27
|
+
],
|
|
28
|
+
"homepage": "https://github.com/OpenWonderLabs",
|
|
29
|
+
"author": "OpenWonderLabs (https://github.com/OpenWonderLabs)",
|
|
30
|
+
"license": "MIT",
|
|
31
|
+
"repository": {
|
|
32
|
+
"type": "git",
|
|
33
|
+
"url": "https://github.com/OpenWonderLabs/node-switchbot.git"
|
|
34
|
+
},
|
|
35
|
+
"readmeFilename": "README.md",
|
|
36
|
+
"dependencies": {
|
|
37
|
+
"@homebridge/noble": "^1.9.3"
|
|
38
|
+
},
|
|
39
|
+
"devDependencies": {
|
|
40
|
+
"npm-check-updates": "^11.8.5"
|
|
41
|
+
}
|
|
42
42
|
}
|