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,23 +1,16 @@
|
|
|
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 { WoSmartLockCommands } from '../settings.js';
|
|
8
5
|
import { SwitchBotBLEModel, SwitchBotBLEModelFriendlyName, SwitchBotBLEModelName } from '../types/types.js';
|
|
9
|
-
|
|
6
|
+
/**
|
|
7
|
+
* Class representing a WoSmartLock device.
|
|
8
|
+
* @see https://github.com/OpenWonderLabs/SwitchBotAPI-BLE/blob/latest/devicetypes/lock.md
|
|
9
|
+
*/
|
|
10
10
|
export class WoSmartLock extends SwitchbotDevice {
|
|
11
|
-
iv;
|
|
12
|
-
key_id;
|
|
13
|
-
encryption_key;
|
|
14
|
-
static COMMAND_GET_CKiv = '570f2103';
|
|
15
|
-
static COMMAND_LOCK_INFO = '570f4f8101';
|
|
16
|
-
static COMMAND_UNLOCK = '570f4e01011080';
|
|
17
|
-
static COMMAND_UNLOCK_NO_UNLATCH = '570f4e010110a0';
|
|
18
|
-
static COMMAND_LOCK = '570f4e01011000';
|
|
19
|
-
static COMMAND_ENABLE_NOTIFICATIONS = '570e01001e00008101';
|
|
20
|
-
static COMMAND_DISABLE_NOTIFICATIONS = '570e00';
|
|
11
|
+
iv = null;
|
|
12
|
+
key_id = '';
|
|
13
|
+
encryption_key = null;
|
|
21
14
|
static Result = {
|
|
22
15
|
ERROR: 0x00,
|
|
23
16
|
SUCCESS: 0x01,
|
|
@@ -25,227 +18,146 @@ export class WoSmartLock extends SwitchbotDevice {
|
|
|
25
18
|
};
|
|
26
19
|
static async validateResponse(res) {
|
|
27
20
|
if (res.length >= 3) {
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
case WoSmartLock.Result.SUCCESS_LOW_BATTERY:
|
|
32
|
-
return WoSmartLock.Result.SUCCESS_LOW_BATTERY;
|
|
21
|
+
const result = res.readUInt8(0);
|
|
22
|
+
if (result === WoSmartLock.Result.SUCCESS || result === WoSmartLock.Result.SUCCESS_LOW_BATTERY) {
|
|
23
|
+
return result;
|
|
33
24
|
}
|
|
34
25
|
}
|
|
35
26
|
return WoSmartLock.Result.ERROR;
|
|
36
27
|
}
|
|
37
28
|
static getLockStatus(code) {
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
return 'LOCKING_STOP';
|
|
49
|
-
case 0b1010000:
|
|
50
|
-
return 'UNLOCKING_STOP';
|
|
51
|
-
case 0b1100000: // Only EU lock type
|
|
52
|
-
return 'NOT_FULLY_LOCKED';
|
|
53
|
-
default:
|
|
54
|
-
return 'UNKNOWN';
|
|
55
|
-
}
|
|
29
|
+
const statusMap = {
|
|
30
|
+
0b0000000: 'LOCKED',
|
|
31
|
+
0b0010000: 'UNLOCKED',
|
|
32
|
+
0b0100000: 'LOCKING',
|
|
33
|
+
0b0110000: 'UNLOCKING',
|
|
34
|
+
0b1000000: 'LOCKING_STOP',
|
|
35
|
+
0b1010000: 'UNLOCKING_STOP',
|
|
36
|
+
0b1100000: 'NOT_FULLY_LOCKED', // Only EU lock type
|
|
37
|
+
};
|
|
38
|
+
return statusMap[code] || 'UNKNOWN';
|
|
56
39
|
}
|
|
57
40
|
static async parseServiceData(serviceData, manufacturerData, onlog) {
|
|
58
41
|
if (manufacturerData.length < 11) {
|
|
59
|
-
|
|
60
|
-
onlog(`[parseServiceDataForWoSmartLock] Buffer length ${manufacturerData.length} is too short!`);
|
|
61
|
-
}
|
|
42
|
+
onlog?.(`[parseServiceDataForWoSmartLock] Buffer length ${manufacturerData.length} is too short!`);
|
|
62
43
|
return null;
|
|
63
44
|
}
|
|
64
|
-
// adv data needs both service data and manufacturer data
|
|
65
|
-
// byte var names based on documentation
|
|
66
45
|
const byte2 = serviceData.readUInt8(2);
|
|
67
46
|
const byte15 = manufacturerData.readUInt8(9);
|
|
68
47
|
const byte16 = manufacturerData.readUInt8(10);
|
|
69
|
-
const battery = byte2 & 0b01111111; // %
|
|
70
|
-
const calibration = !!(byte15 & 0b10000000);
|
|
71
|
-
const status = WoSmartLock.getLockStatus(byte15 & 0b01110000);
|
|
72
|
-
const update_from_secondary_lock = !!(byte15 & 0b00001000);
|
|
73
|
-
const door_open = !!(byte15 & 0b00000100);
|
|
74
|
-
const double_lock_mode = !!(byte16 & 0b10000000);
|
|
75
|
-
const unclosed_alarm = !!(byte16 & 0b00100000);
|
|
76
|
-
const unlocked_alarm = !!(byte16 & 0b00010000);
|
|
77
|
-
const auto_lock_paused = !!(byte16 & 0b00000010);
|
|
78
|
-
const night_latch = !!(manufacturerData.length > 11 && manufacturerData.readUInt8(11) & 0b00000001);
|
|
79
48
|
const data = {
|
|
80
49
|
model: SwitchBotBLEModel.Lock,
|
|
81
50
|
modelName: SwitchBotBLEModelName.Lock,
|
|
82
51
|
modelFriendlyName: SwitchBotBLEModelFriendlyName.Lock,
|
|
83
|
-
battery,
|
|
84
|
-
calibration,
|
|
85
|
-
status,
|
|
86
|
-
update_from_secondary_lock,
|
|
87
|
-
door_open,
|
|
88
|
-
double_lock_mode,
|
|
89
|
-
unclosed_alarm,
|
|
90
|
-
unlocked_alarm,
|
|
91
|
-
auto_lock_paused,
|
|
92
|
-
night_latch,
|
|
52
|
+
battery: byte2 & 0b01111111,
|
|
53
|
+
calibration: !!(byte15 & 0b10000000),
|
|
54
|
+
status: WoSmartLock.getLockStatus(byte15 & 0b01110000),
|
|
55
|
+
update_from_secondary_lock: !!(byte15 & 0b00001000),
|
|
56
|
+
door_open: !!(byte15 & 0b00000100),
|
|
57
|
+
double_lock_mode: !!(byte16 & 0b10000000),
|
|
58
|
+
unclosed_alarm: !!(byte16 & 0b00100000),
|
|
59
|
+
unlocked_alarm: !!(byte16 & 0b00010000),
|
|
60
|
+
auto_lock_paused: !!(byte16 & 0b00000010),
|
|
61
|
+
night_latch: !!(manufacturerData.length > 11 && manufacturerData.readUInt8(11) & 0b00000001),
|
|
93
62
|
};
|
|
94
63
|
return data;
|
|
95
64
|
}
|
|
96
65
|
constructor(peripheral, noble) {
|
|
97
66
|
super(peripheral, noble);
|
|
98
|
-
this.iv = null;
|
|
99
|
-
this.key_id = '';
|
|
100
|
-
this.encryption_key = null;
|
|
101
67
|
}
|
|
102
|
-
|
|
103
|
-
*
|
|
104
|
-
*
|
|
105
|
-
*
|
|
106
|
-
|
|
107
|
-
* - keyId, encryptionKey
|
|
108
|
-
*
|
|
109
|
-
* [Return value]
|
|
110
|
-
* - void
|
|
111
|
-
* ---------------------------------------------------------------- */
|
|
68
|
+
/**
|
|
69
|
+
* Initializes the encryption key info for valid lock communication.
|
|
70
|
+
* @param {string} keyId - The key ID.
|
|
71
|
+
* @param {string} encryptionKey - The encryption key.
|
|
72
|
+
*/
|
|
112
73
|
async setKey(keyId, encryptionKey) {
|
|
113
74
|
this.iv = null;
|
|
114
75
|
this.key_id = keyId;
|
|
115
76
|
this.encryption_key = Buffer.from(encryptionKey, 'hex');
|
|
116
77
|
}
|
|
117
|
-
|
|
118
|
-
*
|
|
119
|
-
* -
|
|
120
|
-
|
|
121
|
-
* [Arguments]
|
|
122
|
-
* - none
|
|
123
|
-
*
|
|
124
|
-
* [Return value]
|
|
125
|
-
* - Promise object
|
|
126
|
-
* WoSmartLock.LockResult will be passed to the `resolve()`.
|
|
127
|
-
* ---------------------------------------------------------------- */
|
|
78
|
+
/**
|
|
79
|
+
* Unlocks the Smart Lock.
|
|
80
|
+
* @returns {Promise<number>} - The result of the unlock operation.
|
|
81
|
+
*/
|
|
128
82
|
async unlock() {
|
|
129
|
-
await this.operateLock(
|
|
130
|
-
|
|
131
|
-
if (resBuf) {
|
|
132
|
-
return WoSmartLock.validateResponse(resBuf);
|
|
133
|
-
}
|
|
134
|
-
else {
|
|
135
|
-
return WoSmartLockPro.Result.ERROR;
|
|
136
|
-
}
|
|
137
|
-
})
|
|
138
|
-
.catch((error) => {
|
|
139
|
-
return error;
|
|
140
|
-
});
|
|
83
|
+
const resBuf = await this.operateLock(WoSmartLockCommands.UNLOCK);
|
|
84
|
+
return resBuf ? WoSmartLock.validateResponse(resBuf) : WoSmartLock.Result.ERROR;
|
|
141
85
|
}
|
|
142
|
-
|
|
143
|
-
*
|
|
144
|
-
* -
|
|
145
|
-
|
|
146
|
-
* [Arguments]
|
|
147
|
-
* - none
|
|
148
|
-
*
|
|
149
|
-
* [Return value]
|
|
150
|
-
* - Promise object
|
|
151
|
-
* WoSmartLock.LockResult will be passed to the `resolve()`.
|
|
152
|
-
* ---------------------------------------------------------------- */
|
|
86
|
+
/**
|
|
87
|
+
* Unlocks the Smart Lock without unlatching the door.
|
|
88
|
+
* @returns {Promise<number>} - The result of the unlock operation.
|
|
89
|
+
*/
|
|
153
90
|
async unlockNoUnlatch() {
|
|
154
|
-
await this.operateLock(
|
|
155
|
-
|
|
156
|
-
if (resBuf) {
|
|
157
|
-
return WoSmartLock.validateResponse(resBuf);
|
|
158
|
-
}
|
|
159
|
-
else {
|
|
160
|
-
throw new Error('Failed to retrieve response buffer from the device.');
|
|
161
|
-
}
|
|
162
|
-
})
|
|
163
|
-
.catch((error) => {
|
|
164
|
-
return error;
|
|
165
|
-
});
|
|
91
|
+
const resBuf = await this.operateLock(WoSmartLockCommands.UNLOCK_NO_UNLATCH);
|
|
92
|
+
return resBuf ? WoSmartLock.validateResponse(resBuf) : WoSmartLock.Result.ERROR;
|
|
166
93
|
}
|
|
167
|
-
|
|
168
|
-
*
|
|
169
|
-
* -
|
|
170
|
-
|
|
171
|
-
* [Arguments]
|
|
172
|
-
* - none
|
|
173
|
-
*
|
|
174
|
-
* [Return value]
|
|
175
|
-
* - Promise object
|
|
176
|
-
* WoSmartLock.LockResult will be passed to the `resolve()`.
|
|
177
|
-
* ---------------------------------------------------------------- */
|
|
94
|
+
/**
|
|
95
|
+
* Locks the Smart Lock.
|
|
96
|
+
* @returns {Promise<number>} - The result of the lock operation.
|
|
97
|
+
*/
|
|
178
98
|
async lock() {
|
|
179
|
-
await this.operateLock(
|
|
180
|
-
|
|
181
|
-
if (resBuf) {
|
|
182
|
-
return WoSmartLock.validateResponse(resBuf);
|
|
183
|
-
}
|
|
184
|
-
else {
|
|
185
|
-
throw new Error('Failed to retrieve response buffer from the device.');
|
|
186
|
-
}
|
|
187
|
-
})
|
|
188
|
-
.catch((error) => {
|
|
189
|
-
return error;
|
|
190
|
-
});
|
|
99
|
+
const resBuf = await this.operateLock(WoSmartLockCommands.LOCK);
|
|
100
|
+
return resBuf ? WoSmartLock.validateResponse(resBuf) : WoSmartLock.Result.ERROR;
|
|
191
101
|
}
|
|
192
|
-
|
|
193
|
-
* info
|
|
194
|
-
* -
|
|
195
|
-
|
|
196
|
-
* [Arguments]
|
|
197
|
-
* - none
|
|
198
|
-
*
|
|
199
|
-
* [Return value]
|
|
200
|
-
* - Promise object
|
|
201
|
-
* state object will be passed to the `resolve()`
|
|
202
|
-
* ---------------------------------------------------------------- */
|
|
102
|
+
/**
|
|
103
|
+
* Gets general state info from the Smart Lock.
|
|
104
|
+
* @returns {Promise<object | null>} - The state object or null if an error occurred.
|
|
105
|
+
*/
|
|
203
106
|
async info() {
|
|
204
|
-
await this.operateLock(
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
}
|
|
216
|
-
else {
|
|
217
|
-
throw new Error('Failed to retrieve response buffer from the device.');
|
|
218
|
-
}
|
|
219
|
-
})
|
|
220
|
-
.catch((error) => {
|
|
221
|
-
return error;
|
|
222
|
-
});
|
|
107
|
+
const resBuf = await this.operateLock(WoSmartLockCommands.LOCK_INFO);
|
|
108
|
+
if (resBuf) {
|
|
109
|
+
return {
|
|
110
|
+
calibration: Boolean(resBuf[1] & 0b10000000),
|
|
111
|
+
status: WoSmartLock.getLockStatus((resBuf[1] & 0b01110000)),
|
|
112
|
+
door_open: Boolean(resBuf[1] & 0b00000100),
|
|
113
|
+
unclosed_alarm: Boolean(resBuf[2] & 0b00100000),
|
|
114
|
+
unlocked_alarm: Boolean(resBuf[2] & 0b00010000),
|
|
115
|
+
};
|
|
116
|
+
}
|
|
117
|
+
return null;
|
|
223
118
|
}
|
|
119
|
+
/**
|
|
120
|
+
* Encrypts a string using AES-128-CTR.
|
|
121
|
+
* @param {string} str - The string to encrypt.
|
|
122
|
+
* @returns {Promise<string>} - The encrypted string in hex format.
|
|
123
|
+
*/
|
|
224
124
|
async encrypt(str) {
|
|
225
125
|
const cipher = Crypto.createCipheriv('aes-128-ctr', this.encryption_key, this.iv);
|
|
226
126
|
return Buffer.concat([cipher.update(str, 'hex'), cipher.final()]).toString('hex');
|
|
227
127
|
}
|
|
128
|
+
/**
|
|
129
|
+
* Decrypts a buffer using AES-128-CTR.
|
|
130
|
+
* @param {Buffer} data - The data to decrypt.
|
|
131
|
+
* @returns {Promise<Buffer>} - The decrypted data.
|
|
132
|
+
*/
|
|
228
133
|
async decrypt(data) {
|
|
229
134
|
const decipher = Crypto.createDecipheriv('aes-128-ctr', this.encryption_key, this.iv);
|
|
230
135
|
return Buffer.concat([decipher.update(data), decipher.final()]);
|
|
231
136
|
}
|
|
137
|
+
/**
|
|
138
|
+
* Retrieves the IV from the device.
|
|
139
|
+
* @returns {Promise<Buffer>} - The IV buffer.
|
|
140
|
+
*/
|
|
232
141
|
async getIv() {
|
|
233
|
-
if (this.iv
|
|
234
|
-
const res = await this.operateLock(
|
|
142
|
+
if (!this.iv) {
|
|
143
|
+
const res = await this.operateLock(WoSmartLockCommands.GET_CKIV + this.key_id, false);
|
|
235
144
|
if (res) {
|
|
236
145
|
this.iv = res.subarray(4);
|
|
237
146
|
}
|
|
238
147
|
else {
|
|
239
|
-
// Handle the case when 'res' is undefined
|
|
240
|
-
// For example, you can throw an error or set a default value for 'this.iv'
|
|
241
148
|
throw new Error('Failed to retrieve IV from the device.');
|
|
242
149
|
}
|
|
243
150
|
}
|
|
244
151
|
return this.iv;
|
|
245
152
|
}
|
|
153
|
+
/**
|
|
154
|
+
* Sends an encrypted command to the device.
|
|
155
|
+
* @param {string} key - The command key.
|
|
156
|
+
* @returns {Promise<Buffer>} - The response buffer.
|
|
157
|
+
*/
|
|
246
158
|
async encryptedCommand(key) {
|
|
247
159
|
const iv = await this.getIv();
|
|
248
|
-
const req = Buffer.from(key.substring(0, 2) + this.key_id + Buffer.from(iv.subarray(0, 2)).toString('hex') + this.encrypt(key.substring(2)), 'hex');
|
|
160
|
+
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');
|
|
249
161
|
const bytes = await this.command(req);
|
|
250
162
|
const buf = Buffer.from(bytes);
|
|
251
163
|
const code = WoSmartLock.validateResponse(buf);
|
|
@@ -256,24 +168,24 @@ export class WoSmartLock extends SwitchbotDevice {
|
|
|
256
168
|
throw new Error(`The device returned an error: 0x${buf.toString('hex')}`);
|
|
257
169
|
}
|
|
258
170
|
}
|
|
171
|
+
/**
|
|
172
|
+
* Operates the lock with the given command.
|
|
173
|
+
* @param {string} key - The command key.
|
|
174
|
+
* @param {boolean} [encrypt] - Whether to encrypt the command.
|
|
175
|
+
* @returns {Promise<Buffer>} - The response buffer.
|
|
176
|
+
*/
|
|
259
177
|
async operateLock(key, encrypt = true) {
|
|
260
|
-
// encrypted command
|
|
261
178
|
if (encrypt) {
|
|
262
|
-
return
|
|
179
|
+
return this.encryptedCommand(key);
|
|
263
180
|
}
|
|
264
181
|
const req = Buffer.from(`${key.substring(0, 2)}000000${key.substring(2)}`, 'hex');
|
|
265
|
-
await this.command(req)
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
return buf;
|
|
273
|
-
}
|
|
274
|
-
}).catch((error) => {
|
|
275
|
-
return error;
|
|
276
|
-
});
|
|
182
|
+
const bytes = await this.command(req);
|
|
183
|
+
const buf = Buffer.from(bytes);
|
|
184
|
+
const code = WoSmartLock.validateResponse(buf);
|
|
185
|
+
if (await code === WoSmartLock.Result.ERROR) {
|
|
186
|
+
throw new Error(`The device returned an error: 0x${buf.toString('hex')}`);
|
|
187
|
+
}
|
|
188
|
+
return buf;
|
|
277
189
|
}
|
|
278
190
|
}
|
|
279
191
|
//# sourceMappingURL=wosmartlock.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"wosmartlock.js","sourceRoot":"","sources":["../../src/device/wosmartlock.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"wosmartlock.js","sourceRoot":"","sources":["../../src/device/wosmartlock.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,mBAAmB,EAAE,MAAM,gBAAgB,CAAA;AACpD,OAAO,EAAE,iBAAiB,EAAE,6BAA6B,EAAE,qBAAqB,EAAE,MAAM,mBAAmB,CAAA;AAE3G;;;GAGG;AACH,MAAM,OAAO,WAAY,SAAQ,eAAe;IACvC,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,KAAK,CAAC,gBAAgB,CAAC,GAAW;QACvC,IAAI,GAAG,CAAC,MAAM,IAAI,CAAC,EAAE,CAAC;YACpB,MAAM,MAAM,GAAG,GAAG,CAAC,SAAS,CAAC,CAAC,CAAC,CAAA;YAC/B,IAAI,MAAM,KAAK,WAAW,CAAC,MAAM,CAAC,OAAO,IAAI,MAAM,KAAK,WAAW,CAAC,MAAM,CAAC,mBAAmB,EAAE,CAAC;gBAC/F,OAAO,MAAM,CAAA;YACf,CA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AAG,CAAC,CAAA;QAE9C,IAAI,MAAM,IAAI,KAAK,WAAW,CAAC,MAAM,CAAC,KAAK,EAAE,CAAC;YAC5C,MAAM,IAAI,KAAK,CAAC,mCAAmC,GAAG,CAAC,QAAQ,CAAC,KAAK,CAAC,EAAE,CAAC,CAAA;QAC3E,CAAC;QACD,OAAO,GAAG,CAAA;IACZ,CAAC"}
|
|
@@ -2,35 +2,78 @@ import type * as Noble from '@stoprocent/noble';
|
|
|
2
2
|
import type { lockProServiceData } from '../types/bledevicestatus.js';
|
|
3
3
|
import { Buffer } from 'node:buffer';
|
|
4
4
|
import { SwitchbotDevice } from '../device.js';
|
|
5
|
+
/**
|
|
6
|
+
* Class representing a WoSmartLockPro device.
|
|
7
|
+
* @see https://github.com/OpenWonderLabs/SwitchBotAPI-BLE/blob/latest/devicetypes/lock.md
|
|
8
|
+
*/
|
|
5
9
|
export declare class WoSmartLockPro extends SwitchbotDevice {
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
static COMMAND_GET_CK_IV: string;
|
|
10
|
-
static COMMAND_LOCK_INFO: string;
|
|
11
|
-
static COMMAND_UNLOCK: string;
|
|
12
|
-
static COMMAND_UNLOCK_NO_UNLATCH: string;
|
|
13
|
-
static COMMAND_LOCK: string;
|
|
14
|
-
static COMMAND_ENABLE_NOTIFICATIONS: string;
|
|
15
|
-
static COMMAND_DISABLE_NOTIFICATIONS: string;
|
|
10
|
+
iv: Buffer | null;
|
|
11
|
+
key_id: string;
|
|
12
|
+
encryption_key: Buffer | null;
|
|
16
13
|
static Result: {
|
|
17
14
|
ERROR: number;
|
|
18
15
|
SUCCESS: number;
|
|
19
16
|
SUCCESS_LOW_BATTERY: number;
|
|
20
17
|
};
|
|
21
|
-
static validateResponse(res: Buffer): number
|
|
22
|
-
static getLockStatus(code: number):
|
|
23
|
-
static parseServiceData(serviceData: Buffer, manufacturerData: Buffer, onlog
|
|
18
|
+
static validateResponse(res: Buffer): Promise<number>;
|
|
19
|
+
static getLockStatus(code: number): string;
|
|
20
|
+
static parseServiceData(serviceData: Buffer, manufacturerData: Buffer, onlog?: (message: string) => void): Promise<lockProServiceData | null>;
|
|
24
21
|
constructor(peripheral: Noble.Peripheral, noble: typeof Noble);
|
|
22
|
+
/**
|
|
23
|
+
* Initializes the encryption key info for valid lock communication.
|
|
24
|
+
* @param {string} keyId - The key ID.
|
|
25
|
+
* @param {string} encryptionKey - The encryption key.
|
|
26
|
+
*/
|
|
25
27
|
setKey(keyId: string, encryptionKey: string): Promise<void>;
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
28
|
+
/**
|
|
29
|
+
* Unlocks the Smart Lock.
|
|
30
|
+
* @returns {Promise<number>} - The result of the unlock operation.
|
|
31
|
+
*/
|
|
32
|
+
unlock(): Promise<number>;
|
|
33
|
+
/**
|
|
34
|
+
* Unlocks the Smart Lock without unlatching the door.
|
|
35
|
+
* @returns {Promise<number>} - The result of the unlock operation.
|
|
36
|
+
*/
|
|
37
|
+
unlockNoUnlatch(): Promise<number>;
|
|
38
|
+
/**
|
|
39
|
+
* Locks the Smart Lock.
|
|
40
|
+
* @returns {Promise<number>} - The result of the lock operation.
|
|
41
|
+
*/
|
|
42
|
+
lock(): Promise<number>;
|
|
43
|
+
/**
|
|
44
|
+
* Gets general state info from the Smart Lock.
|
|
45
|
+
* @returns {Promise<object | null>} - The state object or null if an error occurred.
|
|
46
|
+
*/
|
|
47
|
+
info(): Promise<object | null>;
|
|
48
|
+
/**
|
|
49
|
+
* Encrypts a string using AES-128-CTR.
|
|
50
|
+
* @param {string} str - The string to encrypt.
|
|
51
|
+
* @returns {Promise<string>} - The encrypted string in hex format.
|
|
52
|
+
*/
|
|
30
53
|
encrypt(str: string): Promise<string>;
|
|
54
|
+
/**
|
|
55
|
+
* Decrypts a buffer using AES-128-CTR.
|
|
56
|
+
* @param {Buffer} data - The data to decrypt.
|
|
57
|
+
* @returns {Promise<Buffer>} - The decrypted data.
|
|
58
|
+
*/
|
|
31
59
|
decrypt(data: Buffer): Promise<Buffer>;
|
|
60
|
+
/**
|
|
61
|
+
* Retrieves the IV from the device.
|
|
62
|
+
* @returns {Promise<Buffer>} - The IV buffer.
|
|
63
|
+
*/
|
|
32
64
|
getIv(): Promise<Buffer>;
|
|
65
|
+
/**
|
|
66
|
+
* Sends an encrypted command to the device.
|
|
67
|
+
* @param {string} key - The command key.
|
|
68
|
+
* @returns {Promise<Buffer>} - The response buffer.
|
|
69
|
+
*/
|
|
33
70
|
encryptedCommand(key: string): Promise<Buffer>;
|
|
34
|
-
|
|
71
|
+
/**
|
|
72
|
+
* Operates the lock with the given command.
|
|
73
|
+
* @param {string} key - The command key.
|
|
74
|
+
* @param {boolean} [encrypt] - Whether to encrypt the command.
|
|
75
|
+
* @returns {Promise<Buffer>} - The response buffer.
|
|
76
|
+
*/
|
|
77
|
+
operateLockPro(key: string, encrypt?: boolean): Promise<Buffer>;
|
|
35
78
|
}
|
|
36
79
|
//# sourceMappingURL=wosmartlockpro.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"wosmartlockpro.d.ts","sourceRoot":"","sources":["../../src/device/wosmartlockpro.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"wosmartlockpro.d.ts","sourceRoot":"","sources":["../../src/device/wosmartlockpro.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,KAAK,KAAK,MAAM,mBAAmB,CAAA;AAE/C,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,6BAA6B,CAAA;AAErE,OAAO,EAAE,MAAM,EAAE,MAAM,aAAa,CAAA;AAGpC,OAAO,EAAE,eAAe,EAAE,MAAM,cAAc,CAAA;AAI9C;;;GAGG;AACH,qBAAa,cAAe,SAAQ,eAAe;IAC1C,EAAE,EAAE,MAAM,GAAG,IAAI,CAAO;IACxB,MAAM,EAAE,MAAM,CAAK;IACnB,cAAc,EAAE,MAAM,GAAG,IAAI,CAAO;IAE3C,MAAM,CA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