node-switchbot 2.5.0-beta.2 → 2.5.0-beta.21
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/dist/advertising.d.ts +31 -20
- package/dist/advertising.d.ts.map +1 -1
- package/dist/advertising.js +72 -75
- package/dist/advertising.js.map +1 -1
- package/dist/device/woblindtilt.d.ts +19 -50
- package/dist/device/woblindtilt.d.ts.map +1 -1
- package/dist/device/woblindtilt.js +39 -98
- package/dist/device/woblindtilt.js.map +1 -1
- package/dist/device/wobulb.d.ts +41 -15
- package/dist/device/wobulb.d.ts.map +1 -1
- package/dist/device/wobulb.js +71 -127
- package/dist/device/wobulb.js.map +1 -1
- package/dist/device/woceilinglight.d.ts +47 -21
- package/dist/device/woceilinglight.d.ts.map +1 -1
- package/dist/device/woceilinglight.js +94 -169
- package/dist/device/woceilinglight.js.map +1 -1
- package/dist/device/wocontact.d.ts +11 -1
- package/dist/device/wocontact.d.ts.map +1 -1
- package/dist/device/wocontact.js +22 -21
- package/dist/device/wocontact.js.map +1 -1
- package/dist/device/wocurtain.d.ts +39 -1
- package/dist/device/wocurtain.d.ts.map +1 -1
- package/dist/device/wocurtain.js +68 -102
- package/dist/device/wocurtain.js.map +1 -1
- package/dist/device/wohand.d.ts +37 -2
- package/dist/device/wohand.d.ts.map +1 -1
- package/dist/device/wohand.js +54 -88
- package/dist/device/wohand.js.map +1 -1
- package/dist/device/wohub2.d.ts +11 -1
- package/dist/device/wohub2.d.ts.map +1 -1
- package/dist/device/wohub2.js +20 -28
- package/dist/device/wohub2.js.map +1 -1
- package/dist/device/wohumi.d.ts +37 -2
- package/dist/device/wohumi.d.ts.map +1 -1
- package/dist/device/wohumi.js +51 -82
- package/dist/device/wohumi.js.map +1 -1
- package/dist/device/woiosensorth.d.ts +12 -1
- package/dist/device/woiosensorth.d.ts.map +1 -1
- package/dist/device/woiosensorth.js +24 -28
- package/dist/device/woiosensorth.js.map +1 -1
- package/dist/device/woplugmini.d.ts +45 -12
- package/dist/device/woplugmini.d.ts.map +1 -1
- package/dist/device/woplugmini.js +69 -75
- package/dist/device/woplugmini.js.map +1 -1
- package/dist/device/wopresence.d.ts +11 -1
- package/dist/device/wopresence.d.ts.map +1 -1
- package/dist/device/wopresence.js +20 -26
- package/dist/device/wopresence.js.map +1 -1
- package/dist/device/wosensorth.d.ts +18 -2
- package/dist/device/wosensorth.d.ts.map +1 -1
- package/dist/device/wosensorth.js +32 -48
- package/dist/device/wosensorth.js.map +1 -1
- package/dist/device/wosmartlock.d.ts +56 -13
- package/dist/device/wosmartlock.d.ts.map +1 -1
- package/dist/device/wosmartlock.js +106 -194
- package/dist/device/wosmartlock.js.map +1 -1
- package/dist/device/wosmartlockpro.d.ts +61 -18
- package/dist/device/wosmartlockpro.d.ts.map +1 -1
- package/dist/device/wosmartlockpro.js +114 -203
- package/dist/device/wosmartlockpro.js.map +1 -1
- package/dist/device/wostrip.d.ts +37 -18
- package/dist/device/wostrip.d.ts.map +1 -1
- package/dist/device/wostrip.js +78 -124
- package/dist/device/wostrip.js.map +1 -1
- package/dist/device.d.ts +87 -224
- package/dist/device.d.ts.map +1 -1
- package/dist/device.js +123 -407
- package/dist/device.js.map +1 -1
- package/dist/index.d.ts +8 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +8 -0
- package/dist/index.js.map +1 -1
- package/dist/parameter-checker.d.ts +78 -18
- package/dist/parameter-checker.d.ts.map +1 -1
- package/dist/parameter-checker.js +139 -334
- package/dist/parameter-checker.js.map +1 -1
- package/dist/settings.d.ts +46 -0
- package/dist/settings.d.ts.map +1 -1
- package/dist/settings.js +46 -2
- package/dist/settings.js.map +1 -1
- package/dist/switchbot-openapi.d.ts +56 -0
- package/dist/switchbot-openapi.d.ts.map +1 -0
- package/dist/switchbot-openapi.js +241 -0
- package/dist/switchbot-openapi.js.map +1 -0
- package/dist/switchbot.d.ts +41 -17
- package/dist/switchbot.d.ts.map +1 -1
- package/dist/switchbot.js +311 -176
- package/dist/switchbot.js.map +1 -1
- package/dist/test/woblindtilt.test.d.ts.map +1 -0
- package/dist/test/woblindtilt.test.js +97 -0
- package/dist/test/woblindtilt.test.js.map +1 -0
- package/dist/{device → test}/wobulb.test.d.ts.map +1 -1
- package/dist/test/wobulb.test.js +104 -0
- package/dist/test/wobulb.test.js.map +1 -0
- package/dist/test/woceilinglight.test.d.ts.map +1 -0
- package/dist/test/woceilinglight.test.js +95 -0
- package/dist/test/woceilinglight.test.js.map +1 -0
- package/dist/test/wocontact.test.d.ts.map +1 -0
- package/dist/test/wocontact.test.js +38 -0
- package/dist/test/wocontact.test.js.map +1 -0
- package/dist/test/wocurtain.test.d.ts.map +1 -0
- package/dist/test/wocurtain.test.js +76 -0
- package/dist/test/wocurtain.test.js.map +1 -0
- package/dist/{device → test}/wohand.test.d.ts.map +1 -1
- package/dist/test/wohand.test.js +76 -0
- package/dist/test/wohand.test.js.map +1 -0
- package/dist/test/wohub2.test.d.ts +2 -0
- package/dist/test/wohub2.test.d.ts.map +1 -0
- package/dist/{device/wohand2.test.js → test/wohub2.test.js} +10 -8
- package/dist/test/wohub2.test.js.map +1 -0
- package/dist/{device → test}/wohumi.test.d.ts.map +1 -1
- package/dist/{device → test}/wohumi.test.js +5 -2
- package/dist/test/wohumi.test.js.map +1 -0
- package/dist/test/woiosensorth.test.d.ts.map +1 -0
- package/dist/{device → test}/woiosensorth.test.js +11 -9
- package/dist/test/woiosensorth.test.js.map +1 -0
- package/dist/test/woplugmini.test.d.ts.map +1 -0
- package/dist/{device → test}/woplugmini.test.js +10 -5
- package/dist/test/woplugmini.test.js.map +1 -0
- package/dist/test/wopresence.test.d.ts.map +1 -0
- package/dist/{device → test}/wopresence.test.js +5 -1
- package/dist/test/wopresence.test.js.map +1 -0
- package/dist/test/wosensorth.test.d.ts.map +1 -0
- package/dist/{device → test}/wosensorth.test.js +5 -14
- package/dist/test/wosensorth.test.js.map +1 -0
- package/dist/test/wosmartlock.test.d.ts.map +1 -0
- package/dist/test/wosmartlock.test.js +147 -0
- package/dist/test/wosmartlock.test.js.map +1 -0
- package/dist/test/wosmartlockpro.test.d.ts.map +1 -0
- package/dist/{device → test}/wosmartlockpro.test.js +30 -26
- package/dist/test/wosmartlockpro.test.js.map +1 -0
- package/dist/{device → test}/wostrip.test.d.ts.map +1 -1
- package/dist/{device → test}/wostrip.test.js +18 -19
- package/dist/test/wostrip.test.js.map +1 -0
- package/dist/types/bledevicestatus.d.ts +4 -12
- package/dist/types/bledevicestatus.d.ts.map +1 -1
- package/dist/types/devicelist.d.ts.map +1 -1
- package/dist/types/devicelist.js +0 -4
- package/dist/types/devicelist.js.map +1 -1
- package/dist/types/deviceresponse.d.ts.map +1 -1
- package/dist/types/devicestatus.d.ts.map +1 -1
- package/dist/types/irdevicelist.d.ts.map +1 -1
- package/dist/types/pushbody.d.ts +1 -1
- package/dist/types/pushbody.d.ts.map +1 -1
- package/dist/types/types.d.ts +71 -120
- package/dist/types/types.d.ts.map +1 -1
- package/dist/types/types.js +10 -0
- package/dist/types/types.js.map +1 -1
- package/package.json +6 -4
- package/dist/device/woblindtilt.test.d.ts.map +0 -1
- package/dist/device/woblindtilt.test.js +0 -26
- package/dist/device/woblindtilt.test.js.map +0 -1
- package/dist/device/wobulb.test.js +0 -52
- package/dist/device/wobulb.test.js.map +0 -1
- package/dist/device/woceilinglight.test.d.ts.map +0 -1
- package/dist/device/woceilinglight.test.js +0 -63
- package/dist/device/woceilinglight.test.js.map +0 -1
- package/dist/device/wocontact.test.d.ts.map +0 -1
- package/dist/device/wocontact.test.js +0 -34
- package/dist/device/wocontact.test.js.map +0 -1
- package/dist/device/wocurtain.test.d.ts.map +0 -1
- package/dist/device/wocurtain.test.js +0 -33
- package/dist/device/wocurtain.test.js.map +0 -1
- package/dist/device/wohand.test.js +0 -62
- package/dist/device/wohand.test.js.map +0 -1
- package/dist/device/wohand2.test.d.ts +0 -2
- package/dist/device/wohand2.test.d.ts.map +0 -1
- package/dist/device/wohand2.test.js.map +0 -1
- package/dist/device/wohumi.test.js.map +0 -1
- package/dist/device/woiosensorth.test.d.ts.map +0 -1
- package/dist/device/woiosensorth.test.js.map +0 -1
- package/dist/device/woplugmini.test.d.ts.map +0 -1
- package/dist/device/woplugmini.test.js.map +0 -1
- package/dist/device/wopresence.test.d.ts.map +0 -1
- package/dist/device/wopresence.test.js.map +0 -1
- package/dist/device/wosensorth.test.d.ts.map +0 -1
- package/dist/device/wosensorth.test.js.map +0 -1
- package/dist/device/wosmartlock.test.d.ts.map +0 -1
- package/dist/device/wosmartlock.test.js +0 -84
- package/dist/device/wosmartlock.test.js.map +0 -1
- package/dist/device/wosmartlockpro.test.d.ts.map +0 -1
- package/dist/device/wosmartlockpro.test.js.map +0 -1
- package/dist/device/wostrip.test.js.map +0 -1
- /package/dist/{device → test}/woblindtilt.test.d.ts +0 -0
- /package/dist/{device → test}/wobulb.test.d.ts +0 -0
- /package/dist/{device → test}/woceilinglight.test.d.ts +0 -0
- /package/dist/{device → test}/wocontact.test.d.ts +0 -0
- /package/dist/{device → test}/wocurtain.test.d.ts +0 -0
- /package/dist/{device → test}/wohand.test.d.ts +0 -0
- /package/dist/{device → test}/wohumi.test.d.ts +0 -0
- /package/dist/{device → test}/woiosensorth.test.d.ts +0 -0
- /package/dist/{device → test}/woplugmini.test.d.ts +0 -0
- /package/dist/{device → test}/wopresence.test.d.ts +0 -0
- /package/dist/{device → test}/wosensorth.test.d.ts +0 -0
- /package/dist/{device → test}/wosmartlock.test.d.ts +0 -0
- /package/dist/{device → test}/wosmartlockpro.test.d.ts +0 -0
- /package/dist/{device → test}/wostrip.test.d.ts +0 -0
|
@@ -1,282 +1,193 @@
|
|
|
1
1
|
import { Buffer } from 'node:buffer';
|
|
2
2
|
import * as Crypto from 'node:crypto';
|
|
3
|
-
/*
|
|
4
|
-
* wosmartlock.ts: Switchbot BLE API registration.
|
|
5
|
-
* adapted off the work done by [pySwitchbot](https://github.com/Danielhiversen/pySwitchbot)
|
|
6
|
-
*/
|
|
7
3
|
import { SwitchbotDevice } from '../device.js';
|
|
4
|
+
import { WoSmartLockProCommands } from '../settings.js';
|
|
8
5
|
import { SwitchBotBLEModel, SwitchBotBLEModelFriendlyName, SwitchBotBLEModelName } from '../types/types.js';
|
|
6
|
+
/**
|
|
7
|
+
* Class representing a WoSmartLockPro device.
|
|
8
|
+
* @see https://github.com/OpenWonderLabs/SwitchBotAPI-BLE/blob/latest/devicetypes/lock.md
|
|
9
|
+
*/
|
|
9
10
|
export class WoSmartLockPro extends SwitchbotDevice {
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
static COMMAND_GET_CK_IV = '570f2103';
|
|
14
|
-
static COMMAND_LOCK_INFO = '570f4f8102';
|
|
15
|
-
static COMMAND_UNLOCK = '570f4e0101000080';
|
|
16
|
-
static COMMAND_UNLOCK_NO_UNLATCH = '570f4e01010000a0';
|
|
17
|
-
static COMMAND_LOCK = '570f4e0101000000';
|
|
18
|
-
static COMMAND_ENABLE_NOTIFICATIONS = '570e01001e00008101';
|
|
19
|
-
static COMMAND_DISABLE_NOTIFICATIONS = '570e00';
|
|
11
|
+
iv = null;
|
|
12
|
+
key_id = '';
|
|
13
|
+
encryption_key = null;
|
|
20
14
|
static Result = {
|
|
21
15
|
ERROR: 0x00,
|
|
22
16
|
SUCCESS: 0x01,
|
|
23
17
|
SUCCESS_LOW_BATTERY: 0x06,
|
|
24
18
|
};
|
|
25
|
-
static validateResponse(res) {
|
|
19
|
+
static async validateResponse(res) {
|
|
26
20
|
if (res.length >= 3) {
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
case WoSmartLockPro.Result.SUCCESS_LOW_BATTERY:
|
|
31
|
-
return WoSmartLockPro.Result.SUCCESS_LOW_BATTERY;
|
|
21
|
+
const result = res.readUInt8(0);
|
|
22
|
+
if (result === WoSmartLockPro.Result.SUCCESS || result === WoSmartLockPro.Result.SUCCESS_LOW_BATTERY) {
|
|
23
|
+
return result;
|
|
32
24
|
}
|
|
33
25
|
}
|
|
34
26
|
return WoSmartLockPro.Result.ERROR;
|
|
35
27
|
}
|
|
36
28
|
static getLockStatus(code) {
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
return 'LOCKING_STOP';
|
|
48
|
-
case 0b1010000:
|
|
49
|
-
return 'UNLOCKING_STOP';
|
|
50
|
-
case 0b01100000: // Only EU lock type
|
|
51
|
-
return 'NOT_FULLY_LOCKED';
|
|
52
|
-
default:
|
|
53
|
-
return 'UNKNOWN';
|
|
54
|
-
}
|
|
29
|
+
const statusMap = {
|
|
30
|
+
0b0000000: 'LOCKED',
|
|
31
|
+
0b0010000: 'UNLOCKED',
|
|
32
|
+
0b0100000: 'LOCKING',
|
|
33
|
+
0b0110000: 'UNLOCKING',
|
|
34
|
+
0b1000000: 'LOCKING_STOP',
|
|
35
|
+
0b1010000: 'UNLOCKING_STOP',
|
|
36
|
+
0b01100000: 'NOT_FULLY_LOCKED', // Only EU lock type
|
|
37
|
+
};
|
|
38
|
+
return statusMap[code] || 'UNKNOWN';
|
|
55
39
|
}
|
|
56
40
|
static async parseServiceData(serviceData, manufacturerData, onlog) {
|
|
57
41
|
if (manufacturerData.length < 11) {
|
|
58
|
-
|
|
59
|
-
onlog(`[parseServiceDataForWoSmartLockPro] Buffer length ${manufacturerData.length} is too short!`);
|
|
60
|
-
}
|
|
42
|
+
onlog?.(`[parseServiceDataForWoSmartLockPro] Buffer length ${manufacturerData.length} is too short!`);
|
|
61
43
|
return null;
|
|
62
44
|
}
|
|
63
|
-
// adv data needs both service data and manufacturer data
|
|
64
|
-
// byte var names based on documentation
|
|
65
45
|
const byte2 = serviceData.readUInt8(2);
|
|
66
46
|
const byte7 = manufacturerData.readUInt8(7);
|
|
67
47
|
const byte8 = manufacturerData.readUInt8(8);
|
|
68
48
|
const byte9 = manufacturerData.readUInt8(9);
|
|
69
49
|
const byte11 = manufacturerData.readUInt8(11);
|
|
70
|
-
const battery = byte2 & 0b01111111; // %
|
|
71
|
-
const calibration = !!(byte7 & 0b10000000);
|
|
72
|
-
const status = WoSmartLockPro.getLockStatus((byte7 & 0b00111000) >> 3);
|
|
73
|
-
const door_open = !!(byte8 & 0b01100000);
|
|
74
|
-
// Double lock mode is not supported on Lock Pro
|
|
75
|
-
const update_from_secondary_lock = false; // !!(byte7 & 0b00001000)
|
|
76
|
-
const double_lock_mode = false; // !!(byte8 & 0b10000000)
|
|
77
|
-
const unclosed_alarm = !!(byte11 & 0b10000000);
|
|
78
|
-
const unlocked_alarm = !!(byte11 & 0b01000000);
|
|
79
|
-
const auto_lock_paused = !!(byte8 & 0b100000);
|
|
80
|
-
const night_latch = !!(byte9 & 0b00000001);
|
|
81
|
-
// const manual = byte7 & 0b100000;
|
|
82
50
|
const data = {
|
|
83
51
|
model: SwitchBotBLEModel.LockPro,
|
|
84
52
|
modelName: SwitchBotBLEModelName.LockPro,
|
|
85
53
|
modelFriendlyName: SwitchBotBLEModelFriendlyName.LockPro,
|
|
86
|
-
battery,
|
|
87
|
-
calibration,
|
|
88
|
-
status,
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
double_lock_mode,
|
|
92
|
-
unclosed_alarm,
|
|
93
|
-
unlocked_alarm,
|
|
94
|
-
auto_lock_paused,
|
|
95
|
-
night_latch,
|
|
54
|
+
battery: byte2 & 0b01111111,
|
|
55
|
+
calibration: !!(byte7 & 0b10000000),
|
|
56
|
+
status: WoSmartLockPro.getLockStatus((byte7 & 0b00111000) >> 3),
|
|
57
|
+
door_open: !!(byte8 & 0b01100000),
|
|
58
|
+
update_from_secondary_lock: false,
|
|
59
|
+
double_lock_mode: false,
|
|
60
|
+
unclosed_alarm: !!(byte11 & 0b10000000),
|
|
61
|
+
unlocked_alarm: !!(byte11 & 0b01000000),
|
|
62
|
+
auto_lock_paused: !!(byte8 & 0b100000),
|
|
63
|
+
night_latch: !!(byte9 & 0b00000001),
|
|
96
64
|
};
|
|
97
65
|
return data;
|
|
98
66
|
}
|
|
99
67
|
constructor(peripheral, noble) {
|
|
100
68
|
super(peripheral, noble);
|
|
101
|
-
this._iv = null;
|
|
102
|
-
this._key_id = '';
|
|
103
|
-
this._encryption_key = null;
|
|
104
69
|
}
|
|
105
|
-
|
|
106
|
-
*
|
|
107
|
-
*
|
|
108
|
-
*
|
|
109
|
-
|
|
110
|
-
* - keyId, encryptionKey
|
|
111
|
-
*
|
|
112
|
-
* [Return value]
|
|
113
|
-
* - void
|
|
114
|
-
* ---------------------------------------------------------------- */
|
|
70
|
+
/**
|
|
71
|
+
* Initializes the encryption key info for valid lock communication.
|
|
72
|
+
* @param {string} keyId - The key ID.
|
|
73
|
+
* @param {string} encryptionKey - The encryption key.
|
|
74
|
+
*/
|
|
115
75
|
async setKey(keyId, encryptionKey) {
|
|
116
|
-
this.
|
|
117
|
-
this.
|
|
118
|
-
this.
|
|
76
|
+
this.iv = null;
|
|
77
|
+
this.key_id = keyId;
|
|
78
|
+
this.encryption_key = Buffer.from(encryptionKey, 'hex');
|
|
119
79
|
}
|
|
120
|
-
|
|
121
|
-
*
|
|
122
|
-
* -
|
|
123
|
-
|
|
124
|
-
* [Arguments]
|
|
125
|
-
* - none
|
|
126
|
-
*
|
|
127
|
-
* [Return value]
|
|
128
|
-
* - Promise object
|
|
129
|
-
* WoSmartLockPro.LockResult will be passed to the `resolve()`.
|
|
130
|
-
* ---------------------------------------------------------------- */
|
|
80
|
+
/**
|
|
81
|
+
* Unlocks the Smart Lock.
|
|
82
|
+
* @returns {Promise<number>} - The result of the unlock operation.
|
|
83
|
+
*/
|
|
131
84
|
async unlock() {
|
|
132
|
-
await this.operateLockPro(
|
|
133
|
-
|
|
134
|
-
if (resBuf) {
|
|
135
|
-
return WoSmartLockPro.validateResponse(resBuf);
|
|
136
|
-
}
|
|
137
|
-
else {
|
|
138
|
-
return WoSmartLockPro.Result.ERROR;
|
|
139
|
-
}
|
|
140
|
-
})
|
|
141
|
-
.catch((error) => {
|
|
142
|
-
throw error;
|
|
143
|
-
});
|
|
85
|
+
const resBuf = await this.operateLockPro(WoSmartLockProCommands.UNLOCK);
|
|
86
|
+
return resBuf ? WoSmartLockPro.validateResponse(resBuf) : WoSmartLockPro.Result.ERROR;
|
|
144
87
|
}
|
|
145
|
-
|
|
146
|
-
*
|
|
147
|
-
* -
|
|
148
|
-
|
|
149
|
-
* [Arguments]
|
|
150
|
-
* - none
|
|
151
|
-
*
|
|
152
|
-
* [Return value]
|
|
153
|
-
* - Promise object
|
|
154
|
-
* WoSmartLockPro.LockResult will be passed to the `resolve()`.
|
|
155
|
-
* ---------------------------------------------------------------- */
|
|
88
|
+
/**
|
|
89
|
+
* Unlocks the Smart Lock without unlatching the door.
|
|
90
|
+
* @returns {Promise<number>} - The result of the unlock operation.
|
|
91
|
+
*/
|
|
156
92
|
async unlockNoUnlatch() {
|
|
157
|
-
await this.operateLockPro(
|
|
158
|
-
|
|
159
|
-
if (resBuf) {
|
|
160
|
-
return WoSmartLockPro.validateResponse(resBuf);
|
|
161
|
-
}
|
|
162
|
-
else {
|
|
163
|
-
return WoSmartLockPro.Result.ERROR;
|
|
164
|
-
}
|
|
165
|
-
})
|
|
166
|
-
.catch((error) => {
|
|
167
|
-
throw error;
|
|
168
|
-
});
|
|
93
|
+
const resBuf = await this.operateLockPro(WoSmartLockProCommands.UNLOCK_NO_UNLATCH);
|
|
94
|
+
return resBuf ? WoSmartLockPro.validateResponse(resBuf) : WoSmartLockPro.Result.ERROR;
|
|
169
95
|
}
|
|
170
|
-
|
|
171
|
-
*
|
|
172
|
-
* -
|
|
173
|
-
|
|
174
|
-
* [Arguments]
|
|
175
|
-
* - none
|
|
176
|
-
*
|
|
177
|
-
* [Return value]
|
|
178
|
-
* - Promise object
|
|
179
|
-
* WoSmartLockPro.LockResult will be passed to the `resolve()`.
|
|
180
|
-
* ---------------------------------------------------------------- */
|
|
96
|
+
/**
|
|
97
|
+
* Locks the Smart Lock.
|
|
98
|
+
* @returns {Promise<number>} - The result of the lock operation.
|
|
99
|
+
*/
|
|
181
100
|
async lock() {
|
|
182
|
-
this.operateLockPro(
|
|
183
|
-
|
|
184
|
-
if (resBuf) {
|
|
185
|
-
return WoSmartLockPro.validateResponse(resBuf);
|
|
186
|
-
}
|
|
187
|
-
else {
|
|
188
|
-
return WoSmartLockPro.Result.ERROR;
|
|
189
|
-
}
|
|
190
|
-
})
|
|
191
|
-
.catch((error) => {
|
|
192
|
-
throw error;
|
|
193
|
-
});
|
|
101
|
+
const resBuf = await this.operateLockPro(WoSmartLockProCommands.LOCK);
|
|
102
|
+
return resBuf ? WoSmartLockPro.validateResponse(resBuf) : WoSmartLockPro.Result.ERROR;
|
|
194
103
|
}
|
|
195
|
-
|
|
196
|
-
* info
|
|
197
|
-
* -
|
|
198
|
-
|
|
199
|
-
* [Arguments]
|
|
200
|
-
* - none
|
|
201
|
-
*
|
|
202
|
-
* [Return value]
|
|
203
|
-
* - Promise object
|
|
204
|
-
* state object will be passed to the `resolve()`
|
|
205
|
-
* ---------------------------------------------------------------- */
|
|
104
|
+
/**
|
|
105
|
+
* Gets general state info from the Smart Lock.
|
|
106
|
+
* @returns {Promise<object | null>} - The state object or null if an error occurred.
|
|
107
|
+
*/
|
|
206
108
|
async info() {
|
|
207
|
-
await this.operateLockPro(
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
}
|
|
219
|
-
else {
|
|
220
|
-
return null;
|
|
221
|
-
}
|
|
222
|
-
})
|
|
223
|
-
.catch((error) => {
|
|
224
|
-
throw error;
|
|
225
|
-
});
|
|
109
|
+
const resBuf = await this.operateLockPro(WoSmartLockProCommands.LOCK_INFO);
|
|
110
|
+
if (resBuf) {
|
|
111
|
+
return {
|
|
112
|
+
calibration: Boolean(resBuf[0] & 0b10000000),
|
|
113
|
+
status: WoSmartLockPro.getLockStatus((resBuf[0] & 0b01110000) >> 4),
|
|
114
|
+
door_open: Boolean(resBuf[0] & 0b00000100),
|
|
115
|
+
unclosed_alarm: Boolean(resBuf[1] & 0b00100000),
|
|
116
|
+
unlocked_alarm: Boolean(resBuf[1] & 0b00010000),
|
|
117
|
+
};
|
|
118
|
+
}
|
|
119
|
+
return null;
|
|
226
120
|
}
|
|
121
|
+
/**
|
|
122
|
+
* Encrypts a string using AES-128-CTR.
|
|
123
|
+
* @param {string} str - The string to encrypt.
|
|
124
|
+
* @returns {Promise<string>} - The encrypted string in hex format.
|
|
125
|
+
*/
|
|
227
126
|
async encrypt(str) {
|
|
228
|
-
const cipher = Crypto.createCipheriv('aes-128-ctr', this.
|
|
127
|
+
const cipher = Crypto.createCipheriv('aes-128-ctr', this.encryption_key, this.iv);
|
|
229
128
|
return Buffer.concat([cipher.update(str, 'hex'), cipher.final()]).toString('hex');
|
|
230
129
|
}
|
|
130
|
+
/**
|
|
131
|
+
* Decrypts a buffer using AES-128-CTR.
|
|
132
|
+
* @param {Buffer} data - The data to decrypt.
|
|
133
|
+
* @returns {Promise<Buffer>} - The decrypted data.
|
|
134
|
+
*/
|
|
231
135
|
async decrypt(data) {
|
|
232
|
-
const decipher = Crypto.createDecipheriv('aes-128-ctr', this.
|
|
136
|
+
const decipher = Crypto.createDecipheriv('aes-128-ctr', this.encryption_key, this.iv);
|
|
233
137
|
return Buffer.concat([decipher.update(data), decipher.final()]);
|
|
234
138
|
}
|
|
139
|
+
/**
|
|
140
|
+
* Retrieves the IV from the device.
|
|
141
|
+
* @returns {Promise<Buffer>} - The IV buffer.
|
|
142
|
+
*/
|
|
235
143
|
async getIv() {
|
|
236
|
-
if (this.
|
|
237
|
-
const res = await this.operateLockPro(
|
|
144
|
+
if (!this.iv) {
|
|
145
|
+
const res = await this.operateLockPro(WoSmartLockProCommands.GET_CKIV + this.key_id, false);
|
|
238
146
|
if (res) {
|
|
239
|
-
this.
|
|
147
|
+
this.iv = res.subarray(4);
|
|
240
148
|
}
|
|
241
149
|
else {
|
|
242
150
|
throw new Error('Failed to retrieve IV from the device.');
|
|
243
151
|
}
|
|
244
152
|
}
|
|
245
|
-
return this.
|
|
153
|
+
return this.iv;
|
|
246
154
|
}
|
|
155
|
+
/**
|
|
156
|
+
* Sends an encrypted command to the device.
|
|
157
|
+
* @param {string} key - The command key.
|
|
158
|
+
* @returns {Promise<Buffer>} - The response buffer.
|
|
159
|
+
*/
|
|
247
160
|
async encryptedCommand(key) {
|
|
248
161
|
const iv = await this.getIv();
|
|
249
|
-
const req = Buffer.from(key.substring(0, 2) + this.
|
|
162
|
+
const req = Buffer.from(key.substring(0, 2) + this.key_id + Buffer.from(iv.subarray(0, 2)).toString('hex') + await this.encrypt(key.substring(2)), 'hex');
|
|
250
163
|
const bytes = await this.command(req);
|
|
251
164
|
const buf = Buffer.from(bytes);
|
|
252
165
|
const code = WoSmartLockPro.validateResponse(buf);
|
|
253
|
-
if (code !== WoSmartLockPro.Result.ERROR) {
|
|
166
|
+
if (await code !== WoSmartLockPro.Result.ERROR) {
|
|
254
167
|
return Buffer.concat([buf.subarray(0, 1), await this.decrypt(buf.subarray(4))]);
|
|
255
168
|
}
|
|
256
169
|
else {
|
|
257
170
|
throw new Error(`The device returned an error: 0x${buf.toString('hex')}`);
|
|
258
171
|
}
|
|
259
172
|
}
|
|
173
|
+
/**
|
|
174
|
+
* Operates the lock with the given command.
|
|
175
|
+
* @param {string} key - The command key.
|
|
176
|
+
* @param {boolean} [encrypt] - Whether to encrypt the command.
|
|
177
|
+
* @returns {Promise<Buffer>} - The response buffer.
|
|
178
|
+
*/
|
|
260
179
|
async operateLockPro(key, encrypt = true) {
|
|
261
|
-
// encrypted command
|
|
262
180
|
if (encrypt) {
|
|
263
181
|
return this.encryptedCommand(key);
|
|
264
182
|
}
|
|
265
183
|
const req = Buffer.from(`${key.substring(0, 2)}000000${key.substring(2)}`, 'hex');
|
|
266
|
-
await this.command(req)
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
else {
|
|
274
|
-
return buf;
|
|
275
|
-
}
|
|
276
|
-
})
|
|
277
|
-
.catch((error) => {
|
|
278
|
-
throw error;
|
|
279
|
-
});
|
|
184
|
+
const bytes = await this.command(req);
|
|
185
|
+
const buf = Buffer.from(bytes);
|
|
186
|
+
const code = WoSmartLockPro.validateResponse(buf);
|
|
187
|
+
if (await code === WoSmartLockPro.Result.ERROR) {
|
|
188
|
+
throw new Error(`The device returned an error: 0x${buf.toString('hex')}`);
|
|
189
|
+
}
|
|
190
|
+
return buf;
|
|
280
191
|
}
|
|
281
192
|
}
|
|
282
193
|
//# sourceMappingURL=wosmartlockpro.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"wosmartlockpro.js","sourceRoot":"","sources":["../../src/device/wosmartlockpro.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"wosmartlockpro.js","sourceRoot":"","sources":["../../src/device/wosmartlockpro.ts"],"names":[],"mappings":"AAQA,OAAO,EAAE,MAAM,EAAE,MAAM,aAAa,CAAA;AACpC,OAAO,KAAK,MAAM,MAAM,aAAa,CAAA;AAErC,OAAO,EAAE,eAAe,EAAE,MAAM,cAAc,CAAA;AAC9C,OAAO,EAAE,sBAAsB,EAAE,MAAM,gBAAgB,CAAA;AACvD,OAAO,EAAE,iBAAiB,EAAE,6BAA6B,EAAE,qBAAqB,EAAE,MAAM,mBAAmB,CAAA;AAE3G;;;GAGG;AACH,MAAM,OAAO,cAAe,SAAQ,eAAe;IAC1C,EAAE,GAAkB,IAAI,CAAA;IACxB,MAAM,GAAW,EAAE,CAAA;IACnB,cAAc,GAAkB,IAAI,CAAA;IAE3C,MAAM,CAAC,MAAM,GAAG;QACd,KAAK,EAAE,IAAI;QACX,OAAO,EAAE,IAAI;QACb,mBAAmB,EAAE,IAAI;KAC1B,CAAA;IAED,MAAM,CAAC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AAC,IAAI,CAAC,GAAG,GAAG,CAAC,SAAS,CAAC,CAAC,EAAE,CAAC,CAAC,SAAS,GAAG,CAAC,SAAS,CAAC,CAAC,CAAC,EAAE,EAAE,KAAK,CAAC,CAAA;QACjF,MAAM,KAAK,GAAG,MAAM,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,CAAA;QACrC,MAAM,GAAG,GAAG,MAAM,CAAC,IAAI,CAAC,KAAmB,CAAC,CAAA;QAC5C,MAAM,IAAI,GAAG,cAAc,CAAC,gBAAgB,CAAC,GAAG,CAAC,CAAA;QAEjD,IAAI,MAAM,IAAI,KAAK,cAAc,CAAC,MAAM,CAAC,KAAK,EAAE,CAAC;YAC/C,MAAM,IAAI,KAAK,CAAC,mCAAmC,GAAG,CAAC,QAAQ,CAAC,KAAK,CAAC,EAAE,CAAC,CAAA;QAC3E,CAAC;QACD,OAAO,GAAG,CAAA;IACZ,CAAC"}
|
package/dist/device/wostrip.d.ts
CHANGED
|
@@ -2,41 +2,60 @@ import type { stripLightServiceData } from '../types/bledevicestatus.js';
|
|
|
2
2
|
import { Buffer } from 'node:buffer';
|
|
3
3
|
import { SwitchbotDevice } from '../device.js';
|
|
4
4
|
/**
|
|
5
|
-
*
|
|
5
|
+
* Class representing a WoStrip device.
|
|
6
|
+
* @see https://github.com/OpenWonderLabs/SwitchBotAPI-BLE/blob/latest/devicetypes/ledstriplight.md
|
|
6
7
|
*/
|
|
7
8
|
export declare class WoStrip extends SwitchbotDevice {
|
|
8
|
-
static parseServiceData(serviceData: Buffer, onlog: ((message: string) => void) | undefined): Promise<stripLightServiceData | null>;
|
|
9
9
|
/**
|
|
10
|
-
*
|
|
10
|
+
* Parses the service data from the SwitchBot Strip Light.
|
|
11
|
+
* @param {Buffer} serviceData - The service data buffer.
|
|
12
|
+
* @param {(message: string) => void} [onlog] - Optional logging function.
|
|
13
|
+
* @returns {Promise<stripLightServiceData | null>} - Parsed service data or null if invalid.
|
|
11
14
|
*/
|
|
12
|
-
|
|
15
|
+
static parseServiceData(serviceData: Buffer, onlog?: (message: string) => void): Promise<stripLightServiceData | null>;
|
|
13
16
|
/**
|
|
14
|
-
*
|
|
17
|
+
* Reads the state of the strip light.
|
|
18
|
+
* @returns {Promise<boolean>} - Resolves with true if the strip light is ON, false otherwise.
|
|
15
19
|
*/
|
|
16
|
-
|
|
20
|
+
readState(): Promise<boolean>;
|
|
17
21
|
/**
|
|
18
|
-
*
|
|
22
|
+
* Sets the state of the strip light.
|
|
23
|
+
* @public
|
|
24
|
+
* @param {number[]} reqByteArray - The request byte array.
|
|
25
|
+
* @returns {Promise<boolean>} - Resolves with true if the operation was successful.
|
|
19
26
|
*/
|
|
20
|
-
|
|
27
|
+
setState(reqByteArray: number[]): Promise<boolean>;
|
|
21
28
|
/**
|
|
22
|
-
*
|
|
29
|
+
* Turns the strip light on.
|
|
30
|
+
* @returns {Promise<boolean>} - Resolves with true if the strip light is ON.
|
|
23
31
|
*/
|
|
24
|
-
|
|
32
|
+
turnOn(): Promise<boolean>;
|
|
25
33
|
/**
|
|
26
|
-
*
|
|
34
|
+
* Turns the strip light off.
|
|
35
|
+
* @returns {Promise<boolean>} - Resolves with true if the strip light is OFF.
|
|
27
36
|
*/
|
|
28
|
-
|
|
37
|
+
turnOff(): Promise<boolean>;
|
|
29
38
|
/**
|
|
30
|
-
*
|
|
39
|
+
* Sets the brightness of the strip light.
|
|
40
|
+
* @param {number} brightness - The brightness percentage (0-100).
|
|
41
|
+
* @returns {Promise<boolean>} - Resolves with true if the operation was successful.
|
|
31
42
|
*/
|
|
32
|
-
|
|
43
|
+
setBrightness(brightness: number): Promise<boolean>;
|
|
33
44
|
/**
|
|
34
|
-
*
|
|
45
|
+
* Sets the RGB values of the strip light.
|
|
46
|
+
* @param {number} brightness - The brightness percentage (0-100).
|
|
47
|
+
* @param {number} red - The red value (0-255).
|
|
48
|
+
* @param {number} green - The green value (0-255).
|
|
49
|
+
* @param {number} blue - The blue value (0-255).
|
|
50
|
+
* @returns {Promise<boolean>} - Resolves with true if the operation was successful.
|
|
35
51
|
*/
|
|
36
|
-
setRGB(brightness: number, red: number, green: number, blue: number): Promise<
|
|
52
|
+
setRGB(brightness: number, red: number, green: number, blue: number): Promise<boolean>;
|
|
37
53
|
/**
|
|
38
|
-
*
|
|
54
|
+
* Operates the strip light with the given byte array.
|
|
55
|
+
* @public
|
|
56
|
+
* @param {number[]} bytes - The byte array to send.
|
|
57
|
+
* @returns {Promise<boolean>} - Resolves with true if the operation was successful.
|
|
39
58
|
*/
|
|
40
|
-
operateStripLight(bytes: number[]): Promise<
|
|
59
|
+
operateStripLight(bytes: number[]): Promise<boolean>;
|
|
41
60
|
}
|
|
42
61
|
//# sourceMappingURL=wostrip.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"wostrip.d.ts","sourceRoot":"","sources":["../../src/device/wostrip.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"wostrip.d.ts","sourceRoot":"","sources":["../../src/device/wostrip.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,6BAA6B,CAAA;AAExE,OAAO,EAAE,MAAM,EAAE,MAAM,aAAa,CAAA;AAEpC,OAAO,EAAE,eAAe,EAAE,MAAM,cAAc,CAAA;AAG9C;;;GAGG;AACH,qBAAa,OAAQ,SAAQ,eAAe;IAC1C;;;;;OAKG;WACU,gBAAgB,CAC3B,WAAW,EAAE,MAAM,EACnB,KAAK,CAAC,EAAE,CAAC,OAAO,EAAE,MAAM,KAAK,IAAI,GAChC,OAAO,CAAC,qBAAqB,GAAG,IAAI,CAAC;IAoCxC;;;OAGG;IACG,SAAS,IAAI,OAAO,CAAC,OAAO,CAAC;IAInC;;;;;OAKG;IACU,QAAQ,CAAC,YAAY,EAAE,MAAM,EAAE,GAAG,OAAO,CAAC,OAAO,CAAC;IAK/D;;;OAGG;IACG,MAAM,IAAI,OAAO,CAAC,OAAO,CAAC;IAIhC;;;OAGG;IACG,OAAO,IAAI,OAAO,CAAC,OAAO,CAAC;IAIjC;;;;OAIG;IACG,aAAa,CAAC,UAAU,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC;IAOzD;;;;;;;OAOG;IACG,MAAM,CAAC,UAAU,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC;IAa5F;;;;;OAKG;IACU,iBAAiB,CAAC,KAAK,EAAE,MAAM,EAAE,GAAG,OAAO,CAAC,OAAO,CAAC;CAelE"}
|