node-switchbot 1.10.0 → 2.0.0-beta.1
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/.gitattributes +2 -0
- package/.github/dependabot.yml +17 -0
- package/.github/labeler.yml +38 -0
- package/.github/npm-version-script.cjs +81 -0
- package/.github/workflows/beta-release.yml +31 -0
- package/.github/workflows/build.yml +18 -0
- package/.github/workflows/changerelease.yml +13 -0
- package/.github/workflows/dependabot.yml +17 -0
- package/.github/workflows/labeler.yml +16 -0
- package/.github/workflows/release-drafter.yml +14 -0
- package/.github/workflows/release.yml +24 -0
- package/.github/workflows/stale.yml +12 -0
- package/CHANGELOG.md +308 -0
- package/dist/advertising.d.ts +172 -0
- package/dist/advertising.d.ts.map +1 -0
- package/dist/advertising.js +620 -0
- package/dist/advertising.js.map +1 -0
- package/dist/device/woblindtilt.d.ts +9 -0
- package/dist/device/woblindtilt.d.ts.map +1 -0
- package/dist/device/woblindtilt.js +108 -0
- package/dist/device/woblindtilt.js.map +1 -0
- package/dist/device/wobulb.d.ts +39 -0
- package/dist/device/wobulb.d.ts.map +1 -0
- package/dist/device/wobulb.js +156 -0
- package/dist/device/wobulb.js.map +1 -0
- package/dist/device/wocontact.d.ts +4 -0
- package/dist/device/wocontact.d.ts.map +1 -0
- package/dist/device/wocontact.js +8 -0
- package/dist/device/wocontact.js.map +1 -0
- package/dist/device/wocurtain.d.ts +9 -0
- package/dist/device/wocurtain.d.ts.map +1 -0
- package/dist/device/wocurtain.js +104 -0
- package/dist/device/wocurtain.js.map +1 -0
- package/dist/device/wohand.d.ts +10 -0
- package/dist/device/wohand.d.ts.map +1 -0
- package/dist/device/wohand.js +93 -0
- package/dist/device/wohand.js.map +1 -0
- package/dist/device/wohumi.d.ts +10 -0
- package/dist/device/wohumi.d.ts.map +1 -0
- package/dist/device/wohumi.js +93 -0
- package/dist/device/wohumi.js.map +1 -0
- package/dist/device/woiosensorth.d.ts +4 -0
- package/dist/device/woiosensorth.d.ts.map +1 -0
- package/dist/device/woiosensorth.js +4 -0
- package/dist/device/woiosensorth.js.map +1 -0
- package/dist/device/woplugmini.d.ts +31 -0
- package/dist/device/woplugmini.d.ts.map +1 -0
- package/dist/device/woplugmini.js +68 -0
- package/dist/device/woplugmini.js.map +1 -0
- package/dist/device/wopresence.d.ts +4 -0
- package/dist/device/wopresence.d.ts.map +1 -0
- package/dist/device/wopresence.js +4 -0
- package/dist/device/wopresence.js.map +1 -0
- package/dist/device/wosensorth.d.ts +4 -0
- package/dist/device/wosensorth.d.ts.map +1 -0
- package/dist/device/wosensorth.js +4 -0
- package/dist/device/wosensorth.js.map +1 -0
- package/dist/device/wostrip.d.ts +39 -0
- package/dist/device/wostrip.d.ts.map +1 -0
- package/dist/device/wostrip.js +145 -0
- package/dist/device/wostrip.js.map +1 -0
- package/dist/device.d.ts +46 -0
- package/dist/device.d.ts.map +1 -0
- package/dist/device.js +498 -0
- package/dist/device.js.map +1 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +6 -0
- package/dist/index.js.map +1 -0
- package/dist/parameter-checker.d.ts +25 -0
- package/dist/parameter-checker.d.ts.map +1 -0
- package/dist/parameter-checker.js +488 -0
- package/dist/parameter-checker.js.map +1 -0
- package/dist/switchbot.d.ts +29 -0
- package/dist/switchbot.d.ts.map +1 -0
- package/dist/switchbot.js +461 -0
- package/dist/switchbot.js.map +1 -0
- package/package.json +19 -12
- package/lib/parameter-checker.js +0 -524
- package/lib/switchbot-advertising.js +0 -713
- package/lib/switchbot-device-woblindtilt.js +0 -120
- package/lib/switchbot-device-wobulb.js +0 -188
- package/lib/switchbot-device-wocontact.js +0 -6
- package/lib/switchbot-device-wocurtain.js +0 -117
- package/lib/switchbot-device-wohand.js +0 -106
- package/lib/switchbot-device-wohumi.js +0 -106
- package/lib/switchbot-device-woiosensorth.js +0 -6
- package/lib/switchbot-device-woplugmini.js +0 -84
- package/lib/switchbot-device-wopresence.js +0 -6
- package/lib/switchbot-device-wosensorth.js +0 -6
- package/lib/switchbot-device-wostrip.js +0 -182
- package/lib/switchbot-device.js +0 -536
- package/lib/switchbot.js +0 -496
|
@@ -1,713 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
const { Buffer } = require('buffer');
|
|
4
|
-
|
|
5
|
-
class SwitchbotAdvertising {
|
|
6
|
-
constructor() {}
|
|
7
|
-
|
|
8
|
-
/* ------------------------------------------------------------------
|
|
9
|
-
* parse(peripheral)
|
|
10
|
-
* - Parse advertising packets coming from switchbot devices
|
|
11
|
-
*
|
|
12
|
-
* [Arguments]
|
|
13
|
-
* - peripheral | Object | Required | A `Peripheral` object of noble
|
|
14
|
-
*
|
|
15
|
-
* [Return value]
|
|
16
|
-
* - An object as follows:
|
|
17
|
-
*
|
|
18
|
-
* WoHand
|
|
19
|
-
* {
|
|
20
|
-
* id: 'c12e453e2008',
|
|
21
|
-
* address: 'c1:2e:45:3e:20:08',
|
|
22
|
-
* rssi: -43,
|
|
23
|
-
* serviceData: {
|
|
24
|
-
* model: 'H',
|
|
25
|
-
* modelName: 'WoHand',
|
|
26
|
-
* mode: false,
|
|
27
|
-
* state: false,
|
|
28
|
-
* battery: 95
|
|
29
|
-
* }
|
|
30
|
-
* }
|
|
31
|
-
*
|
|
32
|
-
* WoSensorTH
|
|
33
|
-
* {
|
|
34
|
-
* id: 'cb4eb903c96d',
|
|
35
|
-
* address: 'cb:4e:b9:03:c9:6d',
|
|
36
|
-
* rssi: -54,
|
|
37
|
-
* serviceData: {
|
|
38
|
-
* model: 'T',
|
|
39
|
-
* modelName: 'WoSensorTH',
|
|
40
|
-
* temperature: { c: 26.2, f: 79.2 },
|
|
41
|
-
* fahrenheit: false,
|
|
42
|
-
* humidity: 45,
|
|
43
|
-
* battery: 100
|
|
44
|
-
* }
|
|
45
|
-
* }
|
|
46
|
-
*
|
|
47
|
-
* WoCurtain
|
|
48
|
-
* {
|
|
49
|
-
* id: 'ec58c5d00111',
|
|
50
|
-
* address: 'ec:58:c5:d0:01:11',
|
|
51
|
-
* rssi: -39,
|
|
52
|
-
* serviceData: {
|
|
53
|
-
* model: 'c',
|
|
54
|
-
* modelName: 'WoCurtain',
|
|
55
|
-
* calibration: true,
|
|
56
|
-
* battery: 91,
|
|
57
|
-
* position: 1,
|
|
58
|
-
* lightLevel: 1
|
|
59
|
-
* }
|
|
60
|
-
* }
|
|
61
|
-
*
|
|
62
|
-
* If the specified `Peripheral` does not represent any switchbot
|
|
63
|
-
* device, this method will return `null`.
|
|
64
|
-
* ---------------------------------------------------------------- */
|
|
65
|
-
parse(peripheral, onlog) {
|
|
66
|
-
const ad = peripheral.advertisement;
|
|
67
|
-
if (!ad || !ad.serviceData) {
|
|
68
|
-
return null;
|
|
69
|
-
}
|
|
70
|
-
const serviceData = ad.serviceData[0] || ad.serviceData;
|
|
71
|
-
const manufacturerData = ad.manufacturerData;
|
|
72
|
-
const buf = serviceData.data;
|
|
73
|
-
|
|
74
|
-
const bufIsInvalid = !buf || !Buffer.isBuffer(buf) || buf.length < 3;
|
|
75
|
-
const manufacturerDataIsInvalid =
|
|
76
|
-
!manufacturerData ||
|
|
77
|
-
!Buffer.isBuffer(manufacturerData) ||
|
|
78
|
-
manufacturerData.length < 3;
|
|
79
|
-
|
|
80
|
-
if (bufIsInvalid || manufacturerDataIsInvalid) {
|
|
81
|
-
return null;
|
|
82
|
-
}
|
|
83
|
-
|
|
84
|
-
const model = buf.slice(0, 1).toString("utf8");
|
|
85
|
-
let sd = null;
|
|
86
|
-
|
|
87
|
-
if (model === "H") {
|
|
88
|
-
sd = this._parseServiceDataForWoHand(buf, onlog);//WoHand
|
|
89
|
-
} else if (model === "T") {
|
|
90
|
-
sd = this._parseServiceDataForWoSensorTH(buf, onlog);//WoSensorTH
|
|
91
|
-
} else if (model === "e") {
|
|
92
|
-
sd = this._parseServiceDataForWoHumi(buf, onlog);//WoHumi
|
|
93
|
-
} else if (model === "s") {
|
|
94
|
-
sd = this._parseServiceDataForWoPresence(buf, onlog);//WoPresence
|
|
95
|
-
} else if (model === "d") {
|
|
96
|
-
sd = this._parseServiceDataForWoContact(buf, onlog);//WoContact
|
|
97
|
-
} else if (model === "c" || model === "{") {
|
|
98
|
-
sd = this._parseServiceDataForWoCurtain(buf, onlog);// WoCurtain
|
|
99
|
-
} else if (model === "x") {
|
|
100
|
-
sd = this._parseServiceDataForWoBlindTilt(buf, onlog);// WoBlindTilt
|
|
101
|
-
} else if (model === "u") {
|
|
102
|
-
sd = this._parseServiceDataForWoBulb(manufacturerData, onlog);// WoBulb
|
|
103
|
-
} else if (model === "g") {
|
|
104
|
-
sd = this._parseServiceDataForWoPlugMiniUS(manufacturerData, onlog); // WoPlugMini (US)
|
|
105
|
-
} else if (model === "j") {
|
|
106
|
-
sd = this._parseServiceDataForWoPlugMiniJP(manufacturerData, onlog);// WoPlugMini (JP)
|
|
107
|
-
} else if (model === "o") {
|
|
108
|
-
sd = this._parseServiceDataForWoSmartLock(manufacturerData, onlog);// WoSmartLock
|
|
109
|
-
} else if (model === "i") {
|
|
110
|
-
sd = this._parseServiceDataForWoSensorTHPlus(buf, onlog);// WoMeterPlus
|
|
111
|
-
} else if (model === "r") {
|
|
112
|
-
sd = this._parseServiceDataForWoStrip(buf, onlog);// WoStrip
|
|
113
|
-
} else if (model === "w") {
|
|
114
|
-
sd = this._parseServiceDataForWoIOSensorTH(buf, manufacturerData, onlog); // Indoor/Outdoor Thermo-Hygrometer
|
|
115
|
-
} else {
|
|
116
|
-
if (onlog && typeof onlog === "function") {
|
|
117
|
-
onlog(
|
|
118
|
-
`[parseAdvertising.${peripheral.id}] return null, model "${model}" not available!`
|
|
119
|
-
);
|
|
120
|
-
}
|
|
121
|
-
return null;
|
|
122
|
-
}
|
|
123
|
-
|
|
124
|
-
if (!sd) {
|
|
125
|
-
if (onlog && typeof onlog === "function") {
|
|
126
|
-
onlog(
|
|
127
|
-
`[parseAdvertising.${peripheral.id}.${model}] return null, parsed serviceData empty!`
|
|
128
|
-
);
|
|
129
|
-
}
|
|
130
|
-
return null;
|
|
131
|
-
}
|
|
132
|
-
let address = peripheral.address || "";
|
|
133
|
-
if (address === "") {
|
|
134
|
-
address = peripheral.advertisement.manufacturerData || "";
|
|
135
|
-
if (address !== "") {
|
|
136
|
-
const str = peripheral.advertisement.manufacturerData
|
|
137
|
-
.toString("hex")
|
|
138
|
-
.slice(4, 16);
|
|
139
|
-
address = str.substr(0, 2);
|
|
140
|
-
for (var i = 2; i < str.length; i += 2) {
|
|
141
|
-
address = address + ":" + str.substr(i, 2);
|
|
142
|
-
}
|
|
143
|
-
// console.log("address", typeof(address), address);
|
|
144
|
-
}
|
|
145
|
-
} else {
|
|
146
|
-
address = address.replace(/-/g, ":");
|
|
147
|
-
}
|
|
148
|
-
const data = {
|
|
149
|
-
id: peripheral.id,
|
|
150
|
-
address: address,
|
|
151
|
-
rssi: peripheral.rssi,
|
|
152
|
-
serviceData: sd,
|
|
153
|
-
};
|
|
154
|
-
|
|
155
|
-
if (onlog && typeof onlog === "function") {
|
|
156
|
-
onlog(
|
|
157
|
-
`[parseAdvertising.${peripheral.id}.${model}] return ${JSON.stringify(
|
|
158
|
-
data
|
|
159
|
-
)}`
|
|
160
|
-
);
|
|
161
|
-
}
|
|
162
|
-
return data;
|
|
163
|
-
}
|
|
164
|
-
|
|
165
|
-
_parseServiceDataForWoHand(buf, onlog) {
|
|
166
|
-
if (buf.length !== 3) {
|
|
167
|
-
if (onlog && typeof onlog === "function") {
|
|
168
|
-
onlog(
|
|
169
|
-
`[_parseServiceDataForWoHand] Buffer length ${buf.length} !== 3!`
|
|
170
|
-
);
|
|
171
|
-
}
|
|
172
|
-
return null;
|
|
173
|
-
}
|
|
174
|
-
const byte1 = buf.readUInt8(1);
|
|
175
|
-
const byte2 = buf.readUInt8(2);
|
|
176
|
-
|
|
177
|
-
const mode = byte1 & 0b10000000 ? true : false; // Whether the light switch Add-on is used or not. 0 = press, 1 = switch
|
|
178
|
-
const state = byte1 & 0b01000000 ? false : true; // Whether the switch status is ON or OFF. 0 = on, 1 = off
|
|
179
|
-
const battery = byte2 & 0b01111111; // %
|
|
180
|
-
|
|
181
|
-
const data = {
|
|
182
|
-
model: "H",
|
|
183
|
-
modelName: "WoHand",
|
|
184
|
-
mode: mode,
|
|
185
|
-
state: state,
|
|
186
|
-
battery: battery,
|
|
187
|
-
};
|
|
188
|
-
|
|
189
|
-
return data;
|
|
190
|
-
}
|
|
191
|
-
|
|
192
|
-
_parseServiceDataForWoSensorTH(buf, onlog) {
|
|
193
|
-
if (buf.length !== 6) {
|
|
194
|
-
if (onlog && typeof onlog === "function") {
|
|
195
|
-
onlog(
|
|
196
|
-
`[_parseServiceDataForWoSensorTH] Buffer length ${buf.length} !== 6!`
|
|
197
|
-
);
|
|
198
|
-
}
|
|
199
|
-
return null;
|
|
200
|
-
}
|
|
201
|
-
const byte2 = buf.readUInt8(2);
|
|
202
|
-
const byte3 = buf.readUInt8(3);
|
|
203
|
-
const byte4 = buf.readUInt8(4);
|
|
204
|
-
const byte5 = buf.readUInt8(5);
|
|
205
|
-
|
|
206
|
-
const temp_sign = byte4 & 0b10000000 ? 1 : -1;
|
|
207
|
-
const temp_c = temp_sign * ((byte4 & 0b01111111) + (byte3 & 0b00001111) / 10);
|
|
208
|
-
const temp_f = Math.round(((temp_c * 9 / 5) + 32) * 10) / 10;
|
|
209
|
-
|
|
210
|
-
const data = {
|
|
211
|
-
model: "T",
|
|
212
|
-
modelName: "WoSensorTH",
|
|
213
|
-
temperature: {
|
|
214
|
-
c: temp_c,
|
|
215
|
-
f: temp_f,
|
|
216
|
-
},
|
|
217
|
-
fahrenheit: byte5 & 0b10000000 ? true : false,
|
|
218
|
-
humidity: byte5 & 0b01111111,
|
|
219
|
-
battery: byte2 & 0b01111111,
|
|
220
|
-
};
|
|
221
|
-
|
|
222
|
-
return data;
|
|
223
|
-
}
|
|
224
|
-
|
|
225
|
-
_parseServiceDataForWoHumi(buf, onlog) {
|
|
226
|
-
if (buf.length !== 8) {
|
|
227
|
-
if (onlog && typeof onlog === "function") {
|
|
228
|
-
onlog(
|
|
229
|
-
`[_parseServiceDataForWoHumi] Buffer length ${buf.length} !== 8!`
|
|
230
|
-
);
|
|
231
|
-
}
|
|
232
|
-
return null;
|
|
233
|
-
}
|
|
234
|
-
const byte1 = buf.readUInt8(1);
|
|
235
|
-
const byte4 = buf.readUInt8(4);
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
const onState = byte1 & 0b10000000 ? true : false; // 1 - on
|
|
239
|
-
const autoMode = byte4 & 0b10000000 ? true : false; // 1 - auto
|
|
240
|
-
const percentage = byte4 & 0b01111111; // 0-100%, 101/102/103 - Quick gear 1/2/3
|
|
241
|
-
|
|
242
|
-
const data = {
|
|
243
|
-
model: "e",
|
|
244
|
-
modelName: "WoHumi",
|
|
245
|
-
onState: onState,
|
|
246
|
-
autoMode: autoMode,
|
|
247
|
-
percentage: autoMode ? 0 : percentage,
|
|
248
|
-
};
|
|
249
|
-
|
|
250
|
-
return data;
|
|
251
|
-
}
|
|
252
|
-
|
|
253
|
-
_parseServiceDataForWoPresence(buf, onlog) {
|
|
254
|
-
if (buf.length !== 6) {
|
|
255
|
-
if (onlog && typeof onlog === "function") {
|
|
256
|
-
onlog(
|
|
257
|
-
`[_parseServiceDataForWoPresence] Buffer length ${buf.length} !== 6!`
|
|
258
|
-
);
|
|
259
|
-
}
|
|
260
|
-
return null;
|
|
261
|
-
}
|
|
262
|
-
|
|
263
|
-
const byte1 = buf.readUInt8(1);
|
|
264
|
-
const byte2 = buf.readUInt8(2);
|
|
265
|
-
const byte5 = buf.readUInt8(5);
|
|
266
|
-
|
|
267
|
-
const tested = byte1 & 0b10000000 ? true : false;
|
|
268
|
-
const movement = byte1 & 0b01000000 ? true : false;
|
|
269
|
-
const battery = byte2 & 0b01111111;
|
|
270
|
-
const led = (byte5 & 0b00100000) >> 5;
|
|
271
|
-
const iot = (byte5 & 0b00010000) >> 4;
|
|
272
|
-
const sense_distance = (byte5 & 0b00001100) >> 2;
|
|
273
|
-
const lightLevel = byte5 & 0b00000011;
|
|
274
|
-
const is_light = byte5 & 0b00000010 ? true : false;
|
|
275
|
-
|
|
276
|
-
const data = {
|
|
277
|
-
model: "s",
|
|
278
|
-
modelName: "WoMotion",
|
|
279
|
-
tested: tested,
|
|
280
|
-
movement: movement,
|
|
281
|
-
battery: battery,
|
|
282
|
-
led: led,
|
|
283
|
-
iot: iot,
|
|
284
|
-
sense_distance: sense_distance,
|
|
285
|
-
lightLevel:
|
|
286
|
-
lightLevel == 1 ? "dark" : lightLevel == 2 ? "bright" : "unknown",
|
|
287
|
-
is_light: is_light,
|
|
288
|
-
};
|
|
289
|
-
|
|
290
|
-
return data;
|
|
291
|
-
}
|
|
292
|
-
|
|
293
|
-
_parseServiceDataForWoContact(buf, onlog) {
|
|
294
|
-
if (buf.length !== 9) {
|
|
295
|
-
if (onlog && typeof onlog === "function") {
|
|
296
|
-
onlog(
|
|
297
|
-
`[_parseServiceDataForWoContact] Buffer length ${buf.length} !== 9!`
|
|
298
|
-
);
|
|
299
|
-
}
|
|
300
|
-
return null;
|
|
301
|
-
}
|
|
302
|
-
|
|
303
|
-
const byte1 = buf.readUInt8(1);
|
|
304
|
-
const byte2 = buf.readUInt8(2);
|
|
305
|
-
const byte3 = buf.readUInt8(3);
|
|
306
|
-
const byte8 = buf.readUInt8(8);
|
|
307
|
-
|
|
308
|
-
const hallState = (byte3 >> 1) & 0b00000011;
|
|
309
|
-
const tested = byte1 & 0b10000000;
|
|
310
|
-
const movement = byte1 & 0b01000000 ? true : false; // 1 - Movement detected
|
|
311
|
-
const battery = byte2 & 0b01111111; // %
|
|
312
|
-
const contact_open = byte3 & 0b00000010 == 0b00000010;
|
|
313
|
-
const contact_timeout = byte3 & 0b00000100 == 0b00000100;
|
|
314
|
-
const lightLevel = byte3 & 0b00000001;
|
|
315
|
-
const button_count = byte8 & 0b00001111;
|
|
316
|
-
|
|
317
|
-
const data = {
|
|
318
|
-
model: "d",
|
|
319
|
-
modelName: "WoContact",
|
|
320
|
-
movement: movement,
|
|
321
|
-
tested: tested,
|
|
322
|
-
battery: battery,
|
|
323
|
-
contact_open: contact_open,
|
|
324
|
-
contact_timeout: contact_timeout,
|
|
325
|
-
lightLevel: lightLevel == 0 ? "dark" : "bright",
|
|
326
|
-
button_count: button_count,
|
|
327
|
-
doorState:
|
|
328
|
-
hallState == 0
|
|
329
|
-
? "close"
|
|
330
|
-
: hallState == 1
|
|
331
|
-
? "open"
|
|
332
|
-
: "timeout no closed",
|
|
333
|
-
};
|
|
334
|
-
|
|
335
|
-
return data;
|
|
336
|
-
}
|
|
337
|
-
|
|
338
|
-
_parseServiceDataForWoCurtain(buf, onlog) {
|
|
339
|
-
if (buf.length !== 5 && buf.length !== 6) {
|
|
340
|
-
if (onlog && typeof onlog === "function") {
|
|
341
|
-
onlog(
|
|
342
|
-
`[_parseServiceDataForWoCurtain] Buffer length ${buf.length} !== 5 or 6!`
|
|
343
|
-
);
|
|
344
|
-
}
|
|
345
|
-
return null;
|
|
346
|
-
}
|
|
347
|
-
const byte1 = buf.readUInt8(1);
|
|
348
|
-
const byte2 = buf.readUInt8(2);
|
|
349
|
-
const byte3 = buf.readUInt8(3);
|
|
350
|
-
const byte4 = buf.readUInt8(4);
|
|
351
|
-
|
|
352
|
-
const calibration = byte1 & 0b01000000 ? true : false; // Whether the calibration is compconsted
|
|
353
|
-
const battery = byte2 & 0b01111111; // %
|
|
354
|
-
const inMotion = byte3 & 0b10000000 ? true : false;
|
|
355
|
-
const currPosition = byte3 & 0b01111111; // current positon %
|
|
356
|
-
const lightLevel = (byte4 >> 4) & 0b00001111; // light sensor level (1-10)
|
|
357
|
-
const deviceChain = byte4 & 0b00000111;
|
|
358
|
-
const model = buf.slice(0, 1).toString("utf8");
|
|
359
|
-
|
|
360
|
-
const data = {
|
|
361
|
-
model: model,
|
|
362
|
-
modelName: "WoCurtain",
|
|
363
|
-
calibration: calibration,
|
|
364
|
-
battery: battery,
|
|
365
|
-
inMotion: inMotion,
|
|
366
|
-
position: currPosition,
|
|
367
|
-
lightLevel: lightLevel,
|
|
368
|
-
deviceChain: deviceChain,
|
|
369
|
-
};
|
|
370
|
-
|
|
371
|
-
return data;
|
|
372
|
-
}
|
|
373
|
-
|
|
374
|
-
_parseServiceDataForWoBlindTilt(buf, onlog) {
|
|
375
|
-
if (buf.length !== 5 && buf.length !== 6) {
|
|
376
|
-
if (onlog && typeof onlog === "function") {
|
|
377
|
-
onlog(
|
|
378
|
-
`[_parseServiceDataForWoBlindTilt] Buffer length ${buf.length} !== 5 or 6!`
|
|
379
|
-
);
|
|
380
|
-
}
|
|
381
|
-
return null;
|
|
382
|
-
}
|
|
383
|
-
let byte1 = buf.readUInt8(1);
|
|
384
|
-
let byte2 = buf.readUInt8(2);
|
|
385
|
-
|
|
386
|
-
let calibration = byte1 & 0b00000001 ? true : false; // Whether the calibration is completed
|
|
387
|
-
let battery = byte2 & 0b01111111; // %
|
|
388
|
-
let inMotion = byte2 & 0b10000000 ? true : false;
|
|
389
|
-
let tilt = byte2 & 0b01111111; // current tilt % (100 - _tilt) if reverse else _tilt,
|
|
390
|
-
let lightLevel = (byte1 >> 4) & 0b00001111; // light sensor level (1-10)
|
|
391
|
-
|
|
392
|
-
let data = {
|
|
393
|
-
model: "x",
|
|
394
|
-
modelName: "WoBlindTilt",
|
|
395
|
-
calibration: calibration,
|
|
396
|
-
battery: battery,
|
|
397
|
-
inMotion: inMotion,
|
|
398
|
-
tilt: tilt,
|
|
399
|
-
lightLevel: lightLevel,
|
|
400
|
-
};
|
|
401
|
-
|
|
402
|
-
return data;
|
|
403
|
-
}
|
|
404
|
-
|
|
405
|
-
_parseServiceDataForWoBulb(manufacturerData, onlog) {
|
|
406
|
-
if (manufacturerData.length !== 13) {
|
|
407
|
-
if (onlog && typeof onlog === "function") {
|
|
408
|
-
onlog(
|
|
409
|
-
`[_parseServiceDataForWoBulb] Buffer length ${manufacturerData.length} !== 13!`
|
|
410
|
-
);
|
|
411
|
-
}
|
|
412
|
-
return null;
|
|
413
|
-
}
|
|
414
|
-
const byte1 = manufacturerData.readUInt8(1);//power and light status
|
|
415
|
-
//const byte2 = manufacturerData.readUInt8(2);//bulb brightness
|
|
416
|
-
const byte3 = manufacturerData.readUInt8(3);//bulb R
|
|
417
|
-
const byte4 = manufacturerData.readUInt8(4);//bulb G
|
|
418
|
-
const byte5 = manufacturerData.readUInt8(5);//bulb B
|
|
419
|
-
const byte6 = manufacturerData.readUInt8(6);//bulb temperature
|
|
420
|
-
const byte7 = manufacturerData.readUInt8(7);
|
|
421
|
-
const byte8 = manufacturerData.readUInt8(8);
|
|
422
|
-
const byte9 = manufacturerData.readUInt8(9);
|
|
423
|
-
const byte10 = manufacturerData.readUInt8(10);//bulb mode
|
|
424
|
-
|
|
425
|
-
const power = byte1;
|
|
426
|
-
const red = byte3;
|
|
427
|
-
const green = byte4;
|
|
428
|
-
const blue = byte5;
|
|
429
|
-
const color_temperature = byte6;
|
|
430
|
-
const state = byte7 & 0b01111111 ? true : false;
|
|
431
|
-
const brightness = byte7 & 0b01111111;
|
|
432
|
-
const delay = byte8 & 0b10000000;
|
|
433
|
-
const preset = byte8 & 0b00001000;
|
|
434
|
-
const color_mode = byte8 & 0b00000111;
|
|
435
|
-
const speed = byte9 & 0b01111111;
|
|
436
|
-
const loop_index = byte10 & 0b11111110;
|
|
437
|
-
|
|
438
|
-
const data = {
|
|
439
|
-
model: "u",
|
|
440
|
-
modelName: "WoBulb",
|
|
441
|
-
color_temperature: color_temperature,
|
|
442
|
-
power: power,
|
|
443
|
-
state: state,
|
|
444
|
-
red: red,
|
|
445
|
-
green: green,
|
|
446
|
-
blue: blue,
|
|
447
|
-
brightness: brightness,
|
|
448
|
-
delay: delay,
|
|
449
|
-
preset: preset,
|
|
450
|
-
color_mode: color_mode,
|
|
451
|
-
speed: speed,
|
|
452
|
-
loop_index: loop_index,
|
|
453
|
-
};
|
|
454
|
-
|
|
455
|
-
return data;
|
|
456
|
-
}
|
|
457
|
-
|
|
458
|
-
_parseServiceDataForWoPlugMiniUS(manufacturerData, onlog) {
|
|
459
|
-
if (manufacturerData.length !== 14) {
|
|
460
|
-
if (onlog && typeof onlog === "function") {
|
|
461
|
-
onlog(
|
|
462
|
-
`[_parseServiceDataForWoPlugMiniUS] Buffer length ${manufacturerData.length} should be 14`
|
|
463
|
-
);
|
|
464
|
-
}
|
|
465
|
-
return null;
|
|
466
|
-
}
|
|
467
|
-
const byte9 = manufacturerData.readUInt8(9); // byte9: plug mini state; 0x00=off, 0x80=on
|
|
468
|
-
const 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
|
|
469
|
-
const byte11 = manufacturerData.readUInt8(11); // byte11: wifi rssi
|
|
470
|
-
const byte12 = manufacturerData.readUInt8(12); // byte12: bit7: overload?
|
|
471
|
-
const byte13 = manufacturerData.readUInt8(13); // byte12[bit0~6] + byte13: current power value
|
|
472
|
-
|
|
473
|
-
const state = byte9 === 0x00 ? "off" : byte9 === 0x80 ? "on" : null;
|
|
474
|
-
const delay = !!(byte10 & 0b00000001);
|
|
475
|
-
const timer = !!(byte10 & 0b00000010);
|
|
476
|
-
const syncUtcTime = !!(byte10 & 0b00000100);
|
|
477
|
-
const wifiRssi = byte11;
|
|
478
|
-
const overload = !!(byte12 & 0b10000000);
|
|
479
|
-
const currentPower = (((byte12 & 0b01111111) << 8) + byte13) / 10; // in watt
|
|
480
|
-
// TODO: voltage ???
|
|
481
|
-
|
|
482
|
-
const data = {
|
|
483
|
-
model: "g",
|
|
484
|
-
modelName: "WoPlugMini",
|
|
485
|
-
state: state,
|
|
486
|
-
delay: delay,
|
|
487
|
-
timer: timer,
|
|
488
|
-
syncUtcTime: syncUtcTime,
|
|
489
|
-
wifiRssi: wifiRssi,
|
|
490
|
-
overload: overload,
|
|
491
|
-
currentPower: currentPower,
|
|
492
|
-
};
|
|
493
|
-
|
|
494
|
-
return data;
|
|
495
|
-
}
|
|
496
|
-
|
|
497
|
-
_parseServiceDataForWoPlugMiniJP(manufacturerData, onlog) {
|
|
498
|
-
if (manufacturerData.length !== 14) {
|
|
499
|
-
if (onlog && typeof onlog === "function") {
|
|
500
|
-
onlog(
|
|
501
|
-
`[_parseServiceDataForWoPlugMiniJP] Buffer length ${manufacturerData.length} should be 14`
|
|
502
|
-
);
|
|
503
|
-
}
|
|
504
|
-
return null;
|
|
505
|
-
}
|
|
506
|
-
const byte9 = manufacturerData.readUInt8(9); // byte9: plug mini state; 0x00=off, 0x80=on
|
|
507
|
-
const 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
|
|
508
|
-
const byte11 = manufacturerData.readUInt8(11); // byte11: wifi rssi
|
|
509
|
-
const byte12 = manufacturerData.readUInt8(12); // byte12: bit7: overload?
|
|
510
|
-
const byte13 = manufacturerData.readUInt8(13); // byte12[bit0~6] + byte13: current power value
|
|
511
|
-
|
|
512
|
-
const state = byte9 === 0x00 ? "off" : byte9 === 0x80 ? "on" : null;
|
|
513
|
-
const delay = !!(byte10 & 0b00000001);
|
|
514
|
-
const timer = !!(byte10 & 0b00000010);
|
|
515
|
-
const syncUtcTime = !!(byte10 & 0b00000100);
|
|
516
|
-
const wifiRssi = byte11;
|
|
517
|
-
const overload = !!(byte12 & 0b10000000);
|
|
518
|
-
const currentPower = (((byte12 & 0b01111111) << 8) + byte13) / 10; // in watt
|
|
519
|
-
// TODO: voltage ???
|
|
520
|
-
|
|
521
|
-
const data = {
|
|
522
|
-
model: "j",
|
|
523
|
-
modelName: "WoPlugMini",
|
|
524
|
-
state: state,
|
|
525
|
-
delay: delay,
|
|
526
|
-
timer: timer,
|
|
527
|
-
syncUtcTime: syncUtcTime,
|
|
528
|
-
wifiRssi: wifiRssi,
|
|
529
|
-
overload: overload,
|
|
530
|
-
currentPower: currentPower,
|
|
531
|
-
};
|
|
532
|
-
|
|
533
|
-
return data;
|
|
534
|
-
}
|
|
535
|
-
|
|
536
|
-
_parseServiceDataForWoSmartLock(manufacturerData, onlog) {
|
|
537
|
-
if (manufacturerData.length !== 6) {
|
|
538
|
-
if (onlog && typeof onlog === "function") {
|
|
539
|
-
onlog(
|
|
540
|
-
`[_parseServiceDataForWoSmartLock] Buffer length ${manufacturerData.length} !== 6!`
|
|
541
|
-
);
|
|
542
|
-
}
|
|
543
|
-
return null;
|
|
544
|
-
}
|
|
545
|
-
const byte2 = manufacturerData.readUInt8(2);
|
|
546
|
-
const byte7 = manufacturerData.readUInt8(7);
|
|
547
|
-
const byte8 = manufacturerData.readUInt8(8);
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
const LockStatus = {
|
|
551
|
-
LOCKED: 0b0000000,
|
|
552
|
-
UNLOCKED: 0b0010000,
|
|
553
|
-
LOCKING: 0b0100000,
|
|
554
|
-
UNLOCKING: 0b0110000,
|
|
555
|
-
LOCKING_STOP: 0b1000000,
|
|
556
|
-
UNLOCKING_STOP: 0b1010000,
|
|
557
|
-
NOT_FULLY_LOCKED: 0b1100000, //Only EU lock type
|
|
558
|
-
}
|
|
559
|
-
|
|
560
|
-
const battery = byte2 & 0b01111111; // %
|
|
561
|
-
const calibration = byte7 & 0b10000000 ? true : false;
|
|
562
|
-
const status = LockStatus(byte7 & 0b01110000);
|
|
563
|
-
const update_from_secondary_lock = byte7 & 0b00001000 ? true : false;
|
|
564
|
-
const door_open = byte7 & 0b00000100 ? true : false;
|
|
565
|
-
const double_lock_mode = byte8 & 0b10000000 ? true : false;
|
|
566
|
-
const unclosed_alarm = byte8 & 0b00100000 ? true : false;
|
|
567
|
-
const unlocked_alarm = byte8 & 0b00010000 ? true : false;
|
|
568
|
-
const auto_lock_paused = byte8 & 0b00000010 ? true : false;
|
|
569
|
-
|
|
570
|
-
const data = {
|
|
571
|
-
model: "o",
|
|
572
|
-
modelName: "WoSmartLock",
|
|
573
|
-
battery: battery,
|
|
574
|
-
calibration: calibration,
|
|
575
|
-
status: status,
|
|
576
|
-
update_from_secondary_lock: update_from_secondary_lock,
|
|
577
|
-
door_open: door_open,
|
|
578
|
-
double_lock_mode: double_lock_mode,
|
|
579
|
-
unclosed_alarm: unclosed_alarm,
|
|
580
|
-
unlocked_alarm: unlocked_alarm,
|
|
581
|
-
auto_lock_paused: auto_lock_paused,
|
|
582
|
-
};
|
|
583
|
-
|
|
584
|
-
return data;
|
|
585
|
-
}
|
|
586
|
-
|
|
587
|
-
_parseServiceDataForWoSensorTHPlus(buf, onlog) {
|
|
588
|
-
if (buf.length !== 6) {
|
|
589
|
-
if (onlog && typeof onlog === "function") {
|
|
590
|
-
onlog(
|
|
591
|
-
`[_parseServiceDataForWoSensorTHPlus] Buffer length ${buf.length} !== 6!`
|
|
592
|
-
);
|
|
593
|
-
}
|
|
594
|
-
return null;
|
|
595
|
-
}
|
|
596
|
-
const byte2 = buf.readUInt8(2);
|
|
597
|
-
const byte3 = buf.readUInt8(3);
|
|
598
|
-
const byte4 = buf.readUInt8(4);
|
|
599
|
-
const byte5 = buf.readUInt8(5);
|
|
600
|
-
|
|
601
|
-
const temp_sign = byte4 & 0b10000000 ? 1 : -1;
|
|
602
|
-
const temp_c = temp_sign * ((byte4 & 0b01111111) + (byte3 & 0b00001111) / 10);
|
|
603
|
-
const temp_f = Math.round(((temp_c * 9 / 5) + 32) * 10) / 10;
|
|
604
|
-
|
|
605
|
-
const data = {
|
|
606
|
-
model: "i",
|
|
607
|
-
modelName: "WoSensorTHPlus",
|
|
608
|
-
temperature: {
|
|
609
|
-
c: temp_c,
|
|
610
|
-
f: temp_f,
|
|
611
|
-
},
|
|
612
|
-
fahrenheit: byte5 & 0b10000000 ? true : false,
|
|
613
|
-
humidity: byte5 & 0b01111111,
|
|
614
|
-
battery: byte2 & 0b01111111,
|
|
615
|
-
};
|
|
616
|
-
|
|
617
|
-
return data;
|
|
618
|
-
}
|
|
619
|
-
|
|
620
|
-
_parseServiceDataForWoStrip(buf, onlog) {
|
|
621
|
-
if (buf.length !== 18) {
|
|
622
|
-
if (onlog && typeof onlog === "function") {
|
|
623
|
-
onlog(
|
|
624
|
-
`[_parseServiceDataForWoStrip] Buffer length ${buf.length} !== 18!`
|
|
625
|
-
);
|
|
626
|
-
}
|
|
627
|
-
return null;
|
|
628
|
-
}
|
|
629
|
-
|
|
630
|
-
//const byte1 = buf.readUInt8(1);//power and light status
|
|
631
|
-
//const byte2 = buf.readUInt8(2);//bulb brightness
|
|
632
|
-
const byte3 = buf.readUInt8(3);//bulb R
|
|
633
|
-
const byte4 = buf.readUInt8(4);//bulb G
|
|
634
|
-
const byte5 = buf.readUInt8(5);//bulb B
|
|
635
|
-
const byte7 = buf.readUInt8(7);
|
|
636
|
-
const byte8 = buf.readUInt8(8);
|
|
637
|
-
const byte9 = buf.readUInt8(9);
|
|
638
|
-
const byte10 = buf.readUInt8(10);
|
|
639
|
-
|
|
640
|
-
const state = byte7 & 0b10000000 ? true : false;
|
|
641
|
-
const brightness = byte7 & 0b01111111;
|
|
642
|
-
const red = byte3;
|
|
643
|
-
const green = byte4;
|
|
644
|
-
const blue = byte5;
|
|
645
|
-
const delay = byte8 & 0b10000000;
|
|
646
|
-
const preset = byte8 & 0b00001000;
|
|
647
|
-
const color_mode = byte8 & 0b00000111;
|
|
648
|
-
const speed = byte9 & 0b01111111;
|
|
649
|
-
const loop_index = byte10 & 0b11111110;
|
|
650
|
-
|
|
651
|
-
const data = {
|
|
652
|
-
model: "r",
|
|
653
|
-
modelName: "WoStrip",
|
|
654
|
-
state: state,
|
|
655
|
-
brightness: brightness,
|
|
656
|
-
red: red,
|
|
657
|
-
green: green,
|
|
658
|
-
blue: blue,
|
|
659
|
-
delay: delay,
|
|
660
|
-
preset: preset,
|
|
661
|
-
color_mode: color_mode,
|
|
662
|
-
speed: speed,
|
|
663
|
-
loop_index: loop_index,
|
|
664
|
-
};
|
|
665
|
-
|
|
666
|
-
return data;
|
|
667
|
-
}
|
|
668
|
-
|
|
669
|
-
_parseServiceDataForWoIOSensorTH(serviceDataBuf, manufacturerDataBuf, onlog) {
|
|
670
|
-
if (serviceDataBuf.length !== 3) {
|
|
671
|
-
if (onlog && typeof onlog === "function") {
|
|
672
|
-
onlog(
|
|
673
|
-
`[_parseServiceDataForWoIOSensorTH] Service Data Buffer length ${serviceDataBuf.length} !== 3!`
|
|
674
|
-
);
|
|
675
|
-
}
|
|
676
|
-
return null;
|
|
677
|
-
}
|
|
678
|
-
if (manufacturerDataBuf.length !== 14) {
|
|
679
|
-
if (onlog && typeof onlog === "function") {
|
|
680
|
-
onlog(
|
|
681
|
-
`[_parseServiceDataForWoIOSensorTH] Manufacturer Data Buffer length ${manufacturerDataBuf.length} !== 14!`
|
|
682
|
-
);
|
|
683
|
-
}
|
|
684
|
-
return null;
|
|
685
|
-
}
|
|
686
|
-
const mdByte10 = manufacturerDataBuf.readUInt8(10);
|
|
687
|
-
const mdByte11 = manufacturerDataBuf.readUInt8(11);
|
|
688
|
-
const mdByte12 = manufacturerDataBuf.readUInt8(12);
|
|
689
|
-
|
|
690
|
-
const sdByte2 = serviceDataBuf.readUInt8(2);
|
|
691
|
-
|
|
692
|
-
const temp_sign = mdByte11 & 0b10000000 ? 1 : -1;
|
|
693
|
-
const temp_c = temp_sign * ((mdByte11 & 0b01111111) + (mdByte10 & 0b00001111) / 10);
|
|
694
|
-
const temp_f = Math.round(((temp_c * 9 / 5) + 32) * 10) / 10;
|
|
695
|
-
|
|
696
|
-
const data = {
|
|
697
|
-
model: "w",
|
|
698
|
-
modelName: "WoIOSensorTH",
|
|
699
|
-
temperature: {
|
|
700
|
-
c: temp_c,
|
|
701
|
-
f: temp_f,
|
|
702
|
-
},
|
|
703
|
-
fahrenheit: mdByte12 & 0b10000000 ? true : false, // needs to be confirmed!
|
|
704
|
-
humidity: mdByte12 & 0b01111111,
|
|
705
|
-
battery: sdByte2 & 0b01111111,
|
|
706
|
-
};
|
|
707
|
-
|
|
708
|
-
console.log(data);
|
|
709
|
-
return data;
|
|
710
|
-
}
|
|
711
|
-
}
|
|
712
|
-
|
|
713
|
-
module.exports = new SwitchbotAdvertising();
|