@ray-js/lock-sdk 1.0.1-beta-1 → 1.0.1-beta-2
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.
|
@@ -16,10 +16,11 @@ export const setKey = [{
|
|
|
16
16
|
name: "endTime",
|
|
17
17
|
bytes: 4
|
|
18
18
|
}, {
|
|
19
|
-
name: "validNum"
|
|
19
|
+
name: "validNum",
|
|
20
|
+
bytes: 2
|
|
20
21
|
}, {
|
|
21
22
|
name: "key",
|
|
22
|
-
|
|
23
|
+
loop: true
|
|
23
24
|
}];
|
|
24
25
|
|
|
25
26
|
/**
|
|
@@ -44,7 +45,7 @@ export const open = [{
|
|
|
44
45
|
bytes: 2
|
|
45
46
|
}, {
|
|
46
47
|
name: "key",
|
|
47
|
-
|
|
48
|
+
loop: true
|
|
48
49
|
}, {
|
|
49
50
|
name: "type",
|
|
50
51
|
bytes: 2
|
package/lib/open.js
CHANGED
|
@@ -108,10 +108,20 @@ const _doAction = async (isOpen, timeout) => {
|
|
|
108
108
|
await syncRemoteSerectKey();
|
|
109
109
|
|
|
110
110
|
// 蓝牙在线时,通过蓝牙开锁
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
111
|
+
let pw = "";
|
|
112
|
+
try {
|
|
113
|
+
const {
|
|
114
|
+
password
|
|
115
|
+
} = await getDoorKey(devInfo.devId);
|
|
116
|
+
pw = await decrypt(devInfo.devId, password);
|
|
117
|
+
} catch (e) {
|
|
118
|
+
// 获取密钥失败,则尝试同步密钥
|
|
119
|
+
await syncRemoteSerectKey(true);
|
|
120
|
+
const {
|
|
121
|
+
password
|
|
122
|
+
} = await getDoorKey(devInfo.devId);
|
|
123
|
+
pw = await decrypt(devInfo.devId, password);
|
|
124
|
+
}
|
|
115
125
|
const response = await publishDps({
|
|
116
126
|
[dpCodes.remoteNoDpKey]: dpUtils.format({
|
|
117
127
|
status: Number(isOpen),
|
|
@@ -123,10 +133,10 @@ const _doAction = async (isOpen, timeout) => {
|
|
|
123
133
|
timeout,
|
|
124
134
|
checkReport
|
|
125
135
|
});
|
|
126
|
-
|
|
136
|
+
|
|
127
137
|
// 状态码为 0 表示开锁成功,其他 0x01:失败 0x02:失效 0x03:秘钥次数使用完 0x04:秘钥不在有效期内 0x05:秘钥比对错误
|
|
128
|
-
if (
|
|
129
|
-
throw getReportError(
|
|
138
|
+
if (response.status !== 0) {
|
|
139
|
+
throw getReportError(response.status);
|
|
130
140
|
}
|
|
131
141
|
|
|
132
142
|
// 开锁成功
|
|
@@ -12,21 +12,24 @@ import { ProductCommunicationType } from "../constant";
|
|
|
12
12
|
|
|
13
13
|
/**
|
|
14
14
|
* 同步密钥
|
|
15
|
+
* @param force 是否强制同步
|
|
15
16
|
*/
|
|
16
|
-
const syncRemoteSerectKey = async
|
|
17
|
+
const syncRemoteSerectKey = async force => {
|
|
17
18
|
const useNear = isUseNearChannel();
|
|
18
19
|
if (useNear) {
|
|
19
20
|
try {
|
|
20
21
|
const isSupportBle = config.communication.includes(ProductCommunicationType.BLUETOOTH);
|
|
21
22
|
// 双模下
|
|
22
23
|
if (config.communication.length > 1 && isSupportBle) {
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
24
|
+
if (!force) {
|
|
25
|
+
// 如果当前的远程解锁密钥设置 为空、或失败、或主动请求获取,则进行同步
|
|
26
|
+
const keyValue = getDpValue(dpCodes.remoteNoPdSetkey);
|
|
27
|
+
if (keyValue) {
|
|
28
|
+
const keyData = dpUtils.parse(getDpValue(dpCodes.remoteNoPdSetkey), reportSetKeyMap);
|
|
29
|
+
// 已成功同步,则不进行同步
|
|
30
|
+
if (keyData.status === 0) {
|
|
31
|
+
return;
|
|
32
|
+
}
|
|
30
33
|
}
|
|
31
34
|
}
|
|
32
35
|
const {
|