@ray-js/lock-sdk 1.2.1-beta.1 → 1.2.1-beta.10

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.
Files changed (32) hide show
  1. package/lib/api/gesture.d.ts +4 -2
  2. package/lib/api/video.d.ts +5 -0
  3. package/lib/api/video.js +10 -0
  4. package/lib/entries/main/exports/fit-sdk/temp.d.ts +4 -19
  5. package/lib/entries/main/exports/gesture.d.ts +3 -5
  6. package/lib/entries/main/exports/misc.d.ts +10 -4
  7. package/lib/entries/main/exports/misc.js +7 -1
  8. package/lib/entries/main/exports/notify.d.ts +2 -5
  9. package/lib/entries/main/exports/offline-dps.d.ts +0 -1
  10. package/lib/entries/main/exports/offline-dps.js +1 -4
  11. package/lib/entries/main/exports/temporary.d.ts +2 -11
  12. package/lib/feature/fit/password-list.d.ts +3 -13
  13. package/lib/feature/fit/temp-password.d.ts +3 -2
  14. package/lib/feature/misc/capability.js +36 -1
  15. package/lib/feature/misc/connect-device.d.ts +6 -0
  16. package/lib/feature/misc/connect-device.js +103 -66
  17. package/lib/feature/misc/types.d.ts +3 -0
  18. package/lib/feature/misc/update-config.js +7 -0
  19. package/lib/feature/password/temporary/lists.d.ts +3 -2
  20. package/lib/feature/password/temporary/offline-create.d.ts +3 -2
  21. package/lib/feature/password/temporary/wifi-online.d.ts +3 -2
  22. package/lib/feature/state/init-state.js +43 -29
  23. package/lib/feature/unlock/method/add-flow.js +2 -2
  24. package/lib/feature/unlock/method/add-password.js +2 -2
  25. package/lib/feature/unlock/method/update-remove.js +1 -1
  26. package/lib/interface.d.ts +8 -0
  27. package/lib/platform/device.d.ts +1 -0
  28. package/lib/platform/device.js +11 -2
  29. package/lib/platform/ipc.d.ts +1 -0
  30. package/lib/platform/ipc.js +6 -0
  31. package/lib/utils/errors.js +2 -0
  32. package/package.json +1 -1
@@ -4,8 +4,10 @@ export interface GestureStatus {
4
4
  [k: string]: any;
5
5
  }
6
6
  export declare const getGestureStatusApi: (devId: string) => Promise<GestureStatus>;
7
- export declare const setGestureStatusApi: (params: {
8
- devId: string;
7
+ export interface UpdateGestureStatusParams {
9
8
  password: string;
10
9
  open: boolean;
10
+ }
11
+ export declare const setGestureStatusApi: (params: UpdateGestureStatusParams & {
12
+ devId: string;
11
13
  }) => Promise<boolean>;
@@ -48,4 +48,9 @@ interface GetDeviceCurrentMeidaConfigResult {
48
48
  vedioClaritys: number[];
49
49
  }
50
50
  export declare const getDeviceCurrentMeidaConfig: (devId: string) => Promise<GetDeviceCurrentMeidaConfigResult>;
51
+ interface GetVideoResolutionMarkResult {
52
+ capability: number[];
53
+ cloudCapability: string[];
54
+ }
55
+ export declare const getVideoResolutionMark: (devId: string) => Promise<GetVideoResolutionMarkResult>;
51
56
  export {};
package/lib/api/video.js CHANGED
@@ -70,3 +70,13 @@ export const getDeviceCurrentMeidaConfig = (devId) => {
70
70
  },
71
71
  });
72
72
  };
73
+ export const getVideoResolutionMark = (devId) => {
74
+ return requestApi({
75
+ logName: "getVideoResolutionMark",
76
+ api: `${THING}.m.device.lock.capability.cloud.get`,
77
+ version: "1.0",
78
+ data: {
79
+ devId,
80
+ },
81
+ });
82
+ };
@@ -1,25 +1,13 @@
1
1
  import { type FitOnlinePasswordItem, type FitOfflinePasswordItem } from "../../../../feature/fit/password-list";
2
2
  import { type AddFitTempPwdParams, type RemoveFitTempPwdParams, type RenameFitTempPwdParams, type RenameFitOfflineTempPwdParams, type RevokeFitOfflineTempPwdParams, type FitOfflineClearCodeResult, type ResendFitTempPwdParams, type UpdateFitTempPwdParams } from "../../../../feature/fit/temp-password";
3
3
  import { type ClearFitInvalidPwdParams, type GetFitInvalidPwdListParams } from "../../../../feature/fit/invalid-password";
4
- import { type FitOfflineOnceResult } from "../../../../feature/password/temporary/offline-create";
4
+ import { type FitOfflineOnceResult, type FitOfflineLimitParams } from "../../../../feature/password/temporary/offline-create";
5
5
  import type { LimitOfflinePwdItem, OfflinePwdAvailableResult } from "../../../../api/temp";
6
6
  import type { TempPasswordResult } from "../../../../interface";
7
- export declare function getFitPasswordList(): Promise<{
8
- id: number;
9
- unlockId: string;
10
- unlockName: string;
11
- photoUnlock: boolean;
12
- userName: string;
13
- lockUserId: number;
14
- userType: number;
15
- devLockId: string;
16
- effective: import("../../../../interface").EffectiveConfig;
17
- }[]>;
7
+ export declare function getFitPasswordList(): Promise<import("../../../../feature/fit/password-list").FitPasswordItem[]>;
18
8
  export declare function getFitOnlinePasswordList(): Promise<FitOnlinePasswordItem[]>;
19
9
  export declare function getFitOfflinePasswordList(): Promise<FitOfflinePasswordItem[]>;
20
- export declare function addFitTempPwd(params: AddFitTempPwdParams): Promise<{
21
- pwdId: number;
22
- }>;
10
+ export declare function addFitTempPwd(params: AddFitTempPwdParams): Promise<import("../../../../feature/fit/temp-password").AddFitTempPwdResult>;
23
11
  export declare function removeFitTempPwd(params: RemoveFitTempPwdParams): Promise<void>;
