@ray-js/lock-sdk 1.0.4 → 1.1.0-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.
- package/lib/api/index.d.ts +25 -0
- package/lib/api/index.js +59 -3
- package/lib/api/linkage.js +7 -7
- package/lib/api/lock.js +16 -16
- package/lib/api/log.js +6 -6
- package/lib/api/request.d.ts +6 -0
- package/lib/api/request.js +57 -0
- package/lib/api/setting.d.ts +1 -1
- package/lib/api/setting.js +3 -3
- package/lib/api/temp.js +20 -20
- package/lib/api/user.d.ts +21 -0
- package/lib/api/user.js +26 -7
- package/lib/api/video.js +2 -2
- package/lib/capability.d.ts +4 -0
- package/lib/capability.js +95 -0
- package/lib/config/dp-code/index.d.ts +6 -1
- package/lib/config/dp-code/index.js +6 -1
- package/lib/config/dp-map/normal.d.ts +2 -3
- package/lib/config/dp-map/normal.js +2 -9
- package/lib/config/dp-map/unlock-method.d.ts +489 -0
- package/lib/config/dp-map/unlock-method.js +17 -0
- package/lib/config/index.d.ts +6 -1
- package/lib/config/index.js +17 -1
- package/lib/index.d.ts +6 -2
- package/lib/index.js +8 -3
- package/lib/interface.d.ts +33 -1
- package/lib/media.d.ts +1 -0
- package/lib/media.js +9 -1
- package/lib/offline-dps.d.ts +9 -0
- package/lib/offline-dps.js +84 -0
- package/lib/open.d.ts +3 -0
- package/lib/open.js +56 -10
- package/lib/other.d.ts +14 -2
- package/lib/other.js +174 -31
- package/lib/signal.d.ts +1 -0
- package/lib/signal.js +7 -0
- package/lib/sleep.d.ts +3 -3
- package/lib/sleep.js +40 -25
- package/lib/state.js +116 -57
- package/lib/sync/offline-dps.d.ts +1 -0
- package/lib/sync/offline-dps.js +34 -0
- package/lib/sync/remote-serect-key.js +19 -23
- package/lib/sync/t0.js +2 -2
- package/lib/sync/unlock-method.d.ts +2 -0
- package/lib/sync/unlock-method.js +42 -0
- package/lib/sync/user.d.ts +2 -0
- package/lib/sync/user.js +76 -0
- package/lib/utils/device.d.ts +7 -0
- package/lib/utils/device.js +39 -0
- package/lib/utils/errors.js +3 -0
- package/lib/utils/index.js +6 -6
- package/lib/utils/ipc.d.ts +11 -0
- package/lib/utils/ipc.js +26 -0
- package/package.json +2 -2
package/lib/config/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { ProductCommunicationType } from "../constant";
|
|
2
|
-
import { CapabilityInfo, DeviceInfo, DpSchema, RemotePermission, DeviceStatus } from "../interface";
|
|
2
|
+
import { CapabilityInfo, DeviceInfo, DpSchema, RemotePermission, DeviceStatus, LockSDKOption } from "../interface";
|
|
3
3
|
declare const config: {
|
|
4
4
|
devInfo: DeviceInfo;
|
|
5
5
|
dpSchema: Record<string, DpSchema>;
|
|
@@ -17,6 +17,11 @@ declare const config: {
|
|
|
17
17
|
imageAngle: number;
|
|
18
18
|
videoAngle: number;
|
|
19
19
|
supportMultipleFace: boolean;
|
|
20
|
+
supportOfflineDps: boolean;
|
|
20
21
|
deviceStatus: DeviceStatus;
|
|
21
22
|
};
|
|
23
|
+
type UpdateConfigParams = Omit<LockSDKOption, "devInfo" | "deviceId">;
|
|
24
|
+
export declare const updateConfig: (options: UpdateConfigParams) => void;
|
|
25
|
+
export declare const hasCapability: (capability: ProductCommunicationType) => boolean;
|
|
26
|
+
export declare const hasDp: (dpCode: string) => boolean;
|
|
22
27
|
export default config;
|
package/lib/config/index.js
CHANGED
|
@@ -15,10 +15,26 @@ const config = {
|
|
|
15
15
|
imageAngle: 0,
|
|
16
16
|
videoAngle: 0,
|
|
17
17
|
supportMultipleFace: false,
|
|
18
|
+
supportOfflineDps: false,
|
|
18
19
|
deviceStatus: {
|
|
19
20
|
type: "offline",
|
|
20
|
-
|
|
21
|
+
connectEnable: false,
|
|
21
22
|
onlineType: "none",
|
|
23
|
+
isWifiActive: false,
|
|
22
24
|
},
|
|
23
25
|
};
|
|
26
|
+
export const updateConfig = (options) => {
|
|
27
|
+
Object.keys(options).forEach((key) => {
|
|
28
|
+
const value = options[key];
|
|
29
|
+
if (value !== undefined) {
|
|
30
|
+
config[key] = value;
|
|
31
|
+
}
|
|
32
|
+
});
|
|
33
|
+
};
|
|
34
|
+
export const hasCapability = (capability) => {
|
|
35
|
+
return config.communication.includes(capability);
|
|
36
|
+
};
|
|
37
|
+
export const hasDp = (dpCode) => {
|
|
38
|
+
return !!config.dpSchema[dpCode];
|
|
39
|
+
};
|
|
24
40
|
export default config;
|
package/lib/index.d.ts
CHANGED
|
@@ -1,6 +1,9 @@
|
|
|
1
|
+
import { hasCapability, hasDp, updateConfig } from "./config";
|
|
1
2
|
import { LockSDKOption } from "./interface";
|
|
2
3
|
import { getCurrentUser, getDeviceStatus, onDeviceStatusChange, offDeviceStatusChange, getCurrentUserSync, getMediaRotate } from "./state";
|
|
3
|
-
import { syncUnlockMethod } from "./sync/unlock-
|
|
4
|
+
import { syncUnlockMethod } from "./sync/unlock-method";
|
|
5
|
+
import { publishDps } from "./utils/publishDps";
|
|
6
|
+
import { publishOfflineDps, getOfflineDps, isOfflineDpSyncing, onOfflineDpsUpdate, offOfflineDpsUpdate, getOfflineDpCache } from "./offline-dps";
|
|
4
7
|
export * from "./user";
|
|
5
8
|
export * from "./unlock-method";
|
|
6
9
|
export * from "./temporary";
|
|
@@ -13,6 +16,7 @@ export * from "./constant";
|
|
|
13
16
|
export * from "./other";
|
|
14
17
|
export * from "./media";
|
|
15
18
|
export * from "./linkage";
|
|
19
|
+
export * from "./capability";
|
|
16
20
|
export declare const init: (options?: LockSDKOption) => Promise<void>;
|
|
17
21
|
export declare const destroy: () => void;
|
|
18
|
-
export { getCurrentUser, getMediaRotate, getCurrentUserSync, syncUnlockMethod, getDeviceStatus, onDeviceStatusChange, offDeviceStatusChange, };
|
|
22
|
+
export { getCurrentUser, getMediaRotate, getCurrentUserSync, syncUnlockMethod, getDeviceStatus, onDeviceStatusChange, offDeviceStatusChange, updateConfig, hasCapability, hasDp, publishDps, publishOfflineDps, getOfflineDps, isOfflineDpSyncing, onOfflineDpsUpdate, offOfflineDpsUpdate, getOfflineDpCache, };
|
package/lib/index.js
CHANGED
|
@@ -1,9 +1,11 @@
|
|
|
1
|
-
import config from "./config";
|
|
1
|
+
import config, { hasCapability, hasDp, updateConfig } from "./config";
|
|
2
2
|
import dpCodes from "./config/dp-code";
|
|
3
3
|
import { addEvents, clearState, initState, removeEvents, getCurrentUser, getDeviceStatus, onDeviceStatusChange, offDeviceStatusChange, getCurrentUserSync, getMediaRotate, } from "./state";
|
|
4
4
|
import { getCapabilities } from "./utils";
|
|
5
5
|
import { getDeviceInfo, getLaunchOptionsSync } from "./utils/device";
|
|
6
|
-
import { syncUnlockMethod } from "./sync/unlock-
|
|
6
|
+
import { syncUnlockMethod } from "./sync/unlock-method";
|
|
7
|
+
import { publishDps } from "./utils/publishDps";
|
|
8
|
+
import { publishOfflineDps, getOfflineDps, isOfflineDpSyncing, onOfflineDpsUpdate, offOfflineDpsUpdate, getOfflineDpCache, } from "./offline-dps";
|
|
7
9
|
export * from "./user";
|
|
8
10
|
export * from "./unlock-method";
|
|
9
11
|
export * from "./temporary";
|
|
@@ -16,6 +18,7 @@ export * from "./constant";
|
|
|
16
18
|
export * from "./other";
|
|
17
19
|
export * from "./media";
|
|
18
20
|
export * from "./linkage";
|
|
21
|
+
export * from "./capability";
|
|
19
22
|
export const init = async (options) => {
|
|
20
23
|
let { devInfo, deviceId } = options || {};
|
|
21
24
|
if (!devInfo && !deviceId) {
|
|
@@ -50,6 +53,8 @@ export const init = async (options) => {
|
|
|
50
53
|
config.strictMode = options?.strictMode ?? true;
|
|
51
54
|
config.passwordDigitalBase = options?.passwordDigitalBase ?? 10;
|
|
52
55
|
config.passwordSupportZero = options?.passwordSupportZero ?? true;
|
|
56
|
+
config.supportMultipleFace = options?.supportMultipleFace ?? false;
|
|
57
|
+
config.supportOfflineDps = options?.supportOfflineDps ?? false;
|
|
53
58
|
config.devInfo = devInfo;
|
|
54
59
|
config.dpSchema = dpSchema;
|
|
55
60
|
config.codesById = codesById;
|
|
@@ -63,4 +68,4 @@ export const destroy = () => {
|
|
|
63
68
|
clearState();
|
|
64
69
|
removeEvents();
|
|
65
70
|
};
|
|
66
|
-
export { getCurrentUser, getMediaRotate, getCurrentUserSync, syncUnlockMethod, getDeviceStatus, onDeviceStatusChange, offDeviceStatusChange, };
|
|
71
|
+
export { getCurrentUser, getMediaRotate, getCurrentUserSync, syncUnlockMethod, getDeviceStatus, onDeviceStatusChange, offDeviceStatusChange, updateConfig, hasCapability, hasDp, publishDps, publishOfflineDps, getOfflineDps, isOfflineDpSyncing, onOfflineDpsUpdate, offOfflineDpsUpdate, getOfflineDpCache, };
|
package/lib/interface.d.ts
CHANGED
|
@@ -8,6 +8,8 @@ export interface LockSDKOption {
|
|
|
8
8
|
strictMode?: boolean;
|
|
9
9
|
passwordDigitalBase?: number;
|
|
10
10
|
passwordSupportZero?: boolean;
|
|
11
|
+
supportMultipleFace?: boolean;
|
|
12
|
+
supportOfflineDps?: boolean;
|
|
11
13
|
}
|
|
12
14
|
export interface ErrorData {
|
|
13
15
|
errorCode: number;
|
|
@@ -39,6 +41,7 @@ export interface DeviceInfo {
|
|
|
39
41
|
wifiEnableState?: number;
|
|
40
42
|
activeTime: number;
|
|
41
43
|
dpsTime: Record<string, string>;
|
|
44
|
+
parentId?: string;
|
|
42
45
|
}
|
|
43
46
|
export interface DpSchema {
|
|
44
47
|
type: "raw" | "obj";
|
|
@@ -180,12 +183,13 @@ export interface UnBindUnlockMethodGroup {
|
|
|
180
183
|
}
|
|
181
184
|
export interface DeviceStatus {
|
|
182
185
|
type: "offline" | "online" | "sleep";
|
|
183
|
-
|
|
186
|
+
connectEnable: boolean;
|
|
184
187
|
onlineType: "local" | "cloud" | "ble" | "none" | "unknown";
|
|
185
188
|
sleepPeriod?: {
|
|
186
189
|
start: number;
|
|
187
190
|
end: number;
|
|
188
191
|
};
|
|
192
|
+
isWifiActive: boolean;
|
|
189
193
|
}
|
|
190
194
|
export interface UnionUnlockInfo {
|
|
191
195
|
userId: string;
|
|
@@ -287,4 +291,32 @@ export interface AlbumMessage extends MediaInfo {
|
|
|
287
291
|
type: number;
|
|
288
292
|
createTime: number;
|
|
289
293
|
}
|
|
294
|
+
export interface DeviceAdvancedAbility {
|
|
295
|
+
cloudStorage: {
|
|
296
|
+
support: boolean;
|
|
297
|
+
};
|
|
298
|
+
ai: {
|
|
299
|
+
support: boolean;
|
|
300
|
+
config: Record<string, any>;
|
|
301
|
+
};
|
|
302
|
+
wechat: {
|
|
303
|
+
support: boolean;
|
|
304
|
+
config: Record<string, any>;
|
|
305
|
+
};
|
|
306
|
+
wechatVoip: {
|
|
307
|
+
support: boolean;
|
|
308
|
+
config: Record<string, any>;
|
|
309
|
+
};
|
|
310
|
+
voip: {
|
|
311
|
+
support: boolean;
|
|
312
|
+
config: Record<string, any>;
|
|
313
|
+
};
|
|
314
|
+
}
|
|
315
|
+
export interface OfflineDpInfo {
|
|
316
|
+
value: DpValue;
|
|
317
|
+
pushStatus: boolean;
|
|
318
|
+
}
|
|
319
|
+
export interface OfflineDps {
|
|
320
|
+
[code: string]: OfflineDpInfo;
|
|
321
|
+
}
|
|
290
322
|
export {};
|
package/lib/media.d.ts
CHANGED
package/lib/media.js
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
import { getMediaUrl as getMediaUrlApi } from "./api/log";
|
|
2
|
-
import config from "./config";
|
|
2
|
+
import config, { hasDp } from "./config";
|
|
3
|
+
import dpCodes from "./config/dp-code";
|
|
4
|
+
import { VedioType } from "./constant";
|
|
3
5
|
export const getMediaUrl = async (params) => {
|
|
4
6
|
if ("mediaPath" in params && "mediaBucket" in params) {
|
|
5
7
|
return getMediaUrlApi({
|
|
@@ -17,3 +19,9 @@ export const getMediaUrl = async (params) => {
|
|
|
17
19
|
}
|
|
18
20
|
throw new Error("Invalid parameters");
|
|
19
21
|
};
|
|
22
|
+
export const isSupportMedia = () => {
|
|
23
|
+
return (hasDp(dpCodes.linkMode) &&
|
|
24
|
+
hasDp(dpCodes.initiativeMessage) &&
|
|
25
|
+
(!hasDp(dpCodes.deviceInfo) ||
|
|
26
|
+
config.capabilities?.vedioType === VedioType.VEDIO_OR_SNAPSHOT));
|
|
27
|
+
};
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { DpValue, OfflineDps } from "./interface";
|
|
2
|
+
export declare const getOfflineDps: (isForce?: boolean) => Promise<OfflineDps>;
|
|
3
|
+
export declare const checkOfflineDpUpdate: (dps: Record<string, DpValue>, isForce?: boolean) => Promise<void>;
|
|
4
|
+
export declare const getOfflineDpCache: (code: string) => import("./interface").OfflineDpInfo;
|
|
5
|
+
export declare const publishOfflineDps: (dps: Record<string, DpValue>) => Promise<void>;
|
|
6
|
+
export declare const clearOfflineDps: () => Promise<void>;
|
|
7
|
+
export declare const onOfflineDpsUpdate: (callback: (dps: OfflineDps) => void) => void;
|
|
8
|
+
export declare const offOfflineDpsUpdate: (callback: (dps: OfflineDps) => void) => void;
|
|
9
|
+
export declare const isOfflineDpSyncing: (code: string) => boolean;
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
import { clearOfflineDpData, fetchOfflineDpData, publishOfflineDpData, } from "./api";
|
|
2
|
+
import config from "./config";
|
|
3
|
+
import base64ToHex from "./utils/base64-to-hex";
|
|
4
|
+
import hexToBase64 from "./utils/hex-to-base64";
|
|
5
|
+
import emitter from "./utils/event";
|
|
6
|
+
let cache;
|
|
7
|
+
export const getOfflineDps = async (isForce) => {
|
|
8
|
+
if (!isForce && cache) {
|
|
9
|
+
return cache;
|
|
10
|
+
}
|
|
11
|
+
const { devInfo, dpSchema } = config;
|
|
12
|
+
const res = await fetchOfflineDpData(devInfo.devId);
|
|
13
|
+
const result = res.reduce((acc, item) => {
|
|
14
|
+
const dps = JSON.parse(item.dps);
|
|
15
|
+
Object.keys(dps).forEach((code) => {
|
|
16
|
+
const schema = dpSchema[code];
|
|
17
|
+
let value = dps[code];
|
|
18
|
+
if (schema?.type === "raw") {
|
|
19
|
+
value = base64ToHex(value);
|
|
20
|
+
}
|
|
21
|
+
acc[code] = { value, pushStatus: item.pushStatus };
|
|
22
|
+
});
|
|
23
|
+
return acc;
|
|
24
|
+
}, {});
|
|
25
|
+
cache = result;
|
|
26
|
+
return result;
|
|
27
|
+
};
|
|
28
|
+
export const checkOfflineDpUpdate = async (dps, isForce) => {
|
|
29
|
+
if (!config.supportOfflineDps) {
|
|
30
|
+
return;
|
|
31
|
+
}
|
|
32
|
+
const hasOne = Object.keys(dps).some((code) => cache[code]?.pushStatus === false);
|
|
33
|
+
if (hasOne || isForce) {
|
|
34
|
+
const res = await getOfflineDps(true);
|
|
35
|
+
emitter.emit(OFFLINE_DPS_UPDATE, res);
|
|
36
|
+
}
|
|
37
|
+
};
|
|
38
|
+
export const getOfflineDpCache = (code) => {
|
|
39
|
+
return cache[code];
|
|
40
|
+
};
|
|
41
|
+
export const publishOfflineDps = async (dps) => {
|
|
42
|
+
const { devInfo, dpSchema } = config;
|
|
43
|
+
const dpData = Object.keys(dps).reduce((acc, code) => {
|
|
44
|
+
const schema = dpSchema[code];
|
|
45
|
+
if (schema) {
|
|
46
|
+
let value = dps[code];
|
|
47
|
+
if (schema.type === "raw") {
|
|
48
|
+
value = hexToBase64(value);
|
|
49
|
+
}
|
|
50
|
+
acc[schema.id] = value;
|
|
51
|
+
}
|
|
52
|
+
return acc;
|
|
53
|
+
}, {});
|
|
54
|
+
await publishOfflineDpData(devInfo.devId, dpData);
|
|
55
|
+
try {
|
|
56
|
+
await checkOfflineDpUpdate({}, true);
|
|
57
|
+
}
|
|
58
|
+
catch {
|
|
59
|
+
}
|
|
60
|
+
};
|
|
61
|
+
export const clearOfflineDps = async () => {
|
|
62
|
+
const { devInfo } = config;
|
|
63
|
+
await clearOfflineDpData(devInfo.devId);
|
|
64
|
+
try {
|
|
65
|
+
await checkOfflineDpUpdate({}, true);
|
|
66
|
+
}
|
|
67
|
+
catch {
|
|
68
|
+
}
|
|
69
|
+
};
|
|
70
|
+
const OFFLINE_DPS_UPDATE = "offline_dps_update";
|
|
71
|
+
export const onOfflineDpsUpdate = (callback) => {
|
|
72
|
+
emitter.on(OFFLINE_DPS_UPDATE, callback);
|
|
73
|
+
};
|
|
74
|
+
export const offOfflineDpsUpdate = (callback) => {
|
|
75
|
+
emitter.off(OFFLINE_DPS_UPDATE, callback);
|
|
76
|
+
};
|
|
77
|
+
export const isOfflineDpSyncing = (code) => {
|
|
78
|
+
const { supportOfflineDps } = config;
|
|
79
|
+
if (!supportOfflineDps) {
|
|
80
|
+
return false;
|
|
81
|
+
}
|
|
82
|
+
const cache = getOfflineDpCache(code);
|
|
83
|
+
return cache && cache.pushStatus === false;
|
|
84
|
+
};
|
package/lib/open.d.ts
CHANGED
|
@@ -11,6 +11,9 @@ export declare const getRemoteEnabled: () => boolean;
|
|
|
11
11
|
export declare const getRemotePermissionList: () => RemotePermission[];
|
|
12
12
|
export declare const getRemotePermission: () => RemotePermission;
|
|
13
13
|
export declare const updateRemotePermission: (permission: RemotePermission) => Promise<void>;
|
|
14
|
+
export declare const getVoiceUnlockPwdEnabled: () => Promise<boolean>;
|
|
15
|
+
export declare const voiceUnlockPwdDisabled: () => Promise<boolean>;
|
|
16
|
+
export declare const updateVoiceUnlockPwd: (password: string) => Promise<boolean>;
|
|
14
17
|
export declare const agreeOpenDoor: (option?: {
|
|
15
18
|
timeout?: number;
|
|
16
19
|
} | undefined) => Promise<unknown>;
|
package/lib/open.js
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import dpUtils from "@ray-js/tuya-dp-transform";
|
|
2
2
|
import { getDoorKey, openDoorByCloud, isConfirmOpenDoorByWifiPro, } from "./api/lock";
|
|
3
|
-
import config from "./config";
|
|
3
|
+
import config, { hasCapability } from "./config";
|
|
4
4
|
import { isUseNearChannel, parallelMerge, parallelOnly } from "./utils";
|
|
5
|
-
import { decrypt } from "./utils/device";
|
|
5
|
+
import { decrypt, encrypt } from "./utils/device";
|
|
6
6
|
import { publishDps } from "./utils/publishDps";
|
|
7
7
|
import { open as openMap, reportOpen as reportOpenMap, } from "./config/dp-map/open";
|
|
8
8
|
import { stringToBytes } from "./utils/byte";
|
|
@@ -10,10 +10,11 @@ import emitter from "./utils/event";
|
|
|
10
10
|
import { getError } from "./utils/errors";
|
|
11
11
|
import { DPCHANGE } from "./utils/constant";
|
|
12
12
|
import dpCodes from "./config/dp-code";
|
|
13
|
-
import { getCurrentUser, permissions } from "./state";
|
|
13
|
+
import { getCurrentUser, getDeviceStatus, permissions } from "./state";
|
|
14
14
|
import { setDeviceProperties } from "./api/setting";
|
|
15
15
|
import syncRemoteSerectKey from "./sync/remote-serect-key";
|
|
16
|
-
import { ProductCommunicationType } from "./constant";
|
|
16
|
+
import { ProductCommunicationType, UserType } from "./constant";
|
|
17
|
+
import { getVoicePwdEnabled, setVoicePwd } from "./api";
|
|
17
18
|
const getReportError = (status) => {
|
|
18
19
|
let error = getError(1004);
|
|
19
20
|
switch (status) {
|
|
@@ -34,25 +35,40 @@ const getReportError = (status) => {
|
|
|
34
35
|
return error;
|
|
35
36
|
};
|
|
36
37
|
export const checkRemoteEnabled = parallelMerge(async () => {
|
|
37
|
-
const {
|
|
38
|
+
const { dpSchema, remoteOpenEnabled, remoteOpenPermission } = config;
|
|
38
39
|
const { userType } = await getCurrentUser();
|
|
39
|
-
|
|
40
|
+
const deviceStatus = getDeviceStatus();
|
|
41
|
+
const hasThread = hasCapability(ProductCommunicationType.THREAD);
|
|
42
|
+
if (deviceStatus.type !== "online") {
|
|
40
43
|
throw getError(1001);
|
|
41
44
|
}
|
|
45
|
+
if (deviceStatus.onlineType === "local") {
|
|
46
|
+
if (!hasThread) {
|
|
47
|
+
throw getError(1064);
|
|
48
|
+
}
|
|
49
|
+
}
|
|
42
50
|
if (dpSchema[dpCodes.remoteNoDpKey] === undefined) {
|
|
43
51
|
throw getError(1045);
|
|
44
52
|
}
|
|
53
|
+
if ((hasThread && deviceStatus.onlineType === "local") ||
|
|
54
|
+
deviceStatus.onlineType === "ble") {
|
|
55
|
+
return;
|
|
56
|
+
}
|
|
45
57
|
if (!remoteOpenEnabled) {
|
|
46
58
|
throw getError(1046);
|
|
47
59
|
}
|
|
48
60
|
if (remoteOpenPermission === "noOne" ||
|
|
49
|
-
(remoteOpenPermission === "adminsOnly" &&
|
|
61
|
+
(remoteOpenPermission === "adminsOnly" &&
|
|
62
|
+
+userType !== UserType.ADMIN &&
|
|
63
|
+
+userType !== UserType.OWNER)) {
|
|
50
64
|
throw getError(1047);
|
|
51
65
|
}
|
|
52
66
|
});
|
|
53
67
|
const _doAction = async (isOpen, timeout) => {
|
|
54
68
|
const { devInfo, onlineType, capabilities, communication, dpSchema } = config;
|
|
55
69
|
await checkRemoteEnabled();
|
|
70
|
+
const deviceStatus = getDeviceStatus();
|
|
71
|
+
const hasThread = hasCapability(ProductCommunicationType.THREAD);
|
|
56
72
|
const isNear = isUseNearChannel();
|
|
57
73
|
const currentUser = await getCurrentUser();
|
|
58
74
|
const memberId = currentUser.lockUserId !== 0 ? currentUser.lockUserId : currentUser.userId;
|
|
@@ -68,9 +84,17 @@ const _doAction = async (isOpen, timeout) => {
|
|
|
68
84
|
}
|
|
69
85
|
return false;
|
|
70
86
|
};
|
|
87
|
+
if (hasThread && deviceStatus.onlineType === "local") {
|
|
88
|
+
await publishDps({ [dpCodes.matterLanUnlock]: isOpen }, {
|
|
89
|
+
checkReport: (dps) => {
|
|
90
|
+
return typeof dps[dpCodes.matterLanUnlock] !== "undefined";
|
|
91
|
+
},
|
|
92
|
+
});
|
|
93
|
+
return;
|
|
94
|
+
}
|
|
71
95
|
if (isNear) {
|
|
72
|
-
if (
|
|
73
|
-
|
|
96
|
+
if (hasCapability(ProductCommunicationType.WIFI) ||
|
|
97
|
+
hasCapability(ProductCommunicationType.THREAD)) {
|
|
74
98
|
await syncRemoteSerectKey();
|
|
75
99
|
let pw = "";
|
|
76
100
|
try {
|
|
@@ -99,7 +123,7 @@ const _doAction = async (isOpen, timeout) => {
|
|
|
99
123
|
return;
|
|
100
124
|
}
|
|
101
125
|
if (communication.length === 1 &&
|
|
102
|
-
|
|
126
|
+
hasCapability(ProductCommunicationType.BLUETOOTH)) {
|
|
103
127
|
throw new Error("Bluetooth lock opening is not supported yet");
|
|
104
128
|
}
|
|
105
129
|
}
|
|
@@ -187,6 +211,28 @@ const handleOpenDoor = (confirm, timeout) => {
|
|
|
187
211
|
});
|
|
188
212
|
});
|
|
189
213
|
};
|
|
214
|
+
export const getVoiceUnlockPwdEnabled = async () => {
|
|
215
|
+
const res = await getVoicePwdEnabled(config.devInfo.devId);
|
|
216
|
+
return res === true || res === 1;
|
|
217
|
+
};
|
|
218
|
+
export const voiceUnlockPwdDisabled = async () => {
|
|
219
|
+
return setVoicePwd({
|
|
220
|
+
devId: config.devInfo.devId,
|
|
221
|
+
open: false,
|
|
222
|
+
pwd: "",
|
|
223
|
+
});
|
|
224
|
+
};
|
|
225
|
+
export const updateVoiceUnlockPwd = async (password) => {
|
|
226
|
+
if (!/^\d{4,6}$/.test(password)) {
|
|
227
|
+
throw getError(1063);
|
|
228
|
+
}
|
|
229
|
+
const encryptedPassword = await encrypt(config.devInfo.devId, password);
|
|
230
|
+
return setVoicePwd({
|
|
231
|
+
devId: config.devInfo.devId,
|
|
232
|
+
open: false,
|
|
233
|
+
pwd: encryptedPassword,
|
|
234
|
+
});
|
|
235
|
+
};
|
|
190
236
|
export const agreeOpenDoor = parallelOnly((option) => {
|
|
191
237
|
return handleOpenDoor(true, option?.timeout || 15000);
|
|
192
238
|
});
|
package/lib/other.d.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { DpValue } from "./interface";
|
|
1
2
|
type ExecutorRange = "unlock" | "lock";
|
|
2
3
|
type Ability = "backHome" | "alarm" | "geographyArrive" | "geographyLeave" | "bleGeofence" | "siriUnlock" | "siriLock";
|
|
3
4
|
interface OpenSceneOptions {
|
|
@@ -6,7 +7,7 @@ interface OpenSceneOptions {
|
|
|
6
7
|
abilities?: Array<Ability>;
|
|
7
8
|
}
|
|
8
9
|
export declare const openScene: (options?: OpenSceneOptions) => Promise<unknown>;
|
|
9
|
-
export declare const isSupportBleControl: () =>
|
|
10
|
+
export declare const isSupportBleControl: () => boolean;
|
|
10
11
|
export declare const getDpPeriodTime: (dpCode: string) => {
|
|
11
12
|
start: number;
|
|
12
13
|
end: number;
|
|
@@ -14,5 +15,16 @@ export declare const getDpPeriodTime: (dpCode: string) => {
|
|
|
14
15
|
export declare const updateDpPeriodTime: (dpCode: string, data: {
|
|
15
16
|
start: number;
|
|
16
17
|
end: number;
|
|
17
|
-
}
|
|
18
|
+
}, option?: {
|
|
19
|
+
offlineDp?: boolean;
|
|
20
|
+
}) => Promise<void> | Promise<Record<string, DpValue>>;
|
|
21
|
+
export declare const parseDpPeriodTime: (dpValue: string) => {
|
|
22
|
+
start: number;
|
|
23
|
+
end: number;
|
|
24
|
+
};
|
|
25
|
+
export declare const formatDpPeriodTime: (start: number, end: number) => string;
|
|
26
|
+
export declare const connectDevice: () => Promise<unknown>;
|
|
27
|
+
export declare const gotoService: (params?: {
|
|
28
|
+
tab?: "cloudStorage" | "AI";
|
|
29
|
+
}) => Promise<unknown>;
|
|
18
30
|
export {};
|