node-switchbot 1.4.1 → 1.4.2-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.
|
@@ -372,15 +372,35 @@ class SwitchbotAdvertising {
|
|
|
372
372
|
}
|
|
373
373
|
return null;
|
|
374
374
|
}
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
375
|
+
const byte9 = buf.readUInt8(9); // byte9: color bulb state; 0x00=off, 0x80=on & lightLevel: 1~100%
|
|
376
|
+
const byte10 = buf.readUInt8(10); // byte10: bit0: 0=no delay,1=delay, bit1:0=no timer, 1=timer; bit2:0=no sync time, 1=sync'ed time
|
|
377
|
+
const byte11 = buf.readUInt8(11); // byte11: wifi rssi
|
|
378
|
+
const byte12 = buf.readUInt8(12); // byte12: bit7: overload?
|
|
379
|
+
const byte13 = buf.readUInt8(13); // byte12[bit0~6] + byte13: current power value
|
|
380
380
|
|
|
381
|
-
|
|
381
|
+
const state = byte9 === 0x00 ? "off" : byte9 === 0x80 ? "on" : null;
|
|
382
|
+
const lightLevel = byte9 & 0b01111111;
|
|
383
|
+
const delay = !!(byte10 & 0b00000001);
|
|
384
|
+
const networkStatus = !!(byte10 & 0b00000001);
|
|
385
|
+
const statePreset = !!(byte10 & 0b00000010);
|
|
386
|
+
const lightState = !!(byte10 & 0b00000100);
|
|
387
|
+
const wifiRssi = byte11;
|
|
388
|
+
const dynamicRate = !!(byte12 & 0b10000000);
|
|
389
|
+
const loopIndex = (((byte12 & 0b01111111) << 8) + byte13) / 10; // in watt
|
|
390
|
+
// TODO: voltage ???
|
|
391
|
+
|
|
392
|
+
const data = {
|
|
382
393
|
model: "u",
|
|
383
394
|
modelName: "WoColorBulb",
|
|
395
|
+
state: state,
|
|
396
|
+
lightLevel: lightLevel,
|
|
397
|
+
delay: delay,
|
|
398
|
+
networkStatus: networkStatus,
|
|
399
|
+
statePreset: statePreset,
|
|
400
|
+
lightState: lightState,
|
|
401
|
+
wifiRssi: wifiRssi,
|
|
402
|
+
dynamicRate: dynamicRate,
|
|
403
|
+
loopIndex: loopIndex,
|
|
384
404
|
};
|
|
385
405
|
|
|
386
406
|
return data;
|
|
@@ -425,8 +445,6 @@ class SwitchbotAdvertising {
|
|
|
425
445
|
return data;
|
|
426
446
|
}
|
|
427
447
|
|
|
428
|
-
|
|
429
|
-
|
|
430
448
|
_parseServiceDataForWoPlugMiniJP(buf, onlog) {
|
|
431
449
|
if (buf.length !== 14) {
|
|
432
450
|
if (onlog && typeof onlog === "function") {
|
|
@@ -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/plugmini.md
|
|
6
|
+
*/
|
|
7
|
+
class SwitchbotDeviceWoPlugMini 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, 0x51, 0x01]);
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* @private
|
|
17
|
+
*/
|
|
18
|
+
_setState(reqByteArray) {
|
|
19
|
+
const base = [0x57, 0x0f, 0x50, 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 = SwitchbotDeviceWoPlugMini;
|
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
|
-
|
|
42
|
-
}
|
|
2
|
+
"name": "node-switchbot",
|
|
3
|
+
"version": "1.4.2-beta.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
|
+
"@abandonware/noble": "^1.9.2-15"
|
|
38
|
+
},
|
|
39
|
+
"devDependencies": {
|
|
40
|
+
"npm-check-updates": "^16.0.6"
|
|
41
|
+
}
|
|
42
|
+
}
|