24
12
  export declare function updateFitTempPwd(params: UpdateFitTempPwdParams): Promise<void>;
25
13
  export declare function renameFitTempPwd(params: RenameFitTempPwdParams): Promise<void>;
@@ -30,10 +18,7 @@ export declare function getFitInvalidPwdList(params?: GetFitInvalidPwdListParams
30
18
  export declare function clearFitInvalidPwd(params?: ClearFitInvalidPwdParams): Promise<boolean>;
31
19
  export declare function getFitDynamicPassword(): Promise<TempPasswordResult>;
32
20
  export declare function getFitOfflineOncePassword(): Promise<FitOfflineOnceResult>;
33
- export declare function getFitOfflineLimitPassword(params: {
34
- effectiveTime: number;
35
- invalidTime: number;
36
- }): Promise<FitOfflineOnceResult>;
21
+ export declare function getFitOfflineLimitPassword(params: FitOfflineLimitParams): Promise<FitOfflineOnceResult>;
37
22
  export declare function getFitOfflineClearAllCode(): Promise<FitOfflineOnceResult>;
38
23
  export declare function getFitOfflineRevocableList(): Promise<LimitOfflinePwdItem[]>;
39
24
  export declare function getFitOfflinePwdAvailable(pwdType: string): Promise<OfflinePwdAvailableResult>;
@@ -1,6 +1,4 @@
1
- export type { GestureStatus } from "../../../api/gesture";
1
+ import type { UpdateGestureStatusParams } from "../../../api/gesture";
2
+ export type { GestureStatus, UpdateGestureStatusParams, } from "../../../api/gesture";
2
3
  export declare function getGestureStatus(): Promise<import("../../../api/gesture").GestureStatus>;
3
- export declare function updateGestureStatus(params: {
4
- password: string;
5
- open: boolean;
6
- }): Promise<boolean>;
4
+ export declare function updateGestureStatus(params: UpdateGestureStatusParams): Promise<boolean>;
@@ -1,5 +1,5 @@
1
1
  import { GotoServiceParams } from "../../../feature/service/goto-service";
2
- import type { OpenSceneOptions } from "../../../feature/misc/types";
2
+ import type { OpenSceneOptions, ConnectDeviceOptions } from "../../../feature/misc/types";
3
3
  export { parseDpPeriodTime } from "../../../feature/misc/dp-period";
4
4
  export { formatDpPeriodTime } from "../../../feature/misc/dp-period";
5
5
  export declare function openScene(options?: OpenSceneOptions): Promise<void>;
@@ -13,8 +13,14 @@ export interface UpdateDpPeriodTimeOption {
13
13
  offlineDp?: boolean;
14
14
  }
15
15
  export declare function updateDpPeriodTime(dpCode: string, data: UpdateDpPeriodTimeParams, option?: UpdateDpPeriodTimeOption): Promise<void>;
16
- export declare function connectDevice(options?: {
17
- timeout?: number;
18
- }): Promise<true>;
16
+ export declare function connectDevice(options?: ConnectDeviceOptions): Promise<true>;
19
17
  export declare function gotoService(params?: GotoServiceParams): Promise<void>;
20
18
  export declare function validatePwdComplexity(password: string): Promise<boolean>;
19
+ export interface AwakeDeviceOptions {
20
+ timeout?: number;
21
+ }
22
+ export declare function awakeDevice(options?: AwakeDeviceOptions): Promise<true>;
23
+ interface DisconnectDeviceOptions {
24
+ disconnetBle?: boolean;
25
+ }
26
+ export declare function disconnectDevice(options?: DisconnectDeviceOptions): Promise<void>;
@@ -2,7 +2,7 @@ import { resolveRuntimeFromExportThis } from "../bootstrap/resolve-runtime-from-
2
2
  import { openSceneForRuntime } from "../../../feature/misc/open-scene";
3
3
  import { isSupportBleControlForRuntime } from "../../../feature/misc/ble-control";
4
4
  import { getDpPeriodTimeForRuntime, updateDpPeriodTimeForRuntime, } from "../../../feature/misc/dp-period";
5
- import { connectDeviceForRuntime } from "../../../feature/misc/connect-device";
5
+ import { awakeDeviceForRuntime, connectDeviceForRuntime, disconnectDeviceForRuntime, } from "../../../feature/misc/connect-device";
6
6
  import { validatePwdComplexityForRuntime } from "../../../feature/misc/validate-pwd";
7
7
  import { gotoServiceForRuntime, } from "../../../feature/service/goto-service";
8
8
  export { parseDpPeriodTime } from "../../../feature/misc/dp-period";
@@ -28,3 +28,9 @@ export async function gotoService(params) {
28
28
  export async function validatePwdComplexity(password) {
29
29
  return validatePwdComplexityForRuntime(resolveRuntimeFromExportThis(this), password);
30
30
  }
31
+ export async function awakeDevice(options) {
32
+ return awakeDeviceForRuntime(resolveRuntimeFromExportThis(this), options);
33
+ }
34
+ export async function disconnectDevice(options) {
35
+ return disconnectDeviceForRuntime(resolveRuntimeFromExportThis(this), options);
36
+ }
@@ -1,7 +1,4 @@
1
+ import type { UpdateVasNotifyConfigParams } from "../../../api/notify";
1
2
  export type { VasNotifyConfig, VasNotifyScene, VasNotifyPushConfig, UpdateVasNotifyConfigParams, } from "../../../api/notify";
2
3
  export declare function getVasNotifyConfig(): Promise<import("../../../api/notify").VasNotifyConfig>;
3
- export declare function updateVasNotifyConfig(params: {
4
- key: string;
5
- enable: boolean;
6
- userId?: string;
7
- }): Promise<import("../../../api/notify").VasNotifyConfig>;
4
+ export declare function updateVasNotifyConfig(params: UpdateVasNotifyConfigParams): Promise<import("../../../api/notify").VasNotifyConfig>;
@@ -4,5 +4,4 @@ export declare function offOfflineDpsUpdate(callback: (dps: OfflineDps) => void)
4
4
  export declare function publishOfflineDps(dps: Record<string, DpValue>): Promise<void>;
5
5
  export declare function getOfflineDps(isForce?: boolean): Promise<OfflineDps>;
6
6
  export declare function getOfflineDpCache(code: string): import("../../../interface").OfflineDpInfo | undefined;
7
- export declare function checkOfflineDpUpdate(dps: Record<string, DpValue>, isForce?: boolean): Promise<void>;
8
7
  export declare function isOfflineDpSyncing(code: string): boolean;
@@ -1,5 +1,5 @@
1
1
  import { resolveRuntimeFromExportThis } from "../bootstrap/resolve-runtime-from-export-this";
2
- import { checkOfflineDpUpdateForRuntime, publishOfflineDpsForRuntime, getOfflineDpsForRuntime, getOfflineDpCacheForRuntime, onOfflineDpsUpdateForRuntime, offOfflineDpsUpdateForRuntime, } from "../../../feature/offline-dps";
2
+ import { publishOfflineDpsForRuntime, getOfflineDpsForRuntime, getOfflineDpCacheForRuntime, onOfflineDpsUpdateForRuntime, offOfflineDpsUpdateForRuntime, } from "../../../feature/offline-dps";
3
3
  export function onOfflineDpsUpdate(callback) {
4
4
  onOfflineDpsUpdateForRuntime(resolveRuntimeFromExportThis(this), callback);
5
5
  }
@@ -15,9 +15,6 @@ export async function getOfflineDps(isForce) {
15
15
  export function getOfflineDpCache(code) {
16
16
  return getOfflineDpCacheForRuntime(resolveRuntimeFromExportThis(this), code);
17
17
  }
18
- export async function checkOfflineDpUpdate(dps, isForce) {
19
- return checkOfflineDpUpdateForRuntime(resolveRuntimeFromExportThis(this), dps, isForce);
20
- }
21
18
  export function isOfflineDpSyncing(code) {
22
19
  const rt = resolveRuntimeFromExportThis(this);
23
20
  if (!rt.config.supportOfflineDps) {
@@ -5,21 +5,12 @@ export declare function createTempCustom(params: CreateCustomParams): Promise<Te
5
5
  export declare function removeTempCustom(params: RemoveCustomProps): Promise<boolean>;
6
6
  export declare function updateTempCustom(params: UpdateTempPasswordParams): Promise<boolean>;
7
7
  export declare function getTempEffectiveList(): Promise<import("../../../feature/password/temporary/types").EffectivePasswrodItem[]>;
8
- export declare function getTempInvalidList(params?: GetInvalidListParams): Promise<{
9
- list: import("../../../feature/password/temporary/types").InvalidPasswordItem[];
10
- hasMore: boolean;
11
- total: number;
12
- }>;
8
+ export declare function getTempInvalidList(params?: GetInvalidListParams): Promise<import("../../../feature/password/temporary/lists").GetTempInvalidListResult>;
13
9
  export declare function clearTempInvalidList(): Promise<boolean>;
14
10
  export declare function freezeTemp(params: FreezeParams): Promise<boolean>;
15
11
  export declare function unfreezeTemp(params: FreezeParams): Promise<boolean>;
16
12
  export declare function renameTemp(params: RenameParams): Promise<void>;
17
- export declare function saveTempOnlineUnlimited(params: CreateOnlineUnlimitedParams): Promise<{
18
- type: "custom";
19
- name: string;
20
- pwdId: string;
21
- effectiveConfig: import("../../../interface").EffectiveConfig;
22
- }>;
13
+ export declare function saveTempOnlineUnlimited(params: CreateOnlineUnlimitedParams): Promise<import("../../../feature/password/temporary/wifi-online").SaveTempOnlineUnlimitedResult>;
23
14
  export declare function removeTempOnlineUnlimited(id: string): Promise<void>;
24
15
  export declare function getTempOnlineUnlimitedList(): Promise<import("../../../feature/password/temporary/wifi-online").OnlinePasswordItem[]>;
25
16
  export declare function createTempOffline(params: CreateOfflineParams): Promise<import("../../../feature/password/temporary/types").OfflineTempResult>;
@@ -1,18 +1,7 @@
1
1
  import { type RawFitOpenModeScheduleItem } from "../../api/fit";
2
- import { EffectiveConfig, UnlockMethodType } from "../../interface";
2
+ import { EffectiveConfig } from "../../interface";
3
3
  import { LockDeviceRuntime } from "../../runtime/LockDeviceRuntime";
4
4
  export interface FitPasswordItem {
5
- id: number;
6
- unlockId: number;
7
- unlockName: string;
8
- type: UnlockMethodType;
9
- userName: string;
10
- lockUserId: number;
11
- userType: number;
12
- devLockId: string;
13
- effective: EffectiveConfig;
14
- }
15
- export declare const getFitPasswordListForRuntime: (runtime: LockDeviceRuntime) => Promise<{
16
5
  id: number;
17
6
  unlockId: string;
18
7
  unlockName: string;
@@ -22,7 +11,8 @@ export declare const getFitPasswordListForRuntime: (runtime: LockDeviceRuntime)
22
11
  userType: number;
23
12
  devLockId: string;
24
13
  effective: EffectiveConfig;
25
- }[]>;
14
+ }
15
+ export declare const getFitPasswordListForRuntime: (runtime: LockDeviceRuntime) => Promise<FitPasswordItem[]>;
26
16
  export interface FitOnlinePasswordItem {
27
17
  id: number;
28
18
  pwdId: number;
@@ -15,9 +15,10 @@ export interface UpdateFitTempPwdParams {
15
15
  name: string;
16
16
  effective: EffectiveConfig;
17
17
  }
18
- export declare function fitAddTempPwdForRuntime(runtime: LockDeviceRuntime, params: AddFitTempPwdParams): Promise<{
18
+ export interface AddFitTempPwdResult {
19
19
  pwdId: number;
20
- }>;
20
+ }
21
+ export declare function fitAddTempPwdForRuntime(runtime: LockDeviceRuntime, params: AddFitTempPwdParams): Promise<AddFitTempPwdResult>;
21
22
  export declare function fitRemoveTempPwdForRuntime(runtime: LockDeviceRuntime, params: RemoveFitTempPwdParams): Promise<void>;
22
23
  export declare function fitUpdateTempPwdForRuntime(runtime: LockDeviceRuntime, params: UpdateFitTempPwdParams): Promise<void>;
23
24
  export interface RenameFitTempPwdParams {
@@ -3,6 +3,9 @@ import { CommunicationType, ProductCommunicationType } from "../../constant";
3
3
  import { checkShowMatterMutilpleShare } from "../../platform/device";
4
4
  import { ipc } from "../../platform";
5
5
  import { getWithLocalCache } from "../storage/swr-cache";
6
+ import { getVideoResolutionMark } from "../../api/video";
7
+ import dpCodes from "../../config/dp-code";
8
+ import { hasDpForRuntime } from "../dp/has-dp";
6
9
  export const hasCapabilityForRuntime = (runtime, capability) => runtime.config.communication.includes(capability);
7
10
  export const isBlePureDeviceForRuntime = (rt) => hasCapabilityForRuntime(rt, ProductCommunicationType.BLUETOOTH) &&
8
11
  rt.config.communication.length === 1;
@@ -68,7 +71,7 @@ export const getDeviceAdvancedAbilitiesForRuntime = async (rt) => {
68
71
  return rt.cache.deviceAdvanceAbilityCache;
69
72
  }
70
73
  const devId = rt.config.devInfo.devId;
71
- const [productAbilitiesRes, deviceAdvancedAbilityRes, tttList] = await Promise.allSettled([
74
+ const [productAbilitiesRes, deviceAdvancedAbilityRes, tttList, videoMarkRes] = await Promise.allSettled([
72
75
  getWithLocalCache(rt, "productAbilities", () => getProductAbilities(devId, [
73
76
  "tyabi4ucx5",
74
77
  "tyabis9tpe",
@@ -79,10 +82,23 @@ export const getDeviceAdvancedAbilitiesForRuntime = async (rt) => {
79
82
  ])),
80
83
  getWithLocalCache(rt, "deviceAdvancedAbility", () => getDeviceAdvancedAbility(devId)),
81
84
  ipc.getTTTAbilityKeyList("isSupportedVRMode"),
85
+ hasDpForRuntime(rt, dpCodes.initiativeMessage)
86
+ ? getWithLocalCache(rt, "videoResolutionMark", () => getVideoResolutionMark(devId))
87
+ : Promise.resolve({
88
+ capability: [],
89
+ cloudCapability: [],
90
+ }),
82
91
  ]);
83
92
  const productAbilities = productAbilitiesRes.status === "fulfilled" ? productAbilitiesRes.value : [];
84
93
  const tttAbList = tttList.status === "fulfilled" ? tttList.value.abilityList : [];
94
+ const videoMark = videoMarkRes.status === "fulfilled"
95
+ ? videoMarkRes.value
96
+ : { capability: [], cloudCapability: [] };
85
97
  const deviceAdvanceAbilityCache = {
98
+ videoConfig: {
99
+ isLowResolution: videoMark?.cloudCapability?.includes("tyabig3wt9"),
100
+ isHighResolution: videoMark?.cloudCapability?.includes("tyabixkep7"),
101
+ },
86
102
  cloudStorage: {
87
103
  support: false,
88
104
  },
@@ -91,6 +107,7 @@ export const getDeviceAdvancedAbilitiesForRuntime = async (rt) => {
91
107
  defaultMode: "VR",
92
108
  modes: [],
93
109
  coverMode: "VR",
110
+ options: {},
94
111
  },
95
112
  ai: {
96
113
  support: false,
@@ -151,6 +168,24 @@ export const getDeviceAdvancedAbilitiesForRuntime = async (rt) => {
151
168
  deviceAdvanceAbilityCache.vr.modes?.[0]?.mode;
152
169
  }
153
170
  deviceAdvanceAbilityCache.vr.coverMode = data.photo_cover_format;
171
+ if (data.configs) {
172
+ let options;
173
+ try {
174
+ options = JSON.parse(data.configs);
175
+ }
176
+ catch (e) {
177
+ }
178
+ if (options.zoomIn) {
179
+ deviceAdvanceAbilityCache.vr.options.zoomIn =
180
+ Number(options.zoomIn?.value) > 0
181
+ ? Number(options.zoomIn?.value)
182
+ : undefined;
183
+ deviceAdvanceAbilityCache.vr.options.radialEmphasis =
184
+ Number(options.radialEmphasis?.value) > 0
185
+ ? Number(options.radialEmphasis?.value)
186
+ : undefined;
187
+ }
188
+ }
154
189
  }
155
190
  break;
156
191
  }
@@ -1,2 +1,8 @@
1
1
  import type { LockDeviceRuntime } from "../../runtime/LockDeviceRuntime";
2
2
  export declare function connectDeviceForRuntime(rt: LockDeviceRuntime, timeout?: number): Promise<true>;
3
+ export declare const awakeDeviceForRuntime: (runtime: LockDeviceRuntime, options?: {
4
+ timeout?: number;
5
+ }) => Promise<true>;
6
+ export declare const disconnectDeviceForRuntime: (rt: LockDeviceRuntime, options?: {
7
+ disconnetBle?: boolean;
8
+ }) => Promise<void>;
@@ -1,5 +1,5 @@
1
1
  import dpCodes from "../../config/dp-code";
2
- import { connectBLEDevice, getBLEOnlineState, onBleChange, onOnlineChange, offBleChange, offOnlineChange, yuChannelSyncSingleSync, } from "../../platform/device";
2
+ import { connectBLEDevice, getBLEOnlineState, onBleChange, onOnlineChange, offBleChange, offOnlineChange, yuChannelSyncSingleSync, disconnectBLEDevice, } from "../../platform/device";
3
3
  import { DPCHANGE } from "../../utils/constant";
4
4
  import emitter from "../../utils/event";
5
5
  import { getError } from "../../utils/errors";
@@ -8,70 +8,8 @@ import { getDpValueForRuntime } from "../dp/get-dp-value";
8
8
  import { getDeviceStatusForRuntime } from "../state/device-status";
9
9
  import { isSupportBleControlForRuntime } from "./ble-control";
10
10
  import { sdkLog } from "../../utils/sdk-log";
11
+ import { hasDpForRuntime } from "../dp/has-dp";
11
12
  const { wirelessAwake } = dpCodes;
12
- const awakeDevice = async (devId, timeout) => {
13
- const startedAt = Date.now();
14
- sdkLog("info", "connectDevice", "awakeStart", {
15
- devId,
16
- data: { timeout: timeout || 15000 },
17
- });
18
- return new Promise((resolve, reject) => {
19
- const handleChangeDp = (dpCodesArg) => {
20
- if (dpCodesArg[wirelessAwake] === true) {
21
- sdkLog("info", "connectDevice", "awakeReportSuccess", {
22
- devId,
23
- duration: Date.now() - startedAt,
24
- });
25
- resolve(true);
26
- emitter.off(DPCHANGE, handleChangeDp);
27
- clearTimeout(timer);
28
- }
29
- };
30
- emitter.on(DPCHANGE, handleChangeDp);
31
- const timer = setTimeout(() => {
32
- emitter.off(DPCHANGE, handleChangeDp);
33
- const error = getError(1002);
34
- sdkLog("warn", "connectDevice", "awakeTimeout", {
35
- devId,
36
- duration: Date.now() - startedAt,
37
- error,
38
- });
39
- reject(error);
40
- }, timeout || 15000);
41
- const run = async () => {
42
- try {
43
- ipc.wakeUpDoorBell(devId);
44
- ipc.wakeUpDoorBell(devId);
45
- ipc.wakeUpDoorBell(devId);
46
- const connected = await ipc.isConnected(devId);
47
- if (connected.isConnected) {
48
- sdkLog("info", "connectDevice", "awakeAlreadyConnected", {
49
- devId,
50
- duration: Date.now() - startedAt,
51
- });
52
- return resolve(true);
53
- }
54
- const connecting = await ipc.isConnecting(devId);
55
- if (!connecting.isConnecting) {
56
- sdkLog("info", "connectDevice", "awakeIpcConnectStart", { devId });
57
- await ipc.connect(devId);
58
- }
59
- else {
60
- sdkLog("debug", "connectDevice", "awakeIpcConnecting", { devId });
61
- }
62
- }
63
- catch (error) {
64
- sdkLog("error", "connectDevice", "awakeFail", {
65
- devId,
66
- duration: Date.now() - startedAt,
67
- error,
68
- });
69
- reject(error);
70
- }
71
- };
72
- run();
73
- });
74
- };
75
13
  const connectBle = async (devId, timeout) => {
76
14
  const startedAt = Date.now();
77
15
  sdkLog("info", "connectDevice", "bleConnectStart", { devId });
@@ -147,7 +85,7 @@ export async function connectDeviceForRuntime(rt, timeout) {
147
85
  const cfg = rt.config;
148
86
  const devId = cfg.devInfo.devId;
149
87
  const deviceStatus = getDeviceStatusForRuntime(rt);
150
- const hasWirelessAwakeDp = !!cfg.dpSchema[wirelessAwake];
88
+ const hasWirelessAwakeDp = hasDpForRuntime(rt, wirelessAwake) && !cfg.notSupportWake;
151
89
  const startedAt = Date.now();
152
90
  sdkLog("info", "connectDevice", "start", {
153
91
  devId,
@@ -160,7 +98,7 @@ export async function connectDeviceForRuntime(rt, timeout) {
160
98
  });
161
99
  if (deviceStatus.connectEnable && hasWirelessAwakeDp) {
162
100
  if (cfg.devInfo.isCloudOnline && !getDpValueForRuntime(rt, wirelessAwake)) {
163
- const result = await awakeDevice(devId, timeout);
101
+ const result = await awakeDeviceForRuntime(rt, { timeout });
164
102
  sdkLog("info", "connectDevice", "success", {
165
103
  devId,
166
104
  duration: Date.now() - startedAt,
@@ -205,3 +143,102 @@ export async function connectDeviceForRuntime(rt, timeout) {
205
143
  });
206
144
  throw error;
207
145
  }
146
+ export const awakeDeviceForRuntime = (runtime, options) => {
147
+ const cfg = runtime.config;
148
+ const devId = cfg.devInfo.devId;
149
+ const timeout = options?.timeout || 15000;
150
+ const startedAt = Date.now();
151
+ const hasWirelessAwake = hasDpForRuntime(runtime, wirelessAwake) && !cfg.notSupportWake;
152
+ sdkLog("info", "connectDevice", "awakeStart", {
153
+ devId,
154
+ data: { timeout, hasWirelessAwake },
155
+ });
156
+ return new Promise((resolve, reject) => {
157
+ const handleChangeDp = (dpCodesArg) => {
158
+ if (dpCodesArg[wirelessAwake] === true) {
159
+ sdkLog("info", "connectDevice", "awakeReportSuccess", {
160
+ devId,
161
+ duration: Date.now() - startedAt,
162
+ });
163
+ resolve(true);
164
+ emitter.off(DPCHANGE, handleChangeDp);
165
+ clearTimeout(timer);
166
+ }
167
+ };
168
+ hasWirelessAwake && emitter.on(DPCHANGE, handleChangeDp);
169
+ const timer = setTimeout(() => {
170
+ emitter.off(DPCHANGE, handleChangeDp);
171
+ const error = getError(1002);
172
+ sdkLog("warn", "connectDevice", "awakeTimeout", {
173
+ devId,
174
+ duration: Date.now() - startedAt,
175
+ error,
176
+ });
177
+ reject(error);
178
+ }, timeout);
179
+ const run = async () => {
180
+ try {
181
+ ipc.wakeUpDoorBell(devId);
182
+ ipc.wakeUpDoorBell(devId);
183
+ ipc.wakeUpDoorBell(devId);
184
+ const connected = await ipc.isConnected(devId);
185
+ if (connected.isConnected) {
186
+ sdkLog("info", "connectDevice", "awakeAlreadyConnected", {
187
+ devId,
188
+ duration: Date.now() - startedAt,
189
+ });
190
+ clearTimeout(timer);
191
+ return resolve(true);
192
+ }
193
+ const connecting = await ipc.isConnecting(devId);
194
+ if (!connecting.isConnecting) {
195
+ sdkLog("info", "connectDevice", "awakeIpcConnectStart", { devId });
196
+ await ipc.connect(devId);
197
+ if (!hasWirelessAwake) {
198
+ clearTimeout(timer);
199
+ return resolve(true);
200
+ }
201
+ }
202
+ else {
203
+ sdkLog("debug", "connectDevice", "awakeIpcConnecting", { devId });
204
+ }
205
+ }
206
+ catch (error) {
207
+ sdkLog("error", "connectDevice", "awakeFail", {
208
+ devId,
209
+ duration: Date.now() - startedAt,
210
+ error,
211
+ });
212
+ reject(error);
213
+ }
214
+ };
215
+ run();
216
+ });
217
+ };
218
+ export const disconnectDeviceForRuntime = async (rt, options) => {
219
+ const cfg = rt.config;
220
+ const devId = cfg.devInfo.devId;
221
+ const startedAt = Date.now();
222
+ sdkLog("info", "disconnectDevice", "start", {
223
+ devId,
224
+ });
225
+ try {
226
+ const deviceStatus = getDeviceStatusForRuntime(rt);
227
+ await ipc.disConnect(devId);
228
+ if (deviceStatus.onlineTypes.includes("ble") && !!options?.disconnetBle) {
229
+ await disconnectBLEDevice(devId);
230
+ }
231
+ sdkLog("info", "disconnectDevice", "success", {
232
+ devId,
233
+ duration: Date.now() - startedAt,
234
+ });
235
+ }
236
+ catch (e) {
237
+ sdkLog("error", "disconnectDevice", "Fail", {
238
+ devId,
239
+ duration: Date.now() - startedAt,
240
+ error: e,
241
+ });
242
+ throw e;
243
+ }
244
+ };
@@ -1,5 +1,8 @@
1
1
  export type ExecutorRange = "unlock" | "lock";
2
2
  export type Ability = "backHome" | "alarm" | "geographyArrive" | "geographyLeave" | "bleGeofence" | "siriUnlock" | "siriLock";
3
+ export interface ConnectDeviceOptions {
4
+ timeout?: number;
5
+ }
3
6
  export interface OpenSceneOptions {
4
7
  themeColor?: string;
5
8
  executorRange?: Array<ExecutorRange>;
@@ -1,9 +1,16 @@
1
+ import { updateDeviceStatus } from "../state/device-status";
1
2
  export function updateConfigForRuntime(runtime, options) {
2
3
  const cfg = runtime.config;
4
+ let needUpdateDeviceStatus = false;
5
+ if (typeof options?.notSupportWake === "boolean" &&
6
+ cfg.notSupportWake !== options.notSupportWake) {
7
+ needUpdateDeviceStatus = true;
8
+ }
3
9
  Object.keys(options).forEach((key) => {
4
10
  const value = options[key];
5
11
  if (value !== undefined) {
6
12
  cfg[key] = value;
7
13
  }
8
14
  });
15
+ needUpdateDeviceStatus && updateDeviceStatus(runtime);
9
16
  }
@@ -1,11 +1,12 @@
1
1
  import type { LockDeviceRuntime } from "../../../runtime/LockDeviceRuntime";
2
2
  import type { EffectivePasswrodItem, GetInvalidListParams, InvalidPasswordItem } from "./types";
3
3
  export declare function getTempEffectiveListForRuntime(rt: LockDeviceRuntime): Promise<EffectivePasswrodItem[]>;
4
- export declare function getTempInvalidListForRuntime(rt: LockDeviceRuntime, params?: GetInvalidListParams): Promise<{
4
+ export interface GetTempInvalidListResult {
5
5
  list: InvalidPasswordItem[];
6
6
  hasMore: boolean;
7
7
  total: number;
8
- }>;
8
+ }
9
+ export declare function getTempInvalidListForRuntime(rt: LockDeviceRuntime, params?: GetInvalidListParams): Promise<GetTempInvalidListResult>;
9
10
  export declare function clearTempInvalidListForRuntime(rt: LockDeviceRuntime): Promise<boolean>;
10
11
  export interface LimitTempItem {
11
12
  id: string;
@@ -10,10 +10,11 @@ export interface FitOfflineOnceResult {
10
10
  gmtExpired: number;
11
11
  }
12
12
  export declare function createFitOfflineOnceForRuntime(rt: LockDeviceRuntime): Promise<FitOfflineOnceResult>;
13
- export declare function createFitOfflineLimitForRuntime(rt: LockDeviceRuntime, params: {
13
+ export interface FitOfflineLimitParams {
14
14
  effectiveTime: number;
15
15
  invalidTime: number;
16
- }): Promise<FitOfflineOnceResult>;
16
+ }
17
+ export declare function createFitOfflineLimitForRuntime(rt: LockDeviceRuntime, params: FitOfflineLimitParams): Promise<FitOfflineOnceResult>;
17
18
  export declare function createFitOfflineClearAllForRuntime(rt: LockDeviceRuntime): Promise<FitOfflineOnceResult>;
18
19
  export declare function getFitOfflineRevocableListForRuntime(rt: LockDeviceRuntime): Promise<LimitOfflinePwdItem[]>;
19
20
  export declare function getFitOfflinePwdAvailableForRuntime(rt: LockDeviceRuntime, pwdType: string): Promise<OfflinePwdAvailableResult>;
@@ -1,12 +1,13 @@
1
1
  import type { LockDeviceRuntime } from "../../../runtime/LockDeviceRuntime";
2
2
  import type { CreateOnlineUnlimitedParams } from "./types";
3
3
  import type { EffectiveConfig } from "../../../interface";
4
- export declare function saveTempOnlineUnlimitedForRuntime(rt: LockDeviceRuntime, params: CreateOnlineUnlimitedParams): Promise<{
4
+ export interface SaveTempOnlineUnlimitedResult {
5
5
  type: "custom";
6
6
  name: string;
7
7
  pwdId: string;
8
8
  effectiveConfig: EffectiveConfig;
9
- }>;
9
+ }
10
+ export declare function saveTempOnlineUnlimitedForRuntime(rt: LockDeviceRuntime, params: CreateOnlineUnlimitedParams): Promise<SaveTempOnlineUnlimitedResult>;
10
11
  export declare function removeTempOnlineUnlimitedForRuntime(rt: LockDeviceRuntime, id: string): Promise<void>;
11
12
  export interface OnlinePasswordItem {
12
13
  status: "effective" | "synchronizing" | "expired" | "disabled" | "invalid";
@@ -18,6 +18,7 @@ import { ipc, yuChannelSyncSingleSync } from "../../platform";
18
18
  import { sdkLog } from "../../utils/sdk-log";
19
19
  import { ProductCommunicationType, RotateType } from "../../constant";
20
20
  import { isHarmony } from "../../utils";
21
+ import { getError } from "../../utils/errors";
21
22
  export const initState = async (runtime) => {
22
23
  const { devInfo: { dps, devId, yuNetState }, dpSchema, } = runtime.config;
23
24
  const startedAt = Date.now();
@@ -41,7 +42,7 @@ export const initState = async (runtime) => {
41
42
  isSupportVideo,
42
43
  },
43
44
  });
44
- const [, , , advanceAbilities, isActiveThread, rotateInfo, deviceSkill, ipcConfig,] = await Promise.allSettled([
45
+ const [, userInfoResult, , advanceAbilities, isActiveThread, rotateInfo, deviceSkill, ipcConfig,] = await Promise.allSettled([
45
46
  updateOnlineType(runtime),
46
47
  getCurrentUserForRuntime(runtime),
47
48
  fetchDeviceProperties(runtime),
@@ -71,6 +72,43 @@ export const initState = async (runtime) => {
71
72
  },
72
73
  }),
73
74
  ]);
75
+ if (userInfoResult.status === "rejected") {
76
+ throw userInfoResult.reason;
77
+ }
78
+ if (advanceAbilities.status === "fulfilled") {
79
+ const abilities = advanceAbilities.value;
80
+ sdkLog("debug", "initState", "advancedAbilitiesFetched", {
81
+ devId,
82
+ data: {
83
+ yuChannelSupport: abilities.yuChannel.support,
84
+ yuChannelValue: abilities.yuChannel.value,
85
+ },
86
+ });
87
+ if (isSupportVideo &&
88
+ !abilities.videoConfig.isHighResolution &&
89
+ !abilities.videoConfig.isLowResolution) {
90
+ throw getError(1107);
91
+ }
92
+ if (abilities.yuChannel.support) {
93
+ if (abilities.yuChannel.value === 1) {
94
+ sdkLog("debug", "initState", "yuChannelSync", {
95
+ devId,
96
+ data: { reason: "abilityEnabled" },
97
+ });
98
+ yuChannelSyncSingleSync(devId);
99
+ }
100
+ else if (yuNetState === 1) {
101
+ sdkLog("debug", "initState", "yuChannelSync", {
102
+ devId,
103
+ data: { reason: "yuNetState" },
104
+ });
105
+ yuChannelSyncSingleSync(devId);
106
+ }
107
+ }
108
+ }
109
+ else {
110
+ throw getError(1108);
111
+ }
74
112
  if (isSupportVideo) {
75
113
  const isSEI = runtime.config.capabilities?.rotateType === RotateType.SEI;
76
114
  if (rotateInfo.status === "fulfilled") {
@@ -125,32 +163,6 @@ export const initState = async (runtime) => {
125
163
  videoAngle: runtime.config.videoAngle,
126
164
  },
127
165
  });
128
- if (advanceAbilities.status === "fulfilled") {
129
- const abilities = advanceAbilities.value;
130
- sdkLog("debug", "initState", "advancedAbilitiesFetched", {
131
- devId,
132
- data: {
133
- yuChannelSupport: abilities.yuChannel.support,
134
- yuChannelValue: abilities.yuChannel.value,
135
- },
136
- });
137
- if (abilities.yuChannel.support) {
138
- if (abilities.yuChannel.value === 1) {
139
- sdkLog("debug", "initState", "yuChannelSync", {
140
- devId,
141
- data: { reason: "abilityEnabled" },
142
- });
143
- yuChannelSyncSingleSync(devId);
144
- }
145
- else if (yuNetState === 1) {
146
- sdkLog("debug", "initState", "yuChannelSync", {
147
- devId,
148
- data: { reason: "yuNetState" },
149
- });
150
- yuChannelSyncSingleSync(devId);
151
- }
152
- }
153
- }
154
166
  syncRemoteSerectKey(runtime);
155
167
  checkOfflineDpUpdateForRuntime(runtime, {}, true).then(() => {
156
168
  sdkLog("debug", "initState", "offlineDpCheckDone", { devId });
@@ -160,8 +172,10 @@ export const initState = async (runtime) => {
160
172
  });
161
173
  setTimeout(() => {
162
174
  sdkLog("debug", "initState", "scheduledSyncUnlock", { devId });
163
- syncT0(runtime);
164
- autoSyncUnlockMethod(runtime);
175
+ if (getDeviceStatusForRuntime(runtime).type === "online") {
176
+ syncT0(runtime);
177
+ autoSyncUnlockMethod(runtime);
178
+ }
165
179
  }, 2000);
166
180
  setTimeout(() => {
167
181
  sdkLog("debug", "initState", "scheduledSyncTempAndUsers", { devId });
@@ -1,7 +1,7 @@
1
1
  import dpUtils from "@ray-js/tuya-dp-transform";
2
2
  import { createUnlockMethod } from "../../../api/lock";
3
3
  import { parallelOnlyForRuntime } from "../../utils";
4
- import { formatCloudUnlockId, sleep } from "../../../utils";
4
+ import { sleep } from "../../../utils";
5
5
  import { getError } from "../../../utils/errors";
6
6
  import { publishDpsForRuntime } from "../../dp/publish-dps";
7
7
  import emitter from "../../../utils/event";
@@ -207,7 +207,7 @@ const handleAddReport = async (dps) => {
207
207
  const res = await createUnlockMethod({
208
208
  devId: cfg.devInfo.devId,
209
209
  userId: addUnlockMethodData.userId,
210
- unlockId: formatCloudUnlockId(addUnlockMethodData.unlockDpId, result.unlockId),
210
+ unlockId: `${addUnlockMethodData.unlockDpId}-${result.unlockId}`,
211
211
  unlockName: "",
212
212
  unlockAttr: 0,
213
213
  });
@@ -1,7 +1,7 @@
1
1
  import dpUtils from "@ray-js/tuya-dp-transform";
2
2
  import { createUnlockMethod } from "../../../api/lock";
3
3
  import { encrypt } from "../../../platform/device";
4
- import { formatCloudUnlockId, sleep } from "../../../utils";
4
+ import { sleep } from "../../../utils";
5
5
  import { getError, handleCloudError } from "../../../utils/errors";
6
6
  import { publishDpsForRuntime } from "../../dp/publish-dps";
7
7
  import { getUnlockMethodBase } from "./internal/base";
@@ -76,7 +76,7 @@ export async function addPasswordForRuntime(rt, params) {
76
76
  const result = await createUnlockMethod({
77
77
  devId: devId,
78
78
  userId: params.userId,
79
- unlockId: formatCloudUnlockId(dpId, res.unlockId),
79
+ unlockId: `${dpId}-${res.unlockId}`,
80
80
  unlockName: params.name,
81
81
  unlockDetail: aesPwd,
82
82
  ...specialInfo,
@@ -26,7 +26,7 @@ export async function updateUnlockMethodForRuntime(rt, params) {
26
26
  await editUnlockMethod({
27
27
  devId: cfg.devInfo.devId,
28
28
  opModeId: params.id,
29
- unlockName: params.name,
29
+ unlockName: params.name || detail.unlockName,
30
30
  ...specialInfo,
31
31
  });
32
32
  sdkLog("info", "unlockMethod", "updateSuccess", {
@@ -359,6 +359,10 @@ export interface AlbumMessage extends MediaInfo {
359
359
  }
360
360
  export type VRModeType = "original" | "VR" | "horizontal" | "vertical";
361
361
  export interface DeviceAdvancedAbility {
362
+ videoConfig: {
363
+ isLowResolution: boolean;
364
+ isHighResolution: boolean;
365
+ };
362
366
  cloudStorage: {
363
367
  support: boolean;
364
368
  };
@@ -370,6 +374,10 @@ export interface DeviceAdvancedAbility {
370
374
  value: number;
371
375
  }>;
372
376
  defaultMode: VRModeType;
377
+ options: {
378
+ zoomIn?: number;
379
+ radialEmphasis?: number;
380
+ };
373
381
  };
374
382
  ai: {
375
383
  support: boolean;
@@ -173,6 +173,7 @@ export declare const navigateTo: (params: ParamType<typeof ty.navigateTo>) => vo
173
173
  export declare const checkShowMatterMutilpleShare: (deviceId: string) => Promise<unknown>;
174
174
  export declare const getBLEOnlineState: (deviceId: string) => Promise<boolean>;
175
175
  export declare const connectBLEDevice: (deviceId: string) => Promise<void>;
176
+ export declare const disconnectBLEDevice: (deviceId: string) => Promise<void>;
176
177
  export interface BLEFileTransferParams {
177
178
  deviceId: string;
178
179
  fileId: number;
@@ -365,6 +365,15 @@ export const connectBLEDevice = (deviceId) => {
365
365
  });
366
366
  });
367
367
  };
368
+ export const disconnectBLEDevice = (deviceId) => {
369
+ return new Promise((resolve, reject) => {
370
+ ty.device.disconnectBLEDevice({
371
+ deviceId,
372
+ success: () => resolve(),
373
+ fail: reject,
374
+ });
375
+ });
376
+ };
368
377
  export const postBLEFileTransfer = (params) => {
369
378
  return new Promise((resolve, reject) => {
370
379
  const device = ty.device;
@@ -450,10 +459,10 @@ export const offAppShow = (cb) => {
450
459
  ty.offAppShow(cb);
451
460
  };
452
461
  export const onAppHide = (cb) => {
453
- ty.onAppShow(cb);
462
+ ty.onAppHide(cb);
454
463
  };
455
464
  export const offAppHide = (cb) => {
456
- ty.offAppShow(cb);
465
+ ty.offAppHide(cb);
457
466
  };
458
467
  export const trackEvent = (event, data) => {
459
468
  ty.event({
@@ -6,6 +6,7 @@ declare const _default: {
6
6
  isConnecting: (deviceId: string) => Promise<{
7
7
  isConnecting: boolean;
8
8
  }>;
9
+ disConnect: (deviceId: string) => Promise<unknown>;
9
10
  connect: (deviceId: string) => Promise<unknown>;
10
11
  getCurrentSupportedTalkMode: (deviceId: string) => Promise<{
11
12
  talkbackMode: number;
@@ -18,6 +18,11 @@ const connect = (deviceId) => {
18
18
  ty.ipc.connect({ deviceId, success: resolve, fail: reject });
19
19
  });
20
20
  };
21
+ const disConnect = (deviceId) => {
22
+ return new Promise((resolve, reject) => {
23
+ ty.ipc.disConnect({ deviceId, success: resolve, fail: reject });
24
+ });
25
+ };
21
26
  const getCurrentSupportedTalkMode = (deviceId) => {
22
27
  if (ty.ipc.getCurrentSupportedTalkMode) {
23
28
  return new Promise((resolve, reject) => {
@@ -47,6 +52,7 @@ export default {
47
52
  wakeUpDoorBell,
48
53
  isConnected,
49
54
  isConnecting,
55
+ disConnect,
50
56
  connect,
51
57
  getCurrentSupportedTalkMode,
52
58
  getTTTAbilityKeyList,
@@ -106,6 +106,8 @@ const errors = {
106
106
  1104: "Failed to switch cameras",
107
107
  1105: "Camera switching is not supported",
108
108
  1106: "No validity configuration data",
109
+ 1107: "Invalid device, please re-authorize",
110
+ 1108: "Failed to get configuration",
109
111
  };
110
112
  export const getError = (code, ...places) => {
111
113
  if (errors[code]) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ray-js/lock-sdk",
3
- "version": "1.2.1-beta.1",
3
+ "version": "1.2.1-beta.10",
4
4
  "files": [
5
5
  "lib",
6
6
  "LICENSE.md"