node-switchbot 1.4.2-beta.5 → 1.4.2-beta.7
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.
|
@@ -83,41 +83,29 @@ class SwitchbotAdvertising {
|
|
|
83
83
|
let sd = null;
|
|
84
84
|
|
|
85
85
|
if (model === "H") {
|
|
86
|
-
|
|
87
|
-
sd = this._parseServiceDataForWoHand(buf, onlog);
|
|
86
|
+
sd = this._parseServiceDataForWoHand(buf, onlog);//WoHand
|
|
88
87
|
} else if (model === "T") {
|
|
89
|
-
|
|
90
|
-
sd = this._parseServiceDataForWoSensorTH(buf, onlog);
|
|
88
|
+
sd = this._parseServiceDataForWoSensorTH(buf, onlog);//WoSensorTH
|
|
91
89
|
} else if (model === "e") {
|
|
92
|
-
|
|
93
|
-
sd = this._parseServiceDataForWoHumi(buf, onlog);
|
|
90
|
+
sd = this._parseServiceDataForWoHumi(buf, onlog);//WoHumi
|
|
94
91
|
} else if (model === "s") {
|
|
95
|
-
|
|
96
|
-
sd = this._parseServiceDataForWoPresence(buf, onlog);
|
|
92
|
+
sd = this._parseServiceDataForWoPresence(buf, onlog);//WoPresence
|
|
97
93
|
} else if (model === "d") {
|
|
98
|
-
|
|
99
|
-
sd = this._parseServiceDataForWoContact(buf, onlog);
|
|
94
|
+
sd = this._parseServiceDataForWoContact(buf, onlog);//WoContact
|
|
100
95
|
} else if (model === "c") {
|
|
101
|
-
|
|
102
|
-
sd = this._parseServiceDataForWoCurtain(buf, onlog);
|
|
96
|
+
sd = this._parseServiceDataForWoCurtain(buf, onlog);// WoCurtain
|
|
103
97
|
} else if (model === "u") {
|
|
104
|
-
|
|
105
|
-
sd = this._parseServiceDataForWoColorBulb(buf, onlog);
|
|
98
|
+
sd = this._parseServiceDataForWoBulb(manufacturerData, onlog);// WoBulb
|
|
106
99
|
} else if (model === "g") {
|
|
107
|
-
// WoPlugMini (US)
|
|
108
|
-
sd = this._parseServiceDataForWoPlugMiniUS(manufacturerData, onlog);
|
|
100
|
+
sd = this._parseServiceDataForWoPlugMiniUS(manufacturerData, onlog); // WoPlugMini (US)
|
|
109
101
|
} else if (model === "j") {
|
|
110
|
-
|
|
111
|
-
sd = this._parseServiceDataForWoPlugMiniJP(manufacturerData, onlog);
|
|
102
|
+
sd = this._parseServiceDataForWoPlugMiniJP(manufacturerData, onlog);// WoPlugMini (JP)
|
|
112
103
|
} else if (model === "o") {
|
|
113
|
-
|
|
114
|
-
sd = this._parseServiceDataForWoSmartLock(buf, onlog);
|
|
104
|
+
sd = this._parseServiceDataForWoSmartLock(buf, onlog);// WoSmartLock
|
|
115
105
|
} else if (model === "i") {
|
|
116
|
-
|
|
117
|
-
sd = this._parseServiceDataForWoSensorTHPlus(buf, onlog);
|
|
106
|
+
sd = this._parseServiceDataForWoSensorTHPlus(buf, onlog);// WoMeterPlus
|
|
118
107
|
} else if (model === "r") {
|
|
119
|
-
|
|
120
|
-
sd = this._parseServiceDataForWoLEDStripLight(buf, onlog);
|
|
108
|
+
sd = this._parseServiceDataForWoStrip(buf, onlog);// WoStrip
|
|
121
109
|
} else {
|
|
122
110
|
if (onlog && typeof onlog === "function") {
|
|
123
111
|
onlog(
|
|
@@ -363,11 +351,11 @@ class SwitchbotAdvertising {
|
|
|
363
351
|
return data;
|
|
364
352
|
}
|
|
365
353
|
|
|
366
|
-
|
|
354
|
+
_parseServiceDataForWoBulb(buf, onlog) {
|
|
367
355
|
if (buf.length !== 6) {
|
|
368
356
|
if (onlog && typeof onlog === "function") {
|
|
369
357
|
onlog(
|
|
370
|
-
`[
|
|
358
|
+
`[_parseServiceDataForWoBulb] Buffer length ${buf.length} !== 6!`
|
|
371
359
|
);
|
|
372
360
|
}
|
|
373
361
|
return null;
|
|
@@ -391,7 +379,7 @@ class SwitchbotAdvertising {
|
|
|
391
379
|
|
|
392
380
|
const data = {
|
|
393
381
|
model: "u",
|
|
394
|
-
modelName: "
|
|
382
|
+
modelName: "WoBulb",
|
|
395
383
|
state: state,
|
|
396
384
|
lightLevel: lightLevel,
|
|
397
385
|
delay: delay,
|
|
@@ -4,7 +4,7 @@ const SwitchbotDevice = require("./switchbot-device.js");
|
|
|
4
4
|
/**
|
|
5
5
|
* @see https://github.com/OpenWonderLabs/SwitchBotAPI-BLE/blob/latest/devicetypes/colorbulb.md
|
|
6
6
|
*/
|
|
7
|
-
class
|
|
7
|
+
class SwitchbotDeviceWoBulb extends SwitchbotDevice {
|
|
8
8
|
/**
|
|
9
9
|
* @returns {Promise<boolean>} resolves with a boolean that tells whether the plug in ON(true) or OFF(false)
|
|
10
10
|
*/
|
|
@@ -78,4 +78,4 @@ class SwitchbotDeviceWoColorBulb extends SwitchbotDevice {
|
|
|
78
78
|
}
|
|
79
79
|
}
|
|
80
80
|
|
|
81
|
-
module.exports =
|
|
81
|
+
module.exports = SwitchbotDeviceWoBulb;
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
const SwitchbotDevice = require("./switchbot-device.js");
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* @see https://github.com/OpenWonderLabs/SwitchBotAPI-BLE/blob/latest/devicetypes/colorbulb.md
|
|
6
|
+
*/
|
|
7
|
+
class SwitchbotDeviceWoStrip extends SwitchbotDevice {
|
|
8
|
+
/**
|
|
9
|
+
* @returns {Promise<boolean>} resolves with a boolean that tells whether the plug in ON(true) or OFF(false)
|
|
10
|
+
*/
|
|
11
|
+
readState() {
|
|
12
|
+
return this._operateBot([0x57, 0x0f, 0x48, 0x01]);
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* @private
|
|
17
|
+
*/
|
|
18
|
+
_setState(reqByteArray) {
|
|
19
|
+
const base = [0x57, 0x0f, 0x47, 0x01];
|
|
20
|
+
return this._operateBot([].concat(base, reqByteArray));
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* @returns {Promise<boolean>} resolves with a boolean that tells whether the plug in ON(true) or OFF(false)
|
|
25
|
+
*/
|
|
26
|
+
turnOn() {
|
|
27
|
+
return this._setState([0x01, 0x01]);
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
/**
|
|
31
|
+
* @returns {Promise<boolean>} resolves with a boolean that tells whether the plug in ON(true) or OFF(false)
|
|
32
|
+
*/
|
|
33
|
+
turnOff() {
|
|
34
|
+
return this._setState([0x01, 0x02]);
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
/**
|
|
38
|
+
* @returns {Promise<boolean>} resolves with a boolean that tells whether the plug in ON(true) or OFF(false)
|
|
39
|
+
*/
|
|
40
|
+
toggle() {
|
|
41
|
+
return this._setState([0x02, 0x03]);
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
/**
|
|
45
|
+
* @private
|
|
46
|
+
*/
|
|
47
|
+
_operateBot(bytes) {
|
|
48
|
+
const req_buf = Buffer.from(bytes);
|
|
49
|
+
return new Promise((resolve, reject) => {
|
|
50
|
+
this._command(req_buf)
|
|
51
|
+
.then((res_bytes) => {
|
|
52
|
+
const res_buf = Buffer.from(res_bytes);
|
|
53
|
+
if (res_buf.length === 2) {
|
|
54
|
+
let code = res_buf.readUInt8(1);
|
|
55
|
+
if (code === 0x00 || code === 0x80) {
|
|
56
|
+
const is_on = code === 0x80;
|
|
57
|
+
resolve(is_on);
|
|
58
|
+
} else {
|
|
59
|
+
reject(
|
|
60
|
+
new Error(
|
|
61
|
+
"The device returned an error: 0x" + res_buf.toString("hex")
|
|
62
|
+
)
|
|
63
|
+
);
|
|
64
|
+
}
|
|
65
|
+
} else {
|
|
66
|
+
reject(
|
|
67
|
+
new Error(
|
|
68
|
+
"Expecting a 2-byte response, got instead: 0x" +
|
|
69
|
+
res_buf.toString("hex")
|
|
70
|
+
)
|
|
71
|
+
);
|
|
72
|
+
}
|
|
73
|
+
})
|
|
74
|
+
.catch((error) => {
|
|
75
|
+
reject(error);
|
|
76
|
+
});
|
|
77
|
+
});
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
module.exports = SwitchbotDeviceWoStrip;
|
package/lib/switchbot.js
CHANGED
|
@@ -10,6 +10,8 @@ const SwitchbotDeviceWoContact = require("./switchbot-device-wocontact.js");
|
|
|
10
10
|
const SwitchbotDeviceWoSensorTH = require("./switchbot-device-wosensorth.js");
|
|
11
11
|
const SwitchbotDeviceWoHumi = require("./switchbot-device-wohumi.js");
|
|
12
12
|
const SwitchbotDeviceWoPlugMini = require("./switchbot-device-woplugmini.js");
|
|
13
|
+
const SwitchbotDeviceWoBulb = require("./switchbot-device-wobulb.js");
|
|
14
|
+
const SwitchbotDeviceWoStrip = require("./switchbot-device-wostrip.js");
|
|
13
15
|
|
|
14
16
|
class Switchbot {
|
|
15
17
|
/* ------------------------------------------------------------------
|
|
@@ -226,7 +228,7 @@ class Switchbot {
|
|
|
226
228
|
device = new SwitchbotDeviceWoCurtain(peripheral, this.noble);
|
|
227
229
|
break;
|
|
228
230
|
case "u":
|
|
229
|
-
device = new
|
|
231
|
+
device = new SwitchbotDeviceWoBulb(peripheral, this.noble);
|
|
230
232
|
break;
|
|
231
233
|
case "g":
|
|
232
234
|
case "j":
|
|
@@ -239,7 +241,7 @@ class Switchbot {
|
|
|
239
241
|
device = new SwitchbotDeviceWoSensorTHPlus(peripheral, this.noble);
|
|
240
242
|
break;
|
|
241
243
|
case "r":
|
|
242
|
-
device = new
|
|
244
|
+
device = new SwitchbotDeviceWoStrip(peripheral, this.noble);
|
|
243
245
|
break;
|
|
244
246
|
default: // 'resetting', 'unknown'
|
|
245
247
|
device = new SwitchbotDevice(peripheral, this.noble);
|
package/package.json
CHANGED