@ray-js/lock-sdk 1.0.0-beta-1
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.d.ts +5 -0
- package/lib/api/index.js +18 -0
- package/lib/api/linkage.d.ts +161 -0
- package/lib/api/linkage.js +74 -0
- package/lib/api/lock.d.ts +195 -0
- package/lib/api/lock.js +129 -0
- package/lib/api/log.d.ts +166 -0
- package/lib/api/log.js +44 -0
- package/lib/api/setting.d.ts +14 -0
- package/lib/api/setting.js +36 -0
- package/lib/api/temp.d.ts +211 -0
- package/lib/api/temp.js +130 -0
- package/lib/api/user.d.ts +154 -0
- package/lib/api/user.js +59 -0
- package/lib/api/video.d.ts +9 -0
- package/lib/api/video.js +17 -0
- package/lib/config/dp-code/index.d.ts +175 -0
- package/lib/config/dp-code/index.js +224 -0
- package/lib/config/dp-map/common.d.ts +102 -0
- package/lib/config/dp-map/common.js +120 -0
- package/lib/config/dp-map/normal.d.ts +6 -0
- package/lib/config/dp-map/normal.js +51 -0
- package/lib/config/dp-map/open.d.ts +21 -0
- package/lib/config/dp-map/open.js +62 -0
- package/lib/config/dp-map/unlock-method-big.d.ts +559 -0
- package/lib/config/dp-map/unlock-method-big.js +237 -0
- package/lib/config/dp-map/unlock-method.d.ts +551 -0
- package/lib/config/dp-map/unlock-method.js +231 -0
- package/lib/config/index.d.ts +46 -0
- package/lib/config/index.js +56 -0
- package/lib/constant.d.ts +101 -0
- package/lib/constant.js +136 -0
- package/lib/dp-interface.d.ts +7 -0
- package/lib/dp-interface.js +1 -0
- package/lib/event.d.ts +8 -0
- package/lib/event.js +9 -0
- package/lib/index.d.ts +25 -0
- package/lib/index.js +92 -0
- package/lib/interface.d.ts +807 -0
- package/lib/interface.js +1 -0
- package/lib/linkage.d.ts +26 -0
- package/lib/linkage.js +175 -0
- package/lib/log.d.ts +91 -0
- package/lib/log.js +314 -0
- package/lib/media.d.ts +43 -0
- package/lib/media.js +80 -0
- package/lib/open.d.ts +48 -0
- package/lib/open.js +247 -0
- package/lib/other.d.ts +36 -0
- package/lib/other.js +178 -0
- package/lib/parse/index.d.ts +6 -0
- package/lib/parse/index.js +22 -0
- package/lib/signal.d.ts +26 -0
- package/lib/signal.js +38 -0
- package/lib/sleep.d.ts +61 -0
- package/lib/sleep.js +121 -0
- package/lib/state.d.ts +54 -0
- package/lib/state.js +429 -0
- package/lib/sync/remote-serect-key.d.ts +5 -0
- package/lib/sync/remote-serect-key.js +60 -0
- package/lib/sync/t0.d.ts +5 -0
- package/lib/sync/t0.js +33 -0
- package/lib/sync/temp.d.ts +7 -0
- package/lib/sync/temp.js +88 -0
- package/lib/sync/unlock-mothod.d.ts +5 -0
- package/lib/sync/unlock-mothod.js +54 -0
- package/lib/temporary.d.ts +226 -0
- package/lib/temporary.js +637 -0
- package/lib/unlock-method.d.ts +269 -0
- package/lib/unlock-method.js +723 -0
- package/lib/user.d.ts +108 -0
- package/lib/user.js +361 -0
- package/lib/utils/base64-to-hex.d.ts +1 -0
- package/lib/utils/base64-to-hex.js +12 -0
- package/lib/utils/byte.d.ts +19 -0
- package/lib/utils/byte.js +74 -0
- package/lib/utils/constant.d.ts +11 -0
- package/lib/utils/constant.js +17 -0
- package/lib/utils/device.d.ts +207 -0
- package/lib/utils/device.js +353 -0
- package/lib/utils/errors.d.ts +2 -0
- package/lib/utils/errors.js +125 -0
- package/lib/utils/event.d.ts +23 -0
- package/lib/utils/event.js +144 -0
- package/lib/utils/hex-to-base64.d.ts +1 -0
- package/lib/utils/hex-to-base64.js +8 -0
- package/lib/utils/hex-to-bytes.d.ts +6 -0
- package/lib/utils/hex-to-bytes.js +16 -0
- package/lib/utils/index.d.ts +169 -0
- package/lib/utils/index.js +419 -0
- package/lib/utils/log.d.ts +5 -0
- package/lib/utils/log.js +78 -0
- package/lib/utils/publishDps.d.ts +11 -0
- package/lib/utils/publishDps.js +91 -0
- package/package.json +37 -0
package/lib/media.js
ADDED
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
import { getMediaUrl as getMediaUrlApi } from "./api/log";
|
|
2
|
+
import config from "./config";
|
|
3
|
+
import dpCodes from "./config/dp-code";
|
|
4
|
+
import { openNativeRouter } from "./utils/device";
|
|
5
|
+
import { publishDps } from "./utils/publishDps";
|
|
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
|
+
});
|
|
26
|
+
};
|
|
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
ADDED
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import { RemotePermission } from "./interface";
|
|
2
|
+
/**
|
|
3
|
+
* 校验是否可以远程开关门
|
|
4
|
+
*/
|
|
5
|
+
export declare const checkRemoteEnabled: () => Promise<void>;
|
|
6
|
+
/**
|
|
7
|
+
* 开锁
|
|
8
|
+
* @param option 开锁选项
|
|
9
|
+
* @param option.timeout 超时时间,默认 15000 毫秒
|
|
10
|
+
* @returns Promise<void>
|
|
11
|
+
*/
|
|
12
|
+
export declare const openDoor: (option?: {
|
|
13
|
+
timeout?: number;
|
|
14
|
+
} | undefined) => Promise<void>;
|
|
15
|
+
/**
|
|
16
|
+
* 关锁
|
|
17
|
+
* @param option 关锁选项
|
|
18
|
+
* @param option.timeout 超时时间,默认 15000 毫秒
|
|
19
|
+
* @returns Promise<void>
|
|
20
|
+
*/
|
|
21
|
+
export declare const closeDoor: (option?: {
|
|
22
|
+
timeout?: number;
|
|
23
|
+
} | undefined) => Promise<void>;
|
|
24
|
+
/**
|
|
25
|
+
* 是否开启远程开关门功能
|
|
26
|
+
* @param state
|
|
27
|
+
*/
|
|
28
|
+
export declare const remoteEnabled: (state: boolean) => Promise<void>;
|
|
29
|
+
/**
|
|
30
|
+
* 获取远程开关门是否开启
|
|
31
|
+
* @returns boolean
|
|
32
|
+
*/
|
|
33
|
+
export declare const getRemoteEnabled: () => boolean;
|
|
34
|
+
/**
|
|
35
|
+
* 获取远程开关门权限列表
|
|
36
|
+
* @returns
|
|
37
|
+
*/
|
|
38
|
+
export declare const getRemotePermissionList: () => RemotePermission[];
|
|
39
|
+
/**
|
|
40
|
+
* 获取远程开关门当前权限
|
|
41
|
+
* @returns 远程开关门权限
|
|
42
|
+
*/
|
|
43
|
+
export declare const getRemotePermission: () => RemotePermission;
|
|
44
|
+
/**
|
|
45
|
+
* 更新远程开关门权限
|
|
46
|
+
* @param permission
|
|
47
|
+
*/
|
|
48
|
+
export declare const updateRemotePermission: (permission: RemotePermission) => Promise<void>;
|
package/lib/open.js
ADDED
|
@@ -0,0 +1,247 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 远程开关锁 API
|
|
3
|
+
*/
|
|
4
|
+
import dpUtils from "@ray-js/tuya-dp-transform";
|
|
5
|
+
import { getDoorKey, openDoorByCloud } from "./api/lock";
|
|
6
|
+
import config from "./config";
|
|
7
|
+
import { isUseNearChannel, parallelMerge, parallelOnly } from "./utils";
|
|
8
|
+
import { decrypt } from "./utils/device";
|
|
9
|
+
import { publishDps } from "./utils/publishDps";
|
|
10
|
+
import { open as openMap, reportOpen as reportOpenMap } from "./config/dp-map/open";
|
|
11
|
+
import { stringToBytes } from "./utils/byte";
|
|
12
|
+
import emitter from "./utils/event";
|
|
13
|
+
import { getError } from "./utils/errors";
|
|
14
|
+
import { DPCHANGE } from "./utils/constant";
|
|
15
|
+
import dpCodes from "./config/dp-code";
|
|
16
|
+
import { getCurrentUser, permissions } from "./state";
|
|
17
|
+
import { setDeviceProperties } from "./api/setting";
|
|
18
|
+
import syncRemoteSerectKey from "./sync/remote-serect-key";
|
|
19
|
+
import { ProductCommunicationType } from "./constant";
|
|
20
|
+
const getReportError = status => {
|
|
21
|
+
// 状态码为 0 表示开锁成功,其他 0x01:失败 0x02:失效 0x03:秘钥次数使用完 0x04:秘钥不在有效期内 0x05:秘钥比对错误
|
|
22
|
+
let error = getError(1004);
|
|
23
|
+
switch (status) {
|
|
24
|
+
case 0x02:
|
|
25
|
+
error = getError(1005);
|
|
26
|
+
break;
|
|
27
|
+
case 0x03:
|
|
28
|
+
error = getError(1006);
|
|
29
|
+
break;
|
|
30
|
+
case 0x04:
|
|
31
|
+
error = getError(1007);
|
|
32
|
+
break;
|
|
33
|
+
case 0x05:
|
|
34
|
+
error = getError(1008);
|
|
35
|
+
break;
|
|
36
|
+
default:
|
|
37
|
+
}
|
|
38
|
+
return error;
|
|
39
|
+
};
|
|
40
|
+
|
|
41
|
+
/**
|
|
42
|
+
* 校验是否可以远程开关门
|
|
43
|
+
*/
|
|
44
|
+
export const checkRemoteEnabled = parallelMerge(async () => {
|
|
45
|
+
const {
|
|
46
|
+
devInfo,
|
|
47
|
+
dpSchema,
|
|
48
|
+
remoteOpenEnabled,
|
|
49
|
+
remoteOpenPermission
|
|
50
|
+
} = config;
|
|
51
|
+
const {
|
|
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
|
+
}
|
|
99
|
+
}
|
|
100
|
+
return false;
|
|
101
|
+
};
|
|
102
|
+
|
|
103
|
+
// 是否为蓝牙在线
|
|
104
|
+
if (isNear) {
|
|
105
|
+
// 为双模支持蓝牙控制且蓝牙在线
|
|
106
|
+
if (communication.includes(ProductCommunicationType.WIFI) || communication.includes(ProductCommunicationType.THREAD)) {
|
|
107
|
+
// 先尝试同步密钥
|
|
108
|
+
await syncRemoteSerectKey();
|
|
109
|
+
|
|
110
|
+
// 蓝牙在线时,通过蓝牙开锁
|
|
111
|
+
const {
|
|
112
|
+
password
|
|
113
|
+
} = await getDoorKey(devInfo.devId);
|
|
114
|
+
const pw = await decrypt(devInfo.devId, password);
|
|
115
|
+
const response = await publishDps({
|
|
116
|
+
[dpCodes.remoteNoDpKey]: dpUtils.format({
|
|
117
|
+
status: Number(isOpen),
|
|
118
|
+
memberId,
|
|
119
|
+
key: stringToBytes(pw),
|
|
120
|
+
type: 3 // 0x03 表示蓝牙方式开锁
|
|
121
|
+
}, openMap)
|
|
122
|
+
}, {
|
|
123
|
+
timeout,
|
|
124
|
+
checkReport
|
|
125
|
+
});
|
|
126
|
+
const result = response[dpCodes.remoteNoDpKey];
|
|
127
|
+
// 状态码为 0 表示开锁成功,其他 0x01:失败 0x02:失效 0x03:秘钥次数使用完 0x04:秘钥不在有效期内 0x05:秘钥比对错误
|
|
128
|
+
if (result.status !== 0) {
|
|
129
|
+
throw getReportError(result.status);
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
// 开锁成功
|
|
133
|
+
return;
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
// 纯蓝牙设备
|
|
137
|
+
if (communication.length === 1 && communication.includes(ProductCommunicationType.BLUETOOTH)) {
|
|
138
|
+
// TODO 后继实际蓝牙门锁开锁
|
|
139
|
+
throw new Error("Bluetooth lock opening is not supported yet");
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
// 其他情况默认为云端开锁
|
|
144
|
+
return new Promise((resolve, reject) => {
|
|
145
|
+
// 走云端远程开锁逻辑
|
|
146
|
+
const handleReport = dpCodes => {
|
|
147
|
+
const result = checkReport(dpCodes);
|
|
148
|
+
if (result) {
|
|
149
|
+
emitter.off(DPCHANGE, handleReport);
|
|
150
|
+
clearTimeout(timeoutTask);
|
|
151
|
+
if (result.status !== 0) {
|
|
152
|
+
// 失败
|
|
153
|
+
reject(getReportError(result.status));
|
|
154
|
+
} else {
|
|
155
|
+
// 开锁成功
|
|
156
|
+
resolve();
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
};
|
|
160
|
+
// 监听开锁结果
|
|
161
|
+
// 设置超时任务
|
|
162
|
+
const timeoutTask = setTimeout(() => {
|
|
163
|
+
emitter.off(DPCHANGE, handleReport);
|
|
164
|
+
// 超时处理
|
|
165
|
+
reject(getError(1002));
|
|
166
|
+
}, timeout);
|
|
167
|
+
// 加入监听器
|
|
168
|
+
emitter.on(DPCHANGE, handleReport);
|
|
169
|
+
openDoorByCloud(devInfo.devId, isOpen).catch(() => {
|
|
170
|
+
clearTimeout(timeoutTask);
|
|
171
|
+
emitter.off(DPCHANGE, handleReport);
|
|
172
|
+
// 开锁失败
|
|
173
|
+
reject(getError(1003));
|
|
174
|
+
});
|
|
175
|
+
});
|
|
176
|
+
};
|
|
177
|
+
|
|
178
|
+
/**
|
|
179
|
+
* 开锁
|
|
180
|
+
* @param option 开锁选项
|
|
181
|
+
* @param option.timeout 超时时间,默认 15000 毫秒
|
|
182
|
+
* @returns Promise<void>
|
|
183
|
+
*/
|
|
184
|
+
export const openDoor = parallelOnly(option => {
|
|
185
|
+
return _doAction(true, (option === null || option === void 0 ? void 0 : option.timeout) || 15000);
|
|
186
|
+
});
|
|
187
|
+
|
|
188
|
+
/**
|
|
189
|
+
* 关锁
|
|
190
|
+
* @param option 关锁选项
|
|
191
|
+
* @param option.timeout 超时时间,默认 15000 毫秒
|
|
192
|
+
* @returns Promise<void>
|
|
193
|
+
*/
|
|
194
|
+
export const closeDoor = parallelOnly(option => {
|
|
195
|
+
return _doAction(false, (option === null || option === void 0 ? void 0 : option.timeout) || 15000);
|
|
196
|
+
});
|
|
197
|
+
|
|
198
|
+
/**
|
|
199
|
+
* 是否开启远程开关门功能
|
|
200
|
+
* @param state
|
|
201
|
+
*/
|
|
202
|
+
export const remoteEnabled = parallelMerge(async state => {
|
|
203
|
+
await setDeviceProperties(config.devInfo.devId, {
|
|
204
|
+
UNLOCK_PHONE_REMOTE: state
|
|
205
|
+
});
|
|
206
|
+
config.remoteOpenEnabled = state;
|
|
207
|
+
if (state) {
|
|
208
|
+
// 同步密钥
|
|
209
|
+
syncRemoteSerectKey();
|
|
210
|
+
}
|
|
211
|
+
});
|
|
212
|
+
|
|
213
|
+
/**
|
|
214
|
+
* 获取远程开关门是否开启
|
|
215
|
+
* @returns boolean
|
|
216
|
+
*/
|
|
217
|
+
export const getRemoteEnabled = () => {
|
|
218
|
+
return config.remoteOpenEnabled;
|
|
219
|
+
};
|
|
220
|
+
|
|
221
|
+
/**
|
|
222
|
+
* 获取远程开关门权限列表
|
|
223
|
+
* @returns
|
|
224
|
+
*/
|
|
225
|
+
export const getRemotePermissionList = () => {
|
|
226
|
+
return permissions;
|
|
227
|
+
};
|
|
228
|
+
|
|
229
|
+
/**
|
|
230
|
+
* 获取远程开关门当前权限
|
|
231
|
+
* @returns 远程开关门权限
|
|
232
|
+
*/
|
|
233
|
+
export const getRemotePermission = () => {
|
|
234
|
+
return config.remoteOpenPermission;
|
|
235
|
+
};
|
|
236
|
+
|
|
237
|
+
/**
|
|
238
|
+
* 更新远程开关门权限
|
|
239
|
+
* @param permission
|
|
240
|
+
*/
|
|
241
|
+
export const updateRemotePermission = async permission => {
|
|
242
|
+
const index = permissions.indexOf(permission);
|
|
243
|
+
await setDeviceProperties(config.devInfo.devId, {
|
|
244
|
+
REMOTE_UNLOCK_AUTH: index > 0 ? index : 0
|
|
245
|
+
});
|
|
246
|
+
config.remoteOpenPermission = permission;
|
|
247
|
+
};
|
package/lib/other.d.ts
ADDED
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 打开场景
|
|
3
|
+
* @param options - 打开场景的参数
|
|
4
|
+
* @param options.themeColor - 主题颜色
|
|
5
|
+
*/
|
|
6
|
+
export declare const openScene: (options?: {
|
|
7
|
+
themeColor?: string;
|
|
8
|
+
}) => Promise<unknown>;
|
|
9
|
+
/**
|
|
10
|
+
* 判断是否支持蓝牙控制
|
|
11
|
+
* @returns boolean
|
|
12
|
+
*/
|
|
13
|
+
export declare const isSupportBleControl: () => import("./interface").DpValue;
|
|
14
|
+
/**
|
|
15
|
+
* 获取休眠时间段
|
|
16
|
+
* @param dpCode - 待获取时段的 dp
|
|
17
|
+
* @returns 返回时间段
|
|
18
|
+
* start: 开始时间(分钟)
|
|
19
|
+
* end: 结束时间(分钟)
|
|
20
|
+
*/
|
|
21
|
+
export declare const getDpPeriodTime: (dpCode: string) => {
|
|
22
|
+
start: number;
|
|
23
|
+
end: number;
|
|
24
|
+
};
|
|
25
|
+
/**
|
|
26
|
+
* 设置时间段
|
|
27
|
+
* @param dpCode - 待设置时段的 dp
|
|
28
|
+
* @param params 休眠时间段数据
|
|
29
|
+
* start: 开始时间(分钟)
|
|
30
|
+
* end: 结束时间(分钟)
|
|
31
|
+
* @returns Promise<void>
|
|
32
|
+
*/
|
|
33
|
+
export declare const updateDpPeriodTime: (dpCode: string, data: {
|
|
34
|
+
start: number;
|
|
35
|
+
end: number;
|
|
36
|
+
}) => Promise<Record<string, import("./interface").DpValue>>;
|
package/lib/other.js
ADDED
|
@@ -0,0 +1,178 @@
|
|
|
1
|
+
import _objectSpread from "@babel/runtime/helpers/esm/objectSpread2";
|
|
2
|
+
import _objectWithoutProperties from "@babel/runtime/helpers/esm/objectWithoutProperties";
|
|
3
|
+
const _excluded = ["themeColor"];
|
|
4
|
+
import dpUtils from "@ray-js/tuya-dp-transform";
|
|
5
|
+
import config from "./config";
|
|
6
|
+
import dpCodes from "./config/dp-code";
|
|
7
|
+
import { ProductCommunicationType } from "./constant";
|
|
8
|
+
import { getDpValue } from "./state";
|
|
9
|
+
import { openPanel } from "./utils/device";
|
|
10
|
+
import { getError } from "./utils/errors";
|
|
11
|
+
import { publishDps } from "./utils/publishDps";
|
|
12
|
+
const {
|
|
13
|
+
alarmLock,
|
|
14
|
+
unlockFingerprint,
|
|
15
|
+
unlockPassword,
|
|
16
|
+
unlockCard,
|
|
17
|
+
unlockKey,
|
|
18
|
+
unlockPhoneRemote
|
|
19
|
+
} = dpCodes;
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* 打开场景
|
|
23
|
+
* @param options - 打开场景的参数
|
|
24
|
+
* @param options.themeColor - 主题颜色
|
|
25
|
+
*/
|
|
26
|
+
export const openScene = async options => {
|
|
27
|
+
const dpIds = [unlockFingerprint, unlockPassword, unlockCard, unlockKey, unlockPhoneRemote].reduce((acc, item) => {
|
|
28
|
+
const id = config.idsByCode[item];
|
|
29
|
+
if (id) {
|
|
30
|
+
acc.push(id);
|
|
31
|
+
}
|
|
32
|
+
return acc;
|
|
33
|
+
}, []);
|
|
34
|
+
const _ref = options || {},
|
|
35
|
+
{
|
|
36
|
+
themeColor = ""
|
|
37
|
+
} = _ref,
|
|
38
|
+
res = _objectWithoutProperties(_ref, _excluded);
|
|
39
|
+
return new Promise((resolve, reject) => {
|
|
40
|
+
openPanel({
|
|
41
|
+
deviceId: config.devInfo.devId,
|
|
42
|
+
extraInfo: {
|
|
43
|
+
productId: config.devInfo.productId,
|
|
44
|
+
bizClientId: "tyqawbz9jf6oqvynya",
|
|
45
|
+
productVersion: "1.0.0",
|
|
46
|
+
i18nTime: "12344",
|
|
47
|
+
uiType: "SMART_MINIPG"
|
|
48
|
+
},
|
|
49
|
+
initialProps: _objectSpread({
|
|
50
|
+
openDpLists: dpIds.join(","),
|
|
51
|
+
dpCode: alarmLock,
|
|
52
|
+
themeColor
|
|
53
|
+
}, res),
|
|
54
|
+
success: resolve,
|
|
55
|
+
fail: reject
|
|
56
|
+
});
|
|
57
|
+
});
|
|
58
|
+
};
|
|
59
|
+
|
|
60
|
+
/**
|
|
61
|
+
* 判断是否支持蓝牙控制
|
|
62
|
+
* @returns boolean
|
|
63
|
+
*/
|
|
64
|
+
export const isSupportBleControl = () => {
|
|
65
|
+
const {
|
|
66
|
+
devInfo,
|
|
67
|
+
codesById,
|
|
68
|
+
communication
|
|
69
|
+
} = config;
|
|
70
|
+
if (!codesById[dpCodes.unlockBle]) {
|
|
71
|
+
return false;
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
// 如果是 matter 设备,则判断是否有激活蓝牙
|
|
75
|
+
// 获取是否连云激活
|
|
76
|
+
const hasThread = communication.includes(ProductCommunicationType.THREAD);
|
|
77
|
+
const hasWifi = communication.includes(ProductCommunicationType.WIFI);
|
|
78
|
+
const hasBle = communication.includes(ProductCommunicationType.BLUETOOTH);
|
|
79
|
+
// 通讯能力不支持蓝牙时,不支持蓝牙控制
|
|
80
|
+
if (!hasBle) {
|
|
81
|
+
return false;
|
|
82
|
+
}
|
|
83
|
+
if (hasThread) {
|
|
84
|
+
var _devInfo$meta;
|
|
85
|
+
// 仅支持 Matter + BLE,当元数据里无 threadWithBLE 此标记时,表示蓝牙未激活
|
|
86
|
+
if (!(devInfo !== null && devInfo !== void 0 && (_devInfo$meta = devInfo.meta) !== null && _devInfo$meta !== void 0 && _devInfo$meta["threadWithBLE"])) {
|
|
87
|
+
return false;
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
// 双模设备下,如果未激活 Wifi,则都可以支持蓝牙控制
|
|
91
|
+
if (hasWifi && hasBle) {
|
|
92
|
+
if (devInfo.wifiEnableState === 1) {
|
|
93
|
+
return true;
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
// 存在 dp 42(蓝牙模块开启开关),当 dp42 为 true 时,表示蓝牙模块已开启,则支持蓝牙控制
|
|
98
|
+
const bleControlDp = codesById[dpCodes.bleControl];
|
|
99
|
+
if (bleControlDp) {
|
|
100
|
+
var _devInfo$dpsTime;
|
|
101
|
+
// // 边界判断,是否有上报时间
|
|
102
|
+
const reportTIme = devInfo === null || devInfo === void 0 || (_devInfo$dpsTime = devInfo.dpsTime) === null || _devInfo$dpsTime === void 0 ? void 0 : _devInfo$dpsTime[bleControlDp];
|
|
103
|
+
const hasReportTime = !reportTIme || Math.floor(Number(reportTIme) / 1000) <= devInfo.activeTime;
|
|
104
|
+
if (!getDpValue(dpCodes.bleControl) || !hasReportTime) {
|
|
105
|
+
return true;
|
|
106
|
+
}
|
|
107
|
+
return getDpValue(dpCodes.bleControl);
|
|
108
|
+
}
|
|
109
|
+
return true;
|
|
110
|
+
};
|
|
111
|
+
const periodDpMap = [{
|
|
112
|
+
name: "startHour"
|
|
113
|
+
}, {
|
|
114
|
+
name: "startMinute"
|
|
115
|
+
}, {
|
|
116
|
+
name: "endHour"
|
|
117
|
+
}, {
|
|
118
|
+
name: "endMinute"
|
|
119
|
+
}];
|
|
120
|
+
|
|
121
|
+
/**
|
|
122
|
+
* 获取休眠时间段
|
|
123
|
+
* @param dpCode - 待获取时段的 dp
|
|
124
|
+
* @returns 返回时间段
|
|
125
|
+
* start: 开始时间(分钟)
|
|
126
|
+
* end: 结束时间(分钟)
|
|
127
|
+
*/
|
|
128
|
+
export const getDpPeriodTime = dpCode => {
|
|
129
|
+
const {
|
|
130
|
+
dpSchema
|
|
131
|
+
} = config;
|
|
132
|
+
const dpValue = getDpValue(dpCode);
|
|
133
|
+
if (typeof dpSchema[dpCode] !== "undefined" && dpValue) {
|
|
134
|
+
var _data$startHour, _data$startMinute, _data$endHour, _data$endMinute;
|
|
135
|
+
const data = dpUtils.parse(getDpValue(dpCodes.dormantTimeSet),
|
|
136
|
+
// @ts-expect-error
|
|
137
|
+
periodDpMap);
|
|
138
|
+
return {
|
|
139
|
+
start: ((_data$startHour = data.startHour) !== null && _data$startHour !== void 0 ? _data$startHour : 0) * 60 + ((_data$startMinute = data.startMinute) !== null && _data$startMinute !== void 0 ? _data$startMinute : 0),
|
|
140
|
+
end: ((_data$endHour = data.endHour) !== null && _data$endHour !== void 0 ? _data$endHour : 0) * 60 + ((_data$endMinute = data.endMinute) !== null && _data$endMinute !== void 0 ? _data$endMinute : 0)
|
|
141
|
+
};
|
|
142
|
+
}
|
|
143
|
+
return {
|
|
144
|
+
start: 0,
|
|
145
|
+
end: 0
|
|
146
|
+
};
|
|
147
|
+
};
|
|
148
|
+
|
|
149
|
+
/**
|
|
150
|
+
* 设置时间段
|
|
151
|
+
* @param dpCode - 待设置时段的 dp
|
|
152
|
+
* @param params 休眠时间段数据
|
|
153
|
+
* start: 开始时间(分钟)
|
|
154
|
+
* end: 结束时间(分钟)
|
|
155
|
+
* @returns Promise<void>
|
|
156
|
+
*/
|
|
157
|
+
export const updateDpPeriodTime = (dpCode, data) => {
|
|
158
|
+
const {
|
|
159
|
+
dpSchema
|
|
160
|
+
} = config;
|
|
161
|
+
if (typeof dpSchema[dpCode] === "undefined") {
|
|
162
|
+
throw getError(1014);
|
|
163
|
+
}
|
|
164
|
+
const startHour = Math.floor(data.start / 60);
|
|
165
|
+
const startMinute = data.start % 60;
|
|
166
|
+
const endHour = Math.floor(data.end / 60);
|
|
167
|
+
const endMinute = data.end % 60;
|
|
168
|
+
return publishDps({
|
|
169
|
+
dormant_time_set: dpUtils.format({
|
|
170
|
+
startHour,
|
|
171
|
+
startMinute,
|
|
172
|
+
endHour,
|
|
173
|
+
endMinute
|
|
174
|
+
},
|
|
175
|
+
// @ts-expect-error
|
|
176
|
+
periodDpMap)
|
|
177
|
+
});
|
|
178
|
+
};
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import _objectSpread from "@babel/runtime/helpers/esm/objectSpread2";
|
|
2
|
+
import dpUtils from "@ray-js/tuya-dp-transform";
|
|
3
|
+
import { capabilities as capabilitiesMap } from "../config/dp-map/normal";
|
|
4
|
+
import { ModuleType } from "../constant";
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* 解析设备能力
|
|
8
|
+
* @param dpValue
|
|
9
|
+
*/
|
|
10
|
+
export const parseCapabilities = dpValue => {
|
|
11
|
+
if (!dpValue) {
|
|
12
|
+
return null;
|
|
13
|
+
}
|
|
14
|
+
const data = dpUtils.parse(dpValue, capabilitiesMap);
|
|
15
|
+
if (data.tyep === ModuleType.M7258) {
|
|
16
|
+
// 针对 7258 模组,处理旋转方式,1和0互换
|
|
17
|
+
return _objectSpread(_objectSpread({}, data), {}, {
|
|
18
|
+
rotateType: data.rotateType === 1 ? 0 : data.rotateType === 0 ? 1 : data.rotateType
|
|
19
|
+
});
|
|
20
|
+
}
|
|
21
|
+
return data;
|
|
22
|
+
};
|
package/lib/signal.d.ts
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 获取设备信号强度
|
|
3
|
+
* 此方法只向设备触发动作不返回信号强度,信号强度变化通过 onSignalChange 监听
|
|
4
|
+
* @returns
|
|
5
|
+
*/
|
|
6
|
+
export declare const getWiFiSignal: () => Promise<{
|
|
7
|
+
fetchedData: Record<string, {
|
|
8
|
+
fetchedData: any;
|
|
9
|
+
timeStamp: number;
|
|
10
|
+
}>;
|
|
11
|
+
} | null>;
|
|
12
|
+
type WiFiSignalChangeListener = (params: {
|
|
13
|
+
signal: number;
|
|
14
|
+
level: "good" | "normal" | "weak" | "bad";
|
|
15
|
+
}) => void;
|
|
16
|
+
/**
|
|
17
|
+
* 监听设备信号强度变化
|
|
18
|
+
* @returns
|
|
19
|
+
*/
|
|
20
|
+
export declare const onWiFiSignalChange: (cb: WiFiSignalChangeListener) => void;
|
|
21
|
+
/**
|
|
22
|
+
* 监听设备信号强度变化
|
|
23
|
+
* @returns
|
|
24
|
+
*/
|
|
25
|
+
export declare const offWiFiSignalChange: (cb: WiFiSignalChangeListener) => void;
|
|
26
|
+
export {};
|
package/lib/signal.js
ADDED
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import config from "./config";
|
|
2
|
+
import { sendMqttMessage } from "./utils/device";
|
|
3
|
+
import { getError } from "./utils/errors";
|
|
4
|
+
import emitter from "./utils/event";
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* 获取设备信号强度
|
|
8
|
+
* 此方法只向设备触发动作不返回信号强度,信号强度变化通过 onSignalChange 监听
|
|
9
|
+
* @returns
|
|
10
|
+
*/
|
|
11
|
+
export const getWiFiSignal = () => {
|
|
12
|
+
if (config.devInfo.isCloudOnline) {
|
|
13
|
+
return sendMqttMessage({
|
|
14
|
+
deviceId: config.devInfo.devId,
|
|
15
|
+
protocol: 22,
|
|
16
|
+
message: {
|
|
17
|
+
reqType: "sigQry"
|
|
18
|
+
}
|
|
19
|
+
});
|
|
20
|
+
} else {
|
|
21
|
+
throw getError(1001);
|
|
22
|
+
}
|
|
23
|
+
};
|
|
24
|
+
/**
|
|
25
|
+
* 监听设备信号强度变化
|
|
26
|
+
* @returns
|
|
27
|
+
*/
|
|
28
|
+
export const onWiFiSignalChange = cb => {
|
|
29
|
+
emitter.on("onWiFiSignalChange", cb);
|
|
30
|
+
};
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
* 监听设备信号强度变化
|
|
34
|
+
* @returns
|
|
35
|
+
*/
|
|
36
|
+
export const offWiFiSignalChange = cb => {
|
|
37
|
+
emitter.off("onWiFiSignalChange", cb);
|
|
38
|
+
};
|