@ray-js/lock-sdk 1.0.1 → 1.0.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.
- package/lib/api/index.js +13 -15
- package/lib/api/linkage.d.ts +0 -18
- package/lib/api/linkage.js +61 -81
- package/lib/api/lock.d.ts +0 -69
- package/lib/api/lock.js +91 -113
- package/lib/api/log.d.ts +0 -33
- package/lib/api/log.js +33 -38
- package/lib/api/setting.d.ts +0 -11
- package/lib/api/setting.js +17 -30
- package/lib/api/temp.d.ts +0 -48
- package/lib/api/temp.js +85 -115
- package/lib/api/user.d.ts +5 -54
- package/lib/api/user.js +40 -52
- package/lib/api/video.d.ts +0 -5
- package/lib/api/video.js +9 -15
- package/lib/config/dp-code/index.d.ts +0 -117
- package/lib/config/dp-code/index.js +79 -221
- package/lib/config/dp-map/common.d.ts +0 -3
- package/lib/config/dp-map/common.js +101 -116
- package/lib/config/dp-map/normal.js +29 -50
- package/lib/config/dp-map/open.d.ts +0 -16
- package/lib/config/dp-map/open.js +62 -63
- package/lib/config/dp-map/unlock-method-big.d.ts +0 -60
- package/lib/config/dp-map/unlock-method-big.js +196 -233
- package/lib/config/dp-map/unlock-method.d.ts +0 -63
- package/lib/config/dp-map/unlock-method.js +189 -227
- package/lib/config/index.d.ts +0 -25
- package/lib/config/index.js +21 -54
- package/lib/constant.d.ts +12 -40
- package/lib/constant.js +83 -136
- package/lib/event.d.ts +0 -6
- package/lib/event.js +1 -8
- package/lib/index.d.ts +0 -7
- package/lib/index.js +45 -71
- package/lib/interface.d.ts +0 -523
- package/lib/interface.js +1 -1
- package/lib/linkage.d.ts +0 -18
- package/lib/linkage.js +125 -162
- package/lib/log.d.ts +0 -50
- package/lib/log.js +255 -290
- package/lib/media.d.ts +0 -34
- package/lib/media.js +6 -77
- package/lib/open.d.ts +0 -35
- package/lib/open.js +129 -224
- package/lib/other.d.ts +0 -24
- package/lib/other.js +98 -159
- package/lib/parse/index.d.ts +0 -4
- package/lib/parse/index.js +13 -19
- package/lib/signal.d.ts +0 -13
- package/lib/signal.js +17 -31
- package/lib/sleep.d.ts +0 -42
- package/lib/sleep.js +41 -98
- package/lib/state.d.ts +0 -38
- package/lib/state.js +223 -369
- package/lib/sync/remote-serect-key.d.ts +0 -4
- package/lib/sync/remote-serect-key.js +33 -49
- package/lib/sync/t0.d.ts +0 -3
- package/lib/sync/t0.js +14 -21
- package/lib/sync/temp.d.ts +0 -5
- package/lib/sync/temp.js +68 -77
- package/lib/sync/unlock-mothod.d.ts +0 -3
- package/lib/sync/unlock-mothod.js +28 -40
- package/lib/temporary.d.ts +0 -149
- package/lib/temporary.js +469 -593
- package/lib/unlock-method.d.ts +0 -185
- package/lib/unlock-method.js +479 -650
- package/lib/user.d.ts +2 -81
- package/lib/user.js +202 -336
- package/lib/utils/base64-to-hex.js +10 -10
- package/lib/utils/byte.d.ts +0 -16
- package/lib/utils/byte.js +57 -68
- package/lib/utils/constant.js +7 -11
- package/lib/utils/device.d.ts +46 -83
- package/lib/utils/device.js +294 -322
- package/lib/utils/errors.js +75 -122
- package/lib/utils/event.js +79 -135
- package/lib/utils/hex-to-base64.js +5 -5
- package/lib/utils/hex-to-bytes.d.ts +0 -5
- package/lib/utils/hex-to-bytes.js +10 -15
- package/lib/utils/index.d.ts +0 -42
- package/lib/utils/index.js +247 -377
- package/lib/utils/log.d.ts +1 -4
- package/lib/utils/log.js +71 -74
- package/lib/utils/publishDps.d.ts +0 -5
- package/lib/utils/publishDps.js +58 -80
- package/package.json +3 -4
package/lib/media.js
CHANGED
|
@@ -1,80 +1,9 @@
|
|
|
1
1
|
import { getMediaUrl as getMediaUrlApi } from "./api/log";
|
|
2
2
|
import config from "./config";
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
*/
|
|
10
|
-
|
|
11
|
-
/**
|
|
12
|
-
* 获取视频的实际播放地址参数
|
|
13
|
-
*/
|
|
14
|
-
|
|
15
|
-
/**
|
|
16
|
-
* 获取视频的实际播放地址
|
|
17
|
-
* @param params
|
|
18
|
-
* @returns
|
|
19
|
-
*/
|
|
20
|
-
export const getMediaUrl = async params => {
|
|
21
|
-
return getMediaUrlApi({
|
|
22
|
-
devId: config.devInfo.devId,
|
|
23
|
-
mediaPath: params.mediaPath,
|
|
24
|
-
mediaBucket: params.mediaBucket
|
|
25
|
-
});
|
|
3
|
+
export const getMediaUrl = async (params) => {
|
|
4
|
+
return getMediaUrlApi({
|
|
5
|
+
devId: config.devInfo.devId,
|
|
6
|
+
mediaPath: params.mediaPath,
|
|
7
|
+
mediaBucket: params.mediaBucket,
|
|
8
|
+
});
|
|
26
9
|
};
|
|
27
|
-
|
|
28
|
-
/**
|
|
29
|
-
* 跳转到本地相册页面
|
|
30
|
-
*/
|
|
31
|
-
export const goToLocalAlbum = async params => {
|
|
32
|
-
return openNativeRouter("ipc_album_panel", {
|
|
33
|
-
extra_camera_uuid: config.devInfo.devId,
|
|
34
|
-
theme: typeof (params === null || params === void 0 ? void 0 : params.theme) === "string" ? params.theme === "dark" ? 1 : 2 : undefined
|
|
35
|
-
});
|
|
36
|
-
};
|
|
37
|
-
|
|
38
|
-
/**
|
|
39
|
-
* 跳转到回放页面
|
|
40
|
-
* @param params { theme?: "dark" | "light" }
|
|
41
|
-
* @returns Promise<boolean>
|
|
42
|
-
*/
|
|
43
|
-
export const goToPlayback = async params => {
|
|
44
|
-
const tabs = [];
|
|
45
|
-
if (config.codesById[dpCodes.recordModeAovSwitch]) {
|
|
46
|
-
tabs.push("cloud");
|
|
47
|
-
|
|
48
|
-
// 如果存在 dp updataInfo,则进行一次同步更新
|
|
49
|
-
if (config.codesById[dpCodes.updataInfo] && config.deviceStatus.type === "online") {
|
|
50
|
-
try {
|
|
51
|
-
await publishDps({
|
|
52
|
-
updata_info: "010001FF"
|
|
53
|
-
}, {
|
|
54
|
-
timeout: 6000
|
|
55
|
-
});
|
|
56
|
-
} catch (e) {
|
|
57
|
-
// 不处理
|
|
58
|
-
}
|
|
59
|
-
}
|
|
60
|
-
}
|
|
61
|
-
// 有 SD 卡时,支持本地回放
|
|
62
|
-
if (config.codesById[dpCodes.sdStatus]) {
|
|
63
|
-
tabs.push("local");
|
|
64
|
-
}
|
|
65
|
-
return openNativeRouter("camera_playbacks_panel", {
|
|
66
|
-
extra_camera_uuid: config.devInfo.devId,
|
|
67
|
-
defaultShowTabs: true,
|
|
68
|
-
isLowPowerDevice: true,
|
|
69
|
-
rotate: config.videoAngle,
|
|
70
|
-
tabs: JSON.stringify(tabs),
|
|
71
|
-
bizType: "doorLock",
|
|
72
|
-
theme: typeof (params === null || params === void 0 ? void 0 : params.theme) === "string" ? params.theme === "dark" ? 1 : 2 : undefined
|
|
73
|
-
});
|
|
74
|
-
};
|
|
75
|
-
export const openCameraSettings = async params => {
|
|
76
|
-
return openNativeRouter("camera_base_setting", {
|
|
77
|
-
extra_camera_uuid: config.devInfo.devId,
|
|
78
|
-
theme: typeof (params === null || params === void 0 ? void 0 : params.theme) === "string" ? params.theme === "dark" ? 1 : 2 : undefined
|
|
79
|
-
});
|
|
80
|
-
};
|
package/lib/open.d.ts
CHANGED
|
@@ -1,48 +1,13 @@
|
|
|
1
1
|
import { RemotePermission } from "./interface";
|
|
2
|
-
/**
|
|
3
|
-
* 校验是否可以远程开关门
|
|
4
|
-
*/
|
|
5
2
|
export declare const checkRemoteEnabled: () => Promise<void>;
|
|
6
|
-
/**
|
|
7
|
-
* 开锁
|
|
8
|
-
* @param option 开锁选项
|
|
9
|
-
* @param option.timeout 超时时间,默认 15000 毫秒
|
|
10
|
-
* @returns Promise<void>
|
|
11
|
-
*/
|
|
12
3
|
export declare const openDoor: (option?: {
|
|
13
4
|
timeout?: number;
|
|
14
5
|
} | undefined) => Promise<void>;
|
|
15
|
-
/**
|
|
16
|
-
* 关锁
|
|
17
|
-
* @param option 关锁选项
|
|
18
|
-
* @param option.timeout 超时时间,默认 15000 毫秒
|
|
19
|
-
* @returns Promise<void>
|
|
20
|
-
*/
|
|
21
6
|
export declare const closeDoor: (option?: {
|
|
22
7
|
timeout?: number;
|
|
23
8
|
} | undefined) => Promise<void>;
|
|
24
|
-
/**
|
|
25
|
-
* 是否开启远程开关门功能
|
|
26
|
-
* @param state
|
|
27
|
-
*/
|
|
28
9
|
export declare const remoteEnabled: (state: boolean) => Promise<void>;
|
|
29
|
-
/**
|
|
30
|
-
* 获取远程开关门是否开启
|
|
31
|
-
* @returns boolean
|
|
32
|
-
*/
|
|
33
10
|
export declare const getRemoteEnabled: () => boolean;
|
|
34
|
-
/**
|
|
35
|
-
* 获取远程开关门权限列表
|
|
36
|
-
* @returns
|
|
37
|
-
*/
|
|
38
11
|
export declare const getRemotePermissionList: () => RemotePermission[];
|
|
39
|
-
/**
|
|
40
|
-
* 获取远程开关门当前权限
|
|
41
|
-
* @returns 远程开关门权限
|
|
42
|
-
*/
|
|
43
12
|
export declare const getRemotePermission: () => RemotePermission;
|
|
44
|
-
/**
|
|
45
|
-
* 更新远程开关门权限
|
|
46
|
-
* @param permission
|
|
47
|
-
*/
|
|
48
13
|
export declare const updateRemotePermission: (permission: RemotePermission) => Promise<void>;
|
package/lib/open.js
CHANGED
|
@@ -1,13 +1,10 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* 远程开关锁 API
|
|
3
|
-
*/
|
|
4
1
|
import dpUtils from "@ray-js/tuya-dp-transform";
|
|
5
2
|
import { getDoorKey, openDoorByCloud } from "./api/lock";
|
|
6
3
|
import config from "./config";
|
|
7
4
|
import { isUseNearChannel, parallelMerge, parallelOnly } from "./utils";
|
|
8
5
|
import { decrypt } from "./utils/device";
|
|
9
6
|
import { publishDps } from "./utils/publishDps";
|
|
10
|
-
import { open as openMap, reportOpen as reportOpenMap } from "./config/dp-map/open";
|
|
7
|
+
import { open as openMap, reportOpen as reportOpenMap, } from "./config/dp-map/open";
|
|
11
8
|
import { stringToBytes } from "./utils/byte";
|
|
12
9
|
import emitter from "./utils/event";
|
|
13
10
|
import { getError } from "./utils/errors";
|
|
@@ -17,241 +14,149 @@ import { getCurrentUser, permissions } from "./state";
|
|
|
17
14
|
import { setDeviceProperties } from "./api/setting";
|
|
18
15
|
import syncRemoteSerectKey from "./sync/remote-serect-key";
|
|
19
16
|
import { ProductCommunicationType } from "./constant";
|
|
20
|
-
const getReportError = status => {
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
return error;
|
|
17
|
+
const getReportError = (status) => {
|
|
18
|
+
let error = getError(1004);
|
|
19
|
+
switch (status) {
|
|
20
|
+
case 0x02:
|
|
21
|
+
error = getError(1005);
|
|
22
|
+
break;
|
|
23
|
+
case 0x03:
|
|
24
|
+
error = getError(1006);
|
|
25
|
+
break;
|
|
26
|
+
case 0x04:
|
|
27
|
+
error = getError(1007);
|
|
28
|
+
break;
|
|
29
|
+
case 0x05:
|
|
30
|
+
error = getError(1008);
|
|
31
|
+
break;
|
|
32
|
+
default:
|
|
33
|
+
}
|
|
34
|
+
return error;
|
|
39
35
|
};
|
|
40
|
-
|
|
41
|
-
/**
|
|
42
|
-
* 校验是否可以远程开关门
|
|
43
|
-
*/
|
|
44
36
|
export const checkRemoteEnabled = parallelMerge(async () => {
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
userType
|
|
53
|
-
} = await getCurrentUser();
|
|
54
|
-
if (!devInfo.isOnline) {
|
|
55
|
-
// 设备不在线
|
|
56
|
-
throw getError(1001);
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
// 是否支持远程开门
|
|
60
|
-
if (dpSchema[dpCodes.remoteNoDpKey] === undefined) {
|
|
61
|
-
// 不支持远程开门
|
|
62
|
-
throw getError(1045);
|
|
63
|
-
}
|
|
64
|
-
// 是否开启远程开关门
|
|
65
|
-
if (!remoteOpenEnabled) {
|
|
66
|
-
// 远程开关门未开启
|
|
67
|
-
throw getError(1046);
|
|
68
|
-
}
|
|
69
|
-
// 是否有权限开关门
|
|
70
|
-
if (remoteOpenPermission === "noOne" || remoteOpenPermission === "adminsOnly" && +userType === 20) {
|
|
71
|
-
throw getError(1047);
|
|
72
|
-
}
|
|
73
|
-
});
|
|
74
|
-
const _doAction = async (isOpen, timeout) => {
|
|
75
|
-
const {
|
|
76
|
-
devInfo,
|
|
77
|
-
onlineType,
|
|
78
|
-
capabilities,
|
|
79
|
-
communication,
|
|
80
|
-
dpSchema
|
|
81
|
-
} = config;
|
|
82
|
-
|
|
83
|
-
// 校验远程开关门是否可用
|
|
84
|
-
await checkRemoteEnabled();
|
|
85
|
-
const isNear = isUseNearChannel();
|
|
86
|
-
const currentUser = await getCurrentUser();
|
|
87
|
-
const memberId = currentUser.lockUserId !== 0 ? currentUser.lockUserId : currentUser.userId;
|
|
88
|
-
const checkReport = dpData => {
|
|
89
|
-
if (typeof dpData[dpCodes.remoteNoDpKey] !== "undefined") {
|
|
90
|
-
const result = dpUtils.parse(dpData[dpCodes.remoteNoDpKey], reportOpenMap);
|
|
91
|
-
// 由于有两端操作的可能,所以需要判断是否有相同的成员id
|
|
92
|
-
if (result.memberId === memberId) {
|
|
93
|
-
// 有相同的成员开锁,表示此操作有结果
|
|
94
|
-
return result;
|
|
95
|
-
} else {
|
|
96
|
-
// 提示可能返回了一个错误的成员id
|
|
97
|
-
console.warn("An incorrect member id was returned");
|
|
98
|
-
}
|
|
37
|
+
const { devInfo, dpSchema, remoteOpenEnabled, remoteOpenPermission } = config;
|
|
38
|
+
const { userType } = await getCurrentUser();
|
|
39
|
+
if (!devInfo.isOnline) {
|
|
40
|
+
throw getError(1001);
|
|
41
|
+
}
|
|
42
|
+
if (dpSchema[dpCodes.remoteNoDpKey] === undefined) {
|
|
43
|
+
throw getError(1045);
|
|
99
44
|
}
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
// 是否为蓝牙在线
|
|
104
|
-
if (isNear) {
|
|
105
|
-
// 为双模支持蓝牙控制且蓝牙在线
|
|
106
|
-
if (communication.includes(ProductCommunicationType.WIFI) || communication.includes(ProductCommunicationType.THREAD)) {
|
|
107
|
-
// 先尝试同步密钥
|
|
108
|
-
await syncRemoteSerectKey();
|
|
109
|
-
|
|
110
|
-
// 蓝牙在线时,通过蓝牙开锁
|
|
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
|
-
}
|
|
125
|
-
const response = await publishDps({
|
|
126
|
-
[dpCodes.remoteNoDpKey]: dpUtils.format({
|
|
127
|
-
status: Number(isOpen),
|
|
128
|
-
memberId,
|
|
129
|
-
key: stringToBytes(pw),
|
|
130
|
-
type: 3 // 0x03 表示蓝牙方式开锁
|
|
131
|
-
}, openMap)
|
|
132
|
-
}, {
|
|
133
|
-
timeout,
|
|
134
|
-
checkReport
|
|
135
|
-
});
|
|
136
|
-
|
|
137
|
-
// 状态码为 0 表示开锁成功,其他 0x01:失败 0x02:失效 0x03:秘钥次数使用完 0x04:秘钥不在有效期内 0x05:秘钥比对错误
|
|
138
|
-
if (response.status !== 0) {
|
|
139
|
-
throw getReportError(response.status);
|
|
140
|
-
}
|
|
141
|
-
|
|
142
|
-
// 开锁成功
|
|
143
|
-
return;
|
|
45
|
+
if (!remoteOpenEnabled) {
|
|
46
|
+
throw getError(1046);
|
|
144
47
|
}
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
// TODO 后继实际蓝牙门锁开锁
|
|
149
|
-
throw new Error("Bluetooth lock opening is not supported yet");
|
|
48
|
+
if (remoteOpenPermission === "noOne" ||
|
|
49
|
+
(remoteOpenPermission === "adminsOnly" && +userType === 20)) {
|
|
50
|
+
throw getError(1047);
|
|
150
51
|
}
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
const
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
52
|
+
});
|
|
53
|
+
const _doAction = async (isOpen, timeout) => {
|
|
54
|
+
const { devInfo, onlineType, capabilities, communication, dpSchema } = config;
|
|
55
|
+
await checkRemoteEnabled();
|
|
56
|
+
const isNear = isUseNearChannel();
|
|
57
|
+
const currentUser = await getCurrentUser();
|
|
58
|
+
const memberId = currentUser.lockUserId !== 0 ? currentUser.lockUserId : currentUser.userId;
|
|
59
|
+
const checkReport = (dpData) => {
|
|
60
|
+
if (typeof dpData[dpCodes.remoteNoDpKey] !== "undefined") {
|
|
61
|
+
const result = dpUtils.parse(dpData[dpCodes.remoteNoDpKey], reportOpenMap);
|
|
62
|
+
if (result.memberId === memberId) {
|
|
63
|
+
return result;
|
|
64
|
+
}
|
|
65
|
+
else {
|
|
66
|
+
console.warn("An incorrect member id was returned");
|
|
67
|
+
}
|
|
167
68
|
}
|
|
168
|
-
|
|
69
|
+
return false;
|
|
169
70
|
};
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
71
|
+
if (isNear) {
|
|
72
|
+
if (communication.includes(ProductCommunicationType.WIFI) ||
|
|
73
|
+
communication.includes(ProductCommunicationType.THREAD)) {
|
|
74
|
+
await syncRemoteSerectKey();
|
|
75
|
+
let pw = "";
|
|
76
|
+
try {
|
|
77
|
+
const { password } = await getDoorKey(devInfo.devId);
|
|
78
|
+
pw = await decrypt(devInfo.devId, password);
|
|
79
|
+
}
|
|
80
|
+
catch (e) {
|
|
81
|
+
await syncRemoteSerectKey(true);
|
|
82
|
+
const { password } = await getDoorKey(devInfo.devId);
|
|
83
|
+
pw = await decrypt(devInfo.devId, password);
|
|
84
|
+
}
|
|
85
|
+
const response = await publishDps({
|
|
86
|
+
[dpCodes.remoteNoDpKey]: dpUtils.format({
|
|
87
|
+
status: Number(isOpen),
|
|
88
|
+
memberId,
|
|
89
|
+
key: stringToBytes(pw),
|
|
90
|
+
type: 3,
|
|
91
|
+
}, openMap),
|
|
92
|
+
}, {
|
|
93
|
+
timeout,
|
|
94
|
+
checkReport,
|
|
95
|
+
});
|
|
96
|
+
if (response.status !== 0) {
|
|
97
|
+
throw getReportError(response.status);
|
|
98
|
+
}
|
|
99
|
+
return;
|
|
100
|
+
}
|
|
101
|
+
if (communication.length === 1 &&
|
|
102
|
+
communication.includes(ProductCommunicationType.BLUETOOTH)) {
|
|
103
|
+
throw new Error("Bluetooth lock opening is not supported yet");
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
return new Promise((resolve, reject) => {
|
|
107
|
+
const handleReport = (dpCodes) => {
|
|
108
|
+
const result = checkReport(dpCodes);
|
|
109
|
+
if (result) {
|
|
110
|
+
emitter.off(DPCHANGE, handleReport);
|
|
111
|
+
clearTimeout(timeoutTask);
|
|
112
|
+
if (result.status !== 0) {
|
|
113
|
+
reject(getReportError(result.status));
|
|
114
|
+
}
|
|
115
|
+
else {
|
|
116
|
+
resolve();
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
};
|
|
120
|
+
const timeoutTask = setTimeout(() => {
|
|
121
|
+
emitter.off(DPCHANGE, handleReport);
|
|
122
|
+
reject(getError(1002));
|
|
123
|
+
}, timeout);
|
|
124
|
+
emitter.on(DPCHANGE, handleReport);
|
|
125
|
+
openDoorByCloud(devInfo.devId, isOpen).catch((e) => {
|
|
126
|
+
clearTimeout(timeoutTask);
|
|
127
|
+
emitter.off(DPCHANGE, handleReport);
|
|
128
|
+
reject(getError(1003));
|
|
129
|
+
});
|
|
184
130
|
});
|
|
185
|
-
});
|
|
186
131
|
};
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
* 开锁
|
|
190
|
-
* @param option 开锁选项
|
|
191
|
-
* @param option.timeout 超时时间,默认 15000 毫秒
|
|
192
|
-
* @returns Promise<void>
|
|
193
|
-
*/
|
|
194
|
-
export const openDoor = parallelOnly(option => {
|
|
195
|
-
return _doAction(true, (option === null || option === void 0 ? void 0 : option.timeout) || 15000);
|
|
132
|
+
export const openDoor = parallelOnly((option) => {
|
|
133
|
+
return _doAction(true, option?.timeout || 15000);
|
|
196
134
|
});
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
* 关锁
|
|
200
|
-
* @param option 关锁选项
|
|
201
|
-
* @param option.timeout 超时时间,默认 15000 毫秒
|
|
202
|
-
* @returns Promise<void>
|
|
203
|
-
*/
|
|
204
|
-
export const closeDoor = parallelOnly(option => {
|
|
205
|
-
return _doAction(false, (option === null || option === void 0 ? void 0 : option.timeout) || 15000);
|
|
135
|
+
export const closeDoor = parallelOnly((option) => {
|
|
136
|
+
return _doAction(false, option?.timeout || 15000);
|
|
206
137
|
});
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
});
|
|
216
|
-
config.remoteOpenEnabled = state;
|
|
217
|
-
if (state) {
|
|
218
|
-
// 同步密钥
|
|
219
|
-
syncRemoteSerectKey();
|
|
220
|
-
}
|
|
138
|
+
export const remoteEnabled = parallelMerge(async (state) => {
|
|
139
|
+
await setDeviceProperties(config.devInfo.devId, {
|
|
140
|
+
UNLOCK_PHONE_REMOTE: state,
|
|
141
|
+
});
|
|
142
|
+
config.remoteOpenEnabled = state;
|
|
143
|
+
if (state) {
|
|
144
|
+
syncRemoteSerectKey();
|
|
145
|
+
}
|
|
221
146
|
});
|
|
222
|
-
|
|
223
|
-
/**
|
|
224
|
-
* 获取远程开关门是否开启
|
|
225
|
-
* @returns boolean
|
|
226
|
-
*/
|
|
227
147
|
export const getRemoteEnabled = () => {
|
|
228
|
-
|
|
148
|
+
return config.remoteOpenEnabled;
|
|
229
149
|
};
|
|
230
|
-
|
|
231
|
-
/**
|
|
232
|
-
* 获取远程开关门权限列表
|
|
233
|
-
* @returns
|
|
234
|
-
*/
|
|
235
150
|
export const getRemotePermissionList = () => {
|
|
236
|
-
|
|
151
|
+
return permissions;
|
|
237
152
|
};
|
|
238
|
-
|
|
239
|
-
/**
|
|
240
|
-
* 获取远程开关门当前权限
|
|
241
|
-
* @returns 远程开关门权限
|
|
242
|
-
*/
|
|
243
153
|
export const getRemotePermission = () => {
|
|
244
|
-
|
|
154
|
+
return config.remoteOpenPermission;
|
|
155
|
+
};
|
|
156
|
+
export const updateRemotePermission = async (permission) => {
|
|
157
|
+
const index = permissions.indexOf(permission);
|
|
158
|
+
await setDeviceProperties(config.devInfo.devId, {
|
|
159
|
+
REMOTE_UNLOCK_AUTH: index > 0 ? index : 0,
|
|
160
|
+
});
|
|
161
|
+
config.remoteOpenPermission = permission;
|
|
245
162
|
};
|
|
246
|
-
|
|
247
|
-
/**
|
|
248
|
-
* 更新远程开关门权限
|
|
249
|
-
* @param permission
|
|
250
|
-
*/
|
|
251
|
-
export const updateRemotePermission = async permission => {
|
|
252
|
-
const index = permissions.indexOf(permission);
|
|
253
|
-
await setDeviceProperties(config.devInfo.devId, {
|
|
254
|
-
REMOTE_UNLOCK_AUTH: index > 0 ? index : 0
|
|
255
|
-
});
|
|
256
|
-
config.remoteOpenPermission = permission;
|
|
257
|
-
};
|
package/lib/other.d.ts
CHANGED
|
@@ -1,35 +1,11 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* 打开场景
|
|
3
|
-
* @param options - 打开场景的参数
|
|
4
|
-
* @param options.themeColor - 主题颜色
|
|
5
|
-
*/
|
|
6
1
|
export declare const openScene: (options?: {
|
|
7
2
|
themeColor?: string;
|
|
8
3
|
}) => Promise<unknown>;
|
|
9
|
-
/**
|
|
10
|
-
* 判断是否支持蓝牙控制
|
|
11
|
-
* @returns boolean
|
|
12
|
-
*/
|
|
13
4
|
export declare const isSupportBleControl: () => import("./interface").DpValue;
|
|
14
|
-
/**
|
|
15
|
-
* 获取休眠时间段
|
|
16
|
-
* @param dpCode - 待获取时段的 dp
|
|
17
|
-
* @returns 返回时间段
|
|
18
|
-
* start: 开始时间(分钟)
|
|
19
|
-
* end: 结束时间(分钟)
|
|
20
|
-
*/
|
|
21
5
|
export declare const getDpPeriodTime: (dpCode: string) => {
|
|
22
6
|
start: number;
|
|
23
7
|
end: number;
|
|
24
8
|
};
|
|
25
|
-
/**
|
|
26
|
-
* 设置时间段
|
|
27
|
-
* @param dpCode - 待设置时段的 dp
|
|
28
|
-
* @param params 休眠时间段数据
|
|
29
|
-
* start: 开始时间(分钟)
|
|
30
|
-
* end: 结束时间(分钟)
|
|
31
|
-
* @returns Promise<void>
|
|
32
|
-
*/
|
|
33
9
|
export declare const updateDpPeriodTime: (dpCode: string, data: {
|
|
34
10
|
start: number;
|
|
35
11
|
end: number;
|