node-switchbot 1.1.3-beta.8 → 1.2.1-beta.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 +38 -1
- package/lib/switchbot-advertising.js +202 -40
- package/lib/switchbot.js +45 -9
- package/package.json +2 -2
package/CHANGELOG.md
CHANGED
|
@@ -2,25 +2,32 @@
|
|
|
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
|
-
## [
|
|
5
|
+
## [Version 1.2.0](https://github.com/OpenWonderLabs/node-switchbot/releases/tag/v1.2.0) (2022-03-04)
|
|
6
6
|
|
|
7
7
|
### Changes
|
|
8
8
|
|
|
9
9
|
- Added support for SwitchBot "Contact" and "Motion"
|
|
10
|
+
- Fix for Curtains on Firmware v3.3 and above
|
|
10
11
|
- Housekeeping and update dependencies
|
|
11
12
|
|
|
13
|
+
**Full Changelog**: https://github.com/OpenWonderLabs/node-switchbot/compare/v1.1.2...v1.2.0
|
|
14
|
+
|
|
12
15
|
## [Version 1.1.2](https://github.com/OpenWonderLabs/node-switchbot/releases/tag/v1.1.2) (2021-11-13)
|
|
13
16
|
|
|
14
17
|
### Changes
|
|
15
18
|
|
|
16
19
|
- Housekeeping and update dependencies
|
|
17
20
|
|
|
21
|
+
**Full Changelog**: https://github.com/OpenWonderLabs/node-switchbot/compare/v1.1.1...v1.1.2
|
|
22
|
+
|
|
18
23
|
## [Version 1.1.1](https://github.com/OpenWonderLabs/node-switchbot/releases/tag/v1.1.1) (2021-11-02)
|
|
19
24
|
|
|
20
25
|
### Changes
|
|
21
26
|
|
|
22
27
|
- Change back from @node/noble to @abandonware/noble
|
|
23
28
|
|
|
29
|
+
**Full Changelog**: https://github.com/OpenWonderLabs/node-switchbot/compare/v1.1.0...v1.1.1
|
|
30
|
+
|
|
24
31
|
## [Version 1.1.0](https://github.com/OpenWonderLabs/node-switchbot/releases/tag/v1.1.0) (2021-10-26)
|
|
25
32
|
|
|
26
33
|
### Changes
|
|
@@ -29,24 +36,32 @@ All notable changes to this project will be documented in this file. This projec
|
|
|
29
36
|
- Add Humidifier advertisement
|
|
30
37
|
- Correct Model for advertisement
|
|
31
38
|
|
|
39
|
+
**Full Changelog**: https://github.com/OpenWonderLabs/node-switchbot/compare/v1.0.8...v1.1.0
|
|
40
|
+
|
|
32
41
|
## [Version 1.0.8](https://github.com/OpenWonderLabs/node-switchbot/releases/tag/v1.0.8) (2021-09-30)
|
|
33
42
|
|
|
34
43
|
### Changes
|
|
35
44
|
|
|
36
45
|
- fix extra trace of old noble from @abandonware/noble
|
|
37
46
|
|
|
47
|
+
**Full Changelog**: https://github.com/OpenWonderLabs/node-switchbot/compare/v1.0.7...v1.0.8
|
|
48
|
+
|
|
38
49
|
## [Version 1.0.7](https://github.com/OpenWonderLabs/node-switchbot/releases/tag/v1.0.7) (2021-09-24)
|
|
39
50
|
|
|
40
51
|
### Changes
|
|
41
52
|
|
|
42
53
|
- Change from @abandonware/noble to @homebridge/noble
|
|
43
54
|
|
|
55
|
+
**Full Changelog**: https://github.com/OpenWonderLabs/node-switchbot/compare/v1.0.6...v1.0.7
|
|
56
|
+
|
|
44
57
|
## [Version 1.0.6](https://github.com/OpenWonderLabs/node-switchbot/releases/tag/v1.0.6) (2021-08-29)
|
|
45
58
|
|
|
46
59
|
### Changes
|
|
47
60
|
|
|
48
61
|
- Fixes FATAL ERROR: ad_id is not defined
|
|
49
62
|
|
|
63
|
+
**Full Changelog**: https://github.com/OpenWonderLabs/node-switchbot/compare/v1.0.5...v1.0.6
|
|
64
|
+
|
|
50
65
|
## [Version 1.0.5](https://github.com/OpenWonderLabs/node-switchbot/releases/tag/v1.0.5) (2021-08-04)
|
|
51
66
|
|
|
52
67
|
### Changes
|
|
@@ -54,42 +69,56 @@ All notable changes to this project will be documented in this file. This projec
|
|
|
54
69
|
- Adding code for Contact and Motion Sensors
|
|
55
70
|
- Not Ready to be used yet though
|
|
56
71
|
|
|
72
|
+
**Full Changelog**: https://github.com/OpenWonderLabs/node-switchbot/compare/v1.0.4...v1.0.5
|
|
73
|
+
|
|
57
74
|
## [Version 1.0.4](https://github.com/OpenWonderLabs/node-switchbot/releases/tag/v1.0.4) (2021-08-03)
|
|
58
75
|
|
|
59
76
|
### Changes
|
|
60
77
|
|
|
61
78
|
- Support for the discover method with id on macOS
|
|
62
79
|
|
|
80
|
+
**Full Changelog**: https://github.com/OpenWonderLabs/node-switchbot/compare/v1.0.3...v1.0.4
|
|
81
|
+
|
|
63
82
|
## [Version 1.0.3](https://github.com/OpenWonderLabs/node-switchbot/releases/tag/v1.0.3) (2021-07-30)
|
|
64
83
|
|
|
65
84
|
### Changes
|
|
66
85
|
|
|
67
86
|
- Fixed misspelling.
|
|
68
87
|
|
|
88
|
+
**Full Changelog**: https://github.com/OpenWonderLabs/node-switchbot/compare/v1.0.2...v1.0.3
|
|
89
|
+
|
|
69
90
|
## [Version 1.0.2](https://github.com/OpenWonderLabs/node-switchbot/releases/tag/v1.0.2) (2021-07-29)
|
|
70
91
|
|
|
71
92
|
### Changes
|
|
72
93
|
|
|
73
94
|
- Housekeeping and update dependencies
|
|
74
95
|
|
|
96
|
+
**Full Changelog**: https://github.com/OpenWonderLabs/node-switchbot/compare/v1.0.1...v1.0.2
|
|
97
|
+
|
|
75
98
|
## [Version 1.0.1](https://github.com/OpenWonderLabs/node-switchbot/releases/tag/v1.0.1) (2021-07-29)
|
|
76
99
|
|
|
77
100
|
### Changes
|
|
78
101
|
|
|
79
102
|
- Fixed issue where after switching Bluetooth off and on, would not work properly.
|
|
80
103
|
|
|
104
|
+
**Full Changelog**: https://github.com/OpenWonderLabs/node-switchbot/compare/v1.0.0...v1.0.1
|
|
105
|
+
|
|
81
106
|
## [Version 1.0.0](https://github.com/OpenWonderLabs/node-switchbot/releases/tag/v1.0.0) (2021-01-21)
|
|
82
107
|
|
|
83
108
|
### Changes
|
|
84
109
|
|
|
85
110
|
- * fix "No device was found" in MacOS
|
|
86
111
|
|
|
112
|
+
**Full Changelog**: https://github.com/OpenWonderLabs/node-switchbot/compare/v0.2.0...v1.0.0
|
|
113
|
+
|
|
87
114
|
## [Version 0.2.0](https://github.com/OpenWonderLabs/node-switchbot/releases/tag/v0.2.0) (2020-11-05)
|
|
88
115
|
|
|
89
116
|
### Changes
|
|
90
117
|
|
|
91
118
|
- Modify Curtain's action command to support group and running mode. (Thanks to [@SwitchBot-Wonderlabs](https://github.com/OpenWonderLabs/node-switchbot/pull/7/))
|
|
92
119
|
|
|
120
|
+
**Full Changelog**: https://github.com/OpenWonderLabs/node-switchbot/compare/v0.1.0...v0.2.0
|
|
121
|
+
|
|
93
122
|
## [Version 0.1.0](https://github.com/OpenWonderLabs/node-switchbot/releases/tag/v0.1.0) (2020-10-28)
|
|
94
123
|
|
|
95
124
|
### Changes
|
|
@@ -97,18 +126,24 @@ All notable changes to this project will be documented in this file. This projec
|
|
|
97
126
|
- Added support for SwitchBot Curtain. (Thanks to [@SwitchBot-Wonderlabs](https://github.com/OpenWonderLabs/node-switchbot/pull/6/))
|
|
98
127
|
- Added support for running on the Raspberry Pi Zero W. (Thanks to [@zizi4n5](https://github.com/OpenWonderLabs/node-switchbot/pull/5))
|
|
99
128
|
|
|
129
|
+
**Full Changelog**: https://github.com/OpenWonderLabs/node-switchbot/compare/v0.0.5...v0.1.0
|
|
130
|
+
|
|
100
131
|
## [Version 0.0.5](https://github.com/OpenWonderLabs/node-switchbot/releases/tag/v0.0.5) (2020-02-19)
|
|
101
132
|
|
|
102
133
|
### Changes
|
|
103
134
|
|
|
104
135
|
- Improved the stability of discovering the BLE characteristics. (Thanks to [@dnicolson](https://github.com/OpenWonderLabs/node-switchbot/issues/3))
|
|
105
136
|
|
|
137
|
+
**Full Changelog**: https://github.com/OpenWonderLabs/node-switchbot/compare/v0.0.4...v0.0.5
|
|
138
|
+
|
|
106
139
|
## [Version 0.0.4](https://github.com/OpenWonderLabs/node-switchbot/releases/tag/v0.0.4) (2020-02-11)
|
|
107
140
|
|
|
108
141
|
### Changes
|
|
109
142
|
|
|
110
143
|
- Fixed the bug that temperature value lower than 0 degC could not be handled. (Thanks to [@musimasami](https://github.com/OpenWonderLabs/node-switchbot/issues/2))
|
|
111
144
|
|
|
145
|
+
**Full Changelog**: https://github.com/OpenWonderLabs/node-switchbot/compare/v0.0.3...v0.0.4
|
|
146
|
+
|
|
112
147
|
## [Version 0.0.3](https://github.com/OpenWonderLabs/node-switchbot/releases/tag/v0.0.3) (2020-02-10)
|
|
113
148
|
|
|
114
149
|
### Changes
|
|
@@ -116,6 +151,8 @@ All notable changes to this project will be documented in this file. This projec
|
|
|
116
151
|
- Now the characteristic UUID `0x2a00` (Device Name) is not mandatory. Some models of Bot don't seem to support the characteristic. (Thanks to [@dnicolson](https://github.com/OpenWonderLabs/node-switchbot/issues/1))
|
|
117
152
|
- Fixed the bug that the `turnOn()` method returns an error if the "Press mode" is selected on the Bot.
|
|
118
153
|
|
|
154
|
+
**Full Changelog**: https://github.com/OpenWonderLabs/node-switchbot/compare/v0.0.2...v0.0.3
|
|
155
|
+
|
|
119
156
|
## [Version 0.0.2](https://github.com/OpenWonderLabs/node-switchbot/releases/tag/v0.0.2) (2019-11-20)
|
|
120
157
|
|
|
121
158
|
### Changes
|
|
@@ -60,7 +60,7 @@ class SwitchbotAdvertising {
|
|
|
60
60
|
* If the specified `Peripheral` does not represent any switchbot
|
|
61
61
|
* device, this method will return `null`.
|
|
62
62
|
* ---------------------------------------------------------------- */
|
|
63
|
-
parse(peripheral) {
|
|
63
|
+
parse(peripheral, onlog) {
|
|
64
64
|
let ad = peripheral.advertisement;
|
|
65
65
|
if (!ad || !ad.serviceData) {
|
|
66
66
|
return null;
|
|
@@ -75,22 +75,38 @@ class SwitchbotAdvertising {
|
|
|
75
75
|
let sd = null;
|
|
76
76
|
|
|
77
77
|
if (model === 'H') { // WoHand
|
|
78
|
-
sd = this._parseServiceDataForWoHand(buf);
|
|
79
|
-
} else if (model === 'e') { // WoHumi
|
|
80
|
-
sd = this._parseServiceDataForWoHumi(buf);
|
|
78
|
+
sd = this._parseServiceDataForWoHand(buf, onlog);
|
|
81
79
|
} else if (model === 'T') { // WoSensorTH
|
|
82
|
-
sd = this._parseServiceDataForWoSensorTH(buf);
|
|
83
|
-
} else if (model === '
|
|
84
|
-
sd = this.
|
|
80
|
+
sd = this._parseServiceDataForWoSensorTH(buf, onlog);
|
|
81
|
+
} else if (model === 'e') { // WoHumi
|
|
82
|
+
sd = this._parseServiceDataForWoHumi(buf, onlog);
|
|
85
83
|
} else if (model === 's') { // WoMotion
|
|
86
|
-
sd = this._parseServiceDataForWoPresence(buf);
|
|
84
|
+
sd = this._parseServiceDataForWoPresence(buf, onlog);
|
|
87
85
|
} else if (model === 'd') { // WoContact
|
|
88
|
-
sd = this._parseServiceDataForWoContact(buf);
|
|
86
|
+
sd = this._parseServiceDataForWoContact(buf, onlog);
|
|
87
|
+
} else if (model === 'c') { // WoCurtain
|
|
88
|
+
sd = this._parseServiceDataForWoCurtain(buf, onlog);
|
|
89
|
+
} else if (model === 'u') { // WoColorBulb
|
|
90
|
+
sd = this._parseServiceDataForWoColorBulb(buf, onlog);
|
|
91
|
+
} else if (model === 'g') { // WoPlugMini
|
|
92
|
+
sd = this._parseServiceDataForWoPlugMini(buf, onlog);
|
|
93
|
+
} else if (model === 'o') { // WoSmartLock
|
|
94
|
+
sd = this._parseServiceDataForWoSmartLock(buf, onlog);
|
|
95
|
+
} else if (model === 'i') { // WoMeterPlus
|
|
96
|
+
sd = this._parseServiceDataForWoSensorTHPlus(buf, onlog);
|
|
97
|
+
} else if (model === 'r') { // WoLEDStripLight
|
|
98
|
+
sd = this._parseServiceDataForWoLEDStripLight(buf, onlog);
|
|
89
99
|
} else {
|
|
100
|
+
if (onlog && typeof onlog === 'function') {
|
|
101
|
+
onlog(`[parseAdvertising.${peripheral.id}] return null, model "${model}" not available!`);
|
|
102
|
+
}
|
|
90
103
|
return null;
|
|
91
104
|
}
|
|
92
105
|
|
|
93
106
|
if (!sd) {
|
|
107
|
+
if (onlog && typeof onlog === 'function') {
|
|
108
|
+
onlog(`[parseAdvertising.${peripheral.id}.${model}] return null, parsed serviceData empty!`);
|
|
109
|
+
}
|
|
94
110
|
return null;
|
|
95
111
|
}
|
|
96
112
|
let address = peripheral.address || '';
|
|
@@ -114,11 +130,18 @@ class SwitchbotAdvertising {
|
|
|
114
130
|
rssi: peripheral.rssi,
|
|
115
131
|
serviceData: sd
|
|
116
132
|
};
|
|
133
|
+
|
|
134
|
+
if (onlog && typeof onlog === 'function') {
|
|
135
|
+
onlog(`[parseAdvertising.${peripheral.id}.${model}] return ${JSON.stringify(data)}`);
|
|
136
|
+
}
|
|
117
137
|
return data;
|
|
118
138
|
}
|
|
119
139
|
|
|
120
|
-
_parseServiceDataForWoHand(buf) {
|
|
140
|
+
_parseServiceDataForWoHand(buf, onlog) {
|
|
121
141
|
if (buf.length !== 3) {
|
|
142
|
+
if (onlog && typeof onlog === 'function') {
|
|
143
|
+
onlog(`[_parseServiceDataForWoHand] Buffer length ${buf.length} !== 3!`);
|
|
144
|
+
}
|
|
122
145
|
return null;
|
|
123
146
|
}
|
|
124
147
|
let byte1 = buf.readUInt8(1);
|
|
@@ -139,33 +162,11 @@ class SwitchbotAdvertising {
|
|
|
139
162
|
return data;
|
|
140
163
|
}
|
|
141
164
|
|
|
142
|
-
|
|
143
|
-
if (buf.length !== 8) {
|
|
144
|
-
return null;
|
|
145
|
-
}
|
|
146
|
-
let byte1 = buf.readUInt8(1);
|
|
147
|
-
// let byte2 = buf.readUInt8(2);
|
|
148
|
-
let byte3 = buf.readUInt8(3);
|
|
149
|
-
let byte4 = buf.readUInt8(4);
|
|
150
|
-
let byte5 = buf.readUInt8(5);
|
|
151
|
-
|
|
152
|
-
let onState = (byte1 & 0b10000000) ? true : false; // 1 - on
|
|
153
|
-
let autoMode = (byte4 & 0b10000000) ? true : false; // 1 - auto
|
|
154
|
-
let percentage = byte4 & 0b01111111; // 0-100%, 101/102/103 - Quick gear 1/2/3
|
|
155
|
-
|
|
156
|
-
let data = {
|
|
157
|
-
model: 'e',
|
|
158
|
-
modelName: 'WoHumi',
|
|
159
|
-
onState: onState,
|
|
160
|
-
autoMode: autoMode,
|
|
161
|
-
percentage: autoMode ? 0 : percentage,
|
|
162
|
-
};
|
|
163
|
-
|
|
164
|
-
return data;
|
|
165
|
-
}
|
|
166
|
-
|
|
167
|
-
_parseServiceDataForWoSensorTH(buf) {
|
|
165
|
+
_parseServiceDataForWoSensorTH(buf, onlog) {
|
|
168
166
|
if (buf.length !== 6) {
|
|
167
|
+
if (onlog && typeof onlog === 'function') {
|
|
168
|
+
onlog(`[_parseServiceDataForWoSensorTH] Buffer length ${buf.length} !== 6!`);
|
|
169
|
+
}
|
|
169
170
|
return null;
|
|
170
171
|
}
|
|
171
172
|
let byte2 = buf.readUInt8(2);
|
|
@@ -193,8 +194,39 @@ class SwitchbotAdvertising {
|
|
|
193
194
|
return data;
|
|
194
195
|
}
|
|
195
196
|
|
|
196
|
-
|
|
197
|
+
_parseServiceDataForWoHumi(buf, onlog) {
|
|
198
|
+
if (buf.length !== 8) {
|
|
199
|
+
if (onlog && typeof onlog === 'function') {
|
|
200
|
+
onlog(`[_parseServiceDataForWoHumi] Buffer length ${buf.length} !== 8!`);
|
|
201
|
+
}
|
|
202
|
+
return null;
|
|
203
|
+
}
|
|
204
|
+
let byte1 = buf.readUInt8(1);
|
|
205
|
+
// let byte2 = buf.readUInt8(2);
|
|
206
|
+
let byte3 = buf.readUInt8(3);
|
|
207
|
+
let byte4 = buf.readUInt8(4);
|
|
208
|
+
let byte5 = buf.readUInt8(5);
|
|
209
|
+
|
|
210
|
+
let onState = (byte1 & 0b10000000) ? true : false; // 1 - on
|
|
211
|
+
let autoMode = (byte4 & 0b10000000) ? true : false; // 1 - auto
|
|
212
|
+
let percentage = byte4 & 0b01111111; // 0-100%, 101/102/103 - Quick gear 1/2/3
|
|
213
|
+
|
|
214
|
+
let data = {
|
|
215
|
+
model: 'e',
|
|
216
|
+
modelName: 'WoHumi',
|
|
217
|
+
onState: onState,
|
|
218
|
+
autoMode: autoMode,
|
|
219
|
+
percentage: autoMode ? 0 : percentage,
|
|
220
|
+
};
|
|
221
|
+
|
|
222
|
+
return data;
|
|
223
|
+
}
|
|
224
|
+
|
|
225
|
+
_parseServiceDataForWoPresence(buf, onlog) {
|
|
197
226
|
if (buf.length !== 6) {
|
|
227
|
+
if (onlog && typeof onlog === 'function') {
|
|
228
|
+
onlog(`[_parseServiceDataForWoPresence] Buffer length ${buf.length} !== 6!`);
|
|
229
|
+
}
|
|
198
230
|
return null;
|
|
199
231
|
}
|
|
200
232
|
let byte1 = buf.readUInt8(1);
|
|
@@ -218,8 +250,11 @@ class SwitchbotAdvertising {
|
|
|
218
250
|
return data;
|
|
219
251
|
}
|
|
220
252
|
|
|
221
|
-
_parseServiceDataForWoContact(buf) {
|
|
253
|
+
_parseServiceDataForWoContact(buf, onlog) {
|
|
222
254
|
if (buf.length !== 9) {
|
|
255
|
+
if (onlog && typeof onlog === 'function') {
|
|
256
|
+
onlog(`[_parseServiceDataForWoContact] Buffer length ${buf.length} !== 9!`);
|
|
257
|
+
}
|
|
223
258
|
return null;
|
|
224
259
|
}
|
|
225
260
|
|
|
@@ -249,14 +284,18 @@ class SwitchbotAdvertising {
|
|
|
249
284
|
return data;
|
|
250
285
|
}
|
|
251
286
|
|
|
252
|
-
_parseServiceDataForWoCurtain(buf) {
|
|
253
|
-
if (buf.length !== 5) {
|
|
287
|
+
_parseServiceDataForWoCurtain(buf, onlog) {
|
|
288
|
+
if (buf.length !== 5 && buf.length !== 6) {
|
|
289
|
+
if (onlog && typeof onlog === 'function') {
|
|
290
|
+
onlog(`[_parseServiceDataForWoCurtain] Buffer length ${buf.length} !== 5 or 6!`);
|
|
291
|
+
}
|
|
254
292
|
return null;
|
|
255
293
|
}
|
|
256
294
|
let byte1 = buf.readUInt8(1);
|
|
257
295
|
let byte2 = buf.readUInt8(2);
|
|
258
296
|
let byte3 = buf.readUInt8(3);
|
|
259
297
|
let byte4 = buf.readUInt8(4);
|
|
298
|
+
// let byte5 = buf.readUInt8(5);
|
|
260
299
|
|
|
261
300
|
let calibration = (byte1 & 0b01000000) ? true : false; // Whether the calibration is completed
|
|
262
301
|
let battery = byte2 & 0b01111111; // %
|
|
@@ -274,6 +313,129 @@ class SwitchbotAdvertising {
|
|
|
274
313
|
|
|
275
314
|
return data;
|
|
276
315
|
}
|
|
316
|
+
|
|
317
|
+
_parseServiceDataForWoColorBulb(buf, onlog) {
|
|
318
|
+
if (buf.length !== 6) {
|
|
319
|
+
if (onlog && typeof onlog === 'function') {
|
|
320
|
+
onlog(`[_parseServiceDataForWoColorBulb] Buffer length ${buf.length} !== 6!`);
|
|
321
|
+
}
|
|
322
|
+
return null;
|
|
323
|
+
}
|
|
324
|
+
let byte1 = buf.readUInt8(1);
|
|
325
|
+
let byte2 = buf.readUInt8(2);
|
|
326
|
+
// let byte3 = buf.readUInt8(3);
|
|
327
|
+
// let byte4 = buf.readUInt8(4);
|
|
328
|
+
let byte5 = buf.readUInt8(5);
|
|
329
|
+
|
|
330
|
+
let data = {
|
|
331
|
+
model: 'u',
|
|
332
|
+
modelName: 'WoColorBulb',
|
|
333
|
+
};
|
|
334
|
+
|
|
335
|
+
return data;
|
|
336
|
+
}
|
|
337
|
+
|
|
338
|
+
_parseServiceDataForWoPlugMini(buf, onlog) {
|
|
339
|
+
if (buf.length !== 6) {
|
|
340
|
+
if (onlog && typeof onlog === 'function') {
|
|
341
|
+
onlog(`[_parseServiceDataForWoPlugMini] Buffer length ${buf.length} !== 6!`);
|
|
342
|
+
}
|
|
343
|
+
return null;
|
|
344
|
+
}
|
|
345
|
+
let byte1 = buf.readUInt8(1);
|
|
346
|
+
let byte2 = buf.readUInt8(2);
|
|
347
|
+
// let byte3 = buf.readUInt8(3);
|
|
348
|
+
// let byte4 = buf.readUInt8(4);
|
|
349
|
+
let byte5 = buf.readUInt8(5);
|
|
350
|
+
|
|
351
|
+
let data = {
|
|
352
|
+
model: 'g',
|
|
353
|
+
modelName: 'WoPlugMini',
|
|
354
|
+
};
|
|
355
|
+
|
|
356
|
+
return data;
|
|
357
|
+
}
|
|
358
|
+
|
|
359
|
+
_parseServiceDataForWoSmartLock(buf, onlog) {
|
|
360
|
+
if (buf.length !== 6) {
|
|
361
|
+
if (onlog && typeof onlog === 'function') {
|
|
362
|
+
onlog(`[_parseServiceDataForWoSmartLock] Buffer length ${buf.length} !== 6!`);
|
|
363
|
+
}
|
|
364
|
+
return null;
|
|
365
|
+
}
|
|
366
|
+
let byte1 = buf.readUInt8(1);
|
|
367
|
+
let byte2 = buf.readUInt8(2);
|
|
368
|
+
// let byte3 = buf.readUInt8(3);
|
|
369
|
+
// let byte4 = buf.readUInt8(4);
|
|
370
|
+
let byte5 = buf.readUInt8(5);
|
|
371
|
+
|
|
372
|
+
//let pirState = (byte1 & 0b01000000) ? true : false; // 1 - Movement detected
|
|
373
|
+
let battery = byte2 & 0b01111111; // %
|
|
374
|
+
//let lightLevel = byte5 & 0b00000011;
|
|
375
|
+
|
|
376
|
+
let data = {
|
|
377
|
+
model: 'o',
|
|
378
|
+
modelName: 'WoSmartLock',
|
|
379
|
+
//movement: pirState,
|
|
380
|
+
battery: battery,
|
|
381
|
+
//lightLevel: (lightLevel == 1) ? 'dark' : ((lightLevel == 2) ? 'bright' : 'unknown'),
|
|
382
|
+
};
|
|
383
|
+
|
|
384
|
+
return data;
|
|
385
|
+
}
|
|
386
|
+
|
|
387
|
+
_parseServiceDataForWoSensorTHPlus(buf, onlog) {
|
|
388
|
+
if (buf.length !== 6) {
|
|
389
|
+
if (onlog && typeof onlog === 'function') {
|
|
390
|
+
onlog(`[_parseServiceDataForWoSensorTHPlus] Buffer length ${buf.length} !== 6!`);
|
|
391
|
+
}
|
|
392
|
+
return null;
|
|
393
|
+
}
|
|
394
|
+
let byte2 = buf.readUInt8(2);
|
|
395
|
+
let byte3 = buf.readUInt8(3);
|
|
396
|
+
let byte4 = buf.readUInt8(4);
|
|
397
|
+
let byte5 = buf.readUInt8(5);
|
|
398
|
+
|
|
399
|
+
let temp_sign = (byte4 & 0b10000000) ? 1 : -1;
|
|
400
|
+
let temp_c = temp_sign * ((byte4 & 0b01111111) + (byte3 / 10));
|
|
401
|
+
let temp_f = (temp_c * 9 / 5) + 32;
|
|
402
|
+
temp_f = Math.round(temp_f * 10) / 10;
|
|
403
|
+
|
|
404
|
+
let data = {
|
|
405
|
+
model: 'i',
|
|
406
|
+
modelName: 'WoSensorTHPlus',
|
|
407
|
+
temperature: {
|
|
408
|
+
c: temp_c,
|
|
409
|
+
f: temp_f
|
|
410
|
+
},
|
|
411
|
+
fahrenheit: (byte5 & 0b10000000) ? true : false,
|
|
412
|
+
humidity: byte5 & 0b01111111,
|
|
413
|
+
battery: (byte2 & 0b01111111)
|
|
414
|
+
};
|
|
415
|
+
|
|
416
|
+
return data;
|
|
417
|
+
}
|
|
418
|
+
|
|
419
|
+
_parseServiceDataForWoLEDStripLight(buf, onlog) {
|
|
420
|
+
if (buf.length !== 6) {
|
|
421
|
+
if (onlog && typeof onlog === 'function') {
|
|
422
|
+
onlog(`[_parseServiceDataForWoLEDStripLight] Buffer length ${buf.length} !== 6!`);
|
|
423
|
+
}
|
|
424
|
+
return null;
|
|
425
|
+
}
|
|
426
|
+
let byte1 = buf.readUInt8(1);
|
|
427
|
+
let byte2 = buf.readUInt8(2);
|
|
428
|
+
// let byte3 = buf.readUInt8(3);
|
|
429
|
+
// let byte4 = buf.readUInt8(4);
|
|
430
|
+
let byte5 = buf.readUInt8(5);
|
|
431
|
+
|
|
432
|
+
let data = {
|
|
433
|
+
model: 'r',
|
|
434
|
+
modelName: 'WoLEDStripLight',
|
|
435
|
+
};
|
|
436
|
+
|
|
437
|
+
return data;
|
|
438
|
+
}
|
|
277
439
|
}
|
|
278
440
|
|
|
279
441
|
module.exports = new SwitchbotAdvertising();
|
package/lib/switchbot.js
CHANGED
|
@@ -34,6 +34,7 @@ class Switchbot {
|
|
|
34
34
|
this.noble = noble;
|
|
35
35
|
this.ondiscover = null;
|
|
36
36
|
this.onadvertisement = null;
|
|
37
|
+
this.onlog = null;
|
|
37
38
|
|
|
38
39
|
// Private properties
|
|
39
40
|
this._scanning = false;
|
|
@@ -50,13 +51,18 @@ class Switchbot {
|
|
|
50
51
|
* - duration | Integer | Optional | Duration for discovery process (msec).
|
|
51
52
|
* | | | The value must be in the range of 1 to 60000.
|
|
52
53
|
* | | | The default value is 5000 (msec).
|
|
53
|
-
* - model | String | Optional | "H", "T", "e", "s", "d", or "
|
|
54
|
+
* - model | String | Optional | "H", "T", "e", "s", "d", "c", "u", "g", "o", "i", or "r".
|
|
54
55
|
* | | | If "H" is specified, this method will discover only Bots.
|
|
55
56
|
* | | | If "T" is specified, this method will discover only Meters.
|
|
56
57
|
* | | | If "e" is specified, this method will discover only Humidifiers.
|
|
57
58
|
* | | | If "s" is specified, this method will discover only Motion Sensors.
|
|
58
59
|
* | | | If "d" is specified, this method will discover only Contact Sensors.
|
|
59
60
|
* | | | If "c" is specified, this method will discover only Curtains.
|
|
61
|
+
* | | | If "u" is specified, this method will discover only Color Bulbs.
|
|
62
|
+
* | | | If "g" is specified, this method will discover only Plugs.
|
|
63
|
+
* | | | If "o" is specified, this method will discover only Locks.
|
|
64
|
+
* | | | If "i" is specified, this method will discover only Meter Pluses.
|
|
65
|
+
* | | | If "r" is specified, this method will discover only Locks.
|
|
60
66
|
* - id | String | Optional | If this value is set, this method will discover
|
|
61
67
|
* | | | only a device whose ID is as same as this value.
|
|
62
68
|
* | | | The ID is identical to the MAC address.
|
|
@@ -78,7 +84,7 @@ class Switchbot {
|
|
|
78
84
|
// Check the parameters
|
|
79
85
|
let valid = parameterChecker.check(params, {
|
|
80
86
|
duration: { required: false, type: 'integer', min: 1, max: 60000 },
|
|
81
|
-
model: { required: false, type: 'string', enum: ['H', 'T', 'e', 's', 'd', 'c'] },
|
|
87
|
+
model: { required: false, type: 'string', enum: ['H', 'T', 'e', 's', 'd', 'c', 'u', 'g', 'o', 'i', 'r'] },
|
|
82
88
|
id: { required: false, type: 'string', min: 12, max: 17 },
|
|
83
89
|
quick: { required: false, type: 'boolean' }
|
|
84
90
|
}, false);
|
|
@@ -178,19 +184,19 @@ class Switchbot {
|
|
|
178
184
|
}
|
|
179
185
|
|
|
180
186
|
_getDeviceObject(peripheral, id, model) {
|
|
181
|
-
let ad = switchbotAdvertising.parse(peripheral);
|
|
187
|
+
let ad = switchbotAdvertising.parse(peripheral, this.onlog);
|
|
182
188
|
if (this._filterAdvertising(ad, id, model)) {
|
|
183
189
|
let device = null;
|
|
184
190
|
switch (ad.serviceData.model) {
|
|
185
191
|
case 'H':
|
|
186
192
|
device = new SwitchbotDeviceWoHand(peripheral, this.noble);
|
|
187
193
|
break;
|
|
188
|
-
case 'e':
|
|
189
|
-
device = new SwitchbotDeviceWoHumi(peripheral, this.noble);
|
|
190
|
-
break;
|
|
191
194
|
case 'T':
|
|
192
195
|
device = new SwitchbotDeviceWoSensorTH(peripheral, this.noble);
|
|
193
196
|
break;
|
|
197
|
+
case 'e':
|
|
198
|
+
device = new SwitchbotDeviceWoHumi(peripheral, this.noble);
|
|
199
|
+
break;
|
|
194
200
|
case 's':
|
|
195
201
|
device = new SwitchbotDeviceWoPresence(peripheral, this.noble);
|
|
196
202
|
break;
|
|
@@ -200,6 +206,21 @@ class Switchbot {
|
|
|
200
206
|
case 'c':
|
|
201
207
|
device = new SwitchbotDeviceWoCurtain(peripheral, this.noble);
|
|
202
208
|
break;
|
|
209
|
+
case 'u':
|
|
210
|
+
device = new SwitchbotDeviceWoColorBulb(peripheral, this.noble);
|
|
211
|
+
break;
|
|
212
|
+
case 'g':
|
|
213
|
+
device = new SwitchbotDeviceWoPlugMini(peripheral, this.noble);
|
|
214
|
+
break;
|
|
215
|
+
case 'o':
|
|
216
|
+
device = new SwitchbotDeviceWoSmartLock(peripheral, this.noble);
|
|
217
|
+
break;
|
|
218
|
+
case 'i':
|
|
219
|
+
device = new SwitchbotDeviceWoSensorTHPlus(peripheral, this.noble);
|
|
220
|
+
break;
|
|
221
|
+
case 'r':
|
|
222
|
+
device = new SwitchbotDeviceWoLEDStripLight(peripheral, this.noble);
|
|
223
|
+
break;
|
|
203
224
|
default: // 'resetting', 'unknown'
|
|
204
225
|
device = new SwitchbotDevice(peripheral, this.noble);
|
|
205
226
|
}
|
|
@@ -234,7 +255,7 @@ class Switchbot {
|
|
|
234
255
|
*
|
|
235
256
|
* [Arguments]
|
|
236
257
|
* - params | Object | Optional |
|
|
237
|
-
* - model | String | Optional | "H", "T", "e", "s", "d", or "
|
|
258
|
+
* - model | String | Optional | "H", "T", "e", "s", "d", "c", "u", "g", "o", "i", or "r".
|
|
238
259
|
* | | | If "H" is specified, the `onadvertisement`
|
|
239
260
|
* | | | event handler will be called only when advertising
|
|
240
261
|
* | | | packets comes from Bots.
|
|
@@ -253,6 +274,21 @@ class Switchbot {
|
|
|
253
274
|
* | | | If "c" is specified, the `onadvertisement`
|
|
254
275
|
* | | | event handler will be called only when advertising
|
|
255
276
|
* | | | packets comes from Curtains.
|
|
277
|
+
* | | | If "u" is specified, the `onadvertisement`
|
|
278
|
+
* | | | event handler will be called only when advertising
|
|
279
|
+
* | | | packets comes from Color Bulb.
|
|
280
|
+
* | | | If "g" is specified, the `onadvertisement`
|
|
281
|
+
* | | | event handler will be called only when advertising
|
|
282
|
+
* | | | packets comes from Plug Mini.
|
|
283
|
+
* | | | If "o" is specified, the `onadvertisement`
|
|
284
|
+
* | | | event handler will be called only when advertising
|
|
285
|
+
* | | | packets comes from Smart Lock.
|
|
286
|
+
* | | | If "i" is specified, the `onadvertisement`
|
|
287
|
+
* | | | event handler will be called only when advertising
|
|
288
|
+
* | | | packets comes from Meter Plus.
|
|
289
|
+
* | | | If "r" is specified, the `onadvertisement`
|
|
290
|
+
* | | | event handler will be called only when advertising
|
|
291
|
+
* | | | packets comes from LED Strip Light.
|
|
256
292
|
* - id | String | Optional | If this value is set, the `onadvertisement`
|
|
257
293
|
* | | | event handler will be called only when advertising
|
|
258
294
|
* | | | packets comes from devices whose ID is as same as
|
|
@@ -269,7 +305,7 @@ class Switchbot {
|
|
|
269
305
|
let promise = new Promise((resolve, reject) => {
|
|
270
306
|
// Check the parameters
|
|
271
307
|
let valid = parameterChecker.check(params, {
|
|
272
|
-
model: { required: false, type: 'string', enum: ['H', 'T', 'e', 's', 'd', 'c'] },
|
|
308
|
+
model: { required: false, type: 'string', enum: ['H', 'T', 'e', 's', 'd', 'c', 'u', 'g', 'o', 'i', 'r'] },
|
|
273
309
|
id: { required: false, type: 'string', min: 12, max: 17 },
|
|
274
310
|
}, false);
|
|
275
311
|
|
|
@@ -293,7 +329,7 @@ class Switchbot {
|
|
|
293
329
|
|
|
294
330
|
// Set a handler for the 'discover' event
|
|
295
331
|
this.noble.on('discover', (peripheral) => {
|
|
296
|
-
let ad = switchbotAdvertising.parse(peripheral);
|
|
332
|
+
let ad = switchbotAdvertising.parse(peripheral, this.onlog);
|
|
297
333
|
if (this._filterAdvertising(ad, p.id, p.model)) {
|
|
298
334
|
if (this.onadvertisement && typeof (this.onadvertisement) === 'function') {
|
|
299
335
|
this.onadvertisement(ad);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "node-switchbot",
|
|
3
|
-
"version": "1.1
|
|
3
|
+
"version": "1.2.1-beta.0",
|
|
4
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
5
|
"main": "./lib/switchbot.js",
|
|
6
6
|
"files": [
|
|
@@ -37,6 +37,6 @@
|
|
|
37
37
|
"@abandonware/noble": "^1.9.2-15"
|
|
38
38
|
},
|
|
39
39
|
"devDependencies": {
|
|
40
|
-
"npm-check-updates": "^12.5.
|
|
40
|
+
"npm-check-updates": "^12.5.2"
|
|
41
41
|
}
|
|
42
42
|
}
|