@ray-js/lock-sdk 1.1.1-beta.9 → 1.1.2-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/log.d.ts +10 -0
- package/lib/api/user.d.ts +0 -20
- package/lib/api/user.js +2 -9
- package/lib/capability.js +1 -1
- package/lib/config/dp-code/index.d.ts +1 -0
- package/lib/config/dp-code/index.js +2 -1
- package/lib/config/dp-map/unlock-method-big.js +1 -1
- package/lib/config/dp-map/unlock-method.d.ts +4 -4
- package/lib/config/dp-map/unlock-method.js +1 -1
- package/lib/index.d.ts +2 -1
- package/lib/index.js +6 -2
- package/lib/interface.d.ts +7 -0
- package/lib/log.js +19 -2
- package/lib/offline-dps.js +4 -12
- package/lib/open/ble-dedicated-dp.d.ts +4 -0
- package/lib/open/ble-dedicated-dp.js +148 -0
- package/lib/open/ble-remote-no-dp-key.d.ts +4 -0
- package/lib/open/ble-remote-no-dp-key.js +69 -0
- package/lib/open/report-status.d.ts +1 -0
- package/lib/open/report-status.js +23 -0
- package/lib/open.js +12 -1
- package/lib/other.js +1 -1
- package/lib/state.js +23 -9
- package/lib/sync/offline-dps.js +1 -6
- package/lib/sync/unlock-method.js +16 -16
- package/lib/sync/user.js +49 -21
- package/lib/temporary.js +14 -32
- package/lib/unlock-method.js +46 -11
- package/lib/user.d.ts +4 -24
- package/lib/user.js +47 -37
- package/lib/utils/device.d.ts +1 -0
- package/lib/utils/device.js +18 -0
- package/lib/utils/errors.d.ts +1 -0
- package/lib/utils/errors.js +36 -0
- package/lib/utils/index.js +1 -2
- package/lib/utils/publishDps.js +6 -1
- package/package.json +1 -1
package/lib/api/log.d.ts
CHANGED
|
@@ -24,6 +24,11 @@ interface LatestLogs {
|
|
|
24
24
|
unionUnlockInfo?: UnionUnlockInfo[];
|
|
25
25
|
unlockNameRosettaKey?: string;
|
|
26
26
|
data: boolean | number | string;
|
|
27
|
+
matterRecordInfo?: {
|
|
28
|
+
matterSn: number;
|
|
29
|
+
matterSource: number;
|
|
30
|
+
matterType: number;
|
|
31
|
+
};
|
|
27
32
|
}[];
|
|
28
33
|
}
|
|
29
34
|
export declare const getLatest2Log: (devId: string) => Promise<LatestLogs>;
|
|
@@ -55,6 +60,11 @@ interface LogInfo {
|
|
|
55
60
|
data?: string;
|
|
56
61
|
unionUnlockInfo?: UnionUnlockInfo[];
|
|
57
62
|
localOperateRecordInfo?: LocalOperateRecordInfo;
|
|
63
|
+
matterRecordInfo?: {
|
|
64
|
+
matterSn: number;
|
|
65
|
+
matterSource: number;
|
|
66
|
+
matterType: number;
|
|
67
|
+
};
|
|
58
68
|
}
|
|
59
69
|
export interface LogsResult {
|
|
60
70
|
datas: LogInfo[];
|
package/lib/api/user.d.ts
CHANGED
|
@@ -82,26 +82,6 @@ export declare const getUserList: (params: getUserListParams) => Promise<{
|
|
|
82
82
|
user: UserListItem[];
|
|
83
83
|
hasNext: boolean;
|
|
84
84
|
}>;
|
|
85
|
-
interface GetUserDetailParams {
|
|
86
|
-
devId: string;
|
|
87
|
-
userId: string;
|
|
88
|
-
}
|
|
89
|
-
interface UserDetail {
|
|
90
|
-
allOpenType: number[];
|
|
91
|
-
avatarUrl: string;
|
|
92
|
-
lockUserId: number;
|
|
93
|
-
nickName: string;
|
|
94
|
-
phase: number;
|
|
95
|
-
productAttribute: number;
|
|
96
|
-
status: number;
|
|
97
|
-
supportOpenType: number[];
|
|
98
|
-
uid: string;
|
|
99
|
-
userContact: string;
|
|
100
|
-
userId: string;
|
|
101
|
-
userTimeSet: string;
|
|
102
|
-
userType: number;
|
|
103
|
-
}
|
|
104
|
-
export declare const getUserDetail: (params: GetUserDetailParams) => Promise<UserDetail>;
|
|
105
85
|
interface GetUserDetailQueryParams {
|
|
106
86
|
devId: string;
|
|
107
87
|
userId: string;
|
package/lib/api/user.js
CHANGED
|
@@ -38,13 +38,6 @@ export const getUserList = (params) => {
|
|
|
38
38
|
data: params,
|
|
39
39
|
});
|
|
40
40
|
};
|
|
41
|
-
export const getUserDetail = (params) => {
|
|
42
|
-
return requestApi({
|
|
43
|
-
api: "m.lock.device.member.detail",
|
|
44
|
-
version: "1.0",
|
|
45
|
-
data: params,
|
|
46
|
-
});
|
|
47
|
-
};
|
|
48
41
|
export const getUserDetailQuery = (params) => {
|
|
49
42
|
return requestApi({
|
|
50
43
|
api: "m.lock.user.detail.query",
|
|
@@ -55,7 +48,7 @@ export const getUserDetailQuery = (params) => {
|
|
|
55
48
|
export const getUsersSyncLockData = (deviceId) => {
|
|
56
49
|
return requestApi({
|
|
57
50
|
api: `${THING}.m.device.lock.sync.batch`,
|
|
58
|
-
version: "
|
|
51
|
+
version: "1.0",
|
|
59
52
|
data: {
|
|
60
53
|
devId: deviceId,
|
|
61
54
|
},
|
|
@@ -64,7 +57,7 @@ export const getUsersSyncLockData = (deviceId) => {
|
|
|
64
57
|
export const removeUser = (devId, userId) => {
|
|
65
58
|
return requestApi({
|
|
66
59
|
api: `${THING}.m.device.member.remove`,
|
|
67
|
-
version: "
|
|
60
|
+
version: "1.0",
|
|
68
61
|
data: {
|
|
69
62
|
devId,
|
|
70
63
|
userId,
|
package/lib/capability.js
CHANGED
|
@@ -8,7 +8,7 @@ export const isActiveThread = async () => {
|
|
|
8
8
|
const hasThread = hasCapability(ProductCommunicationType.THREAD);
|
|
9
9
|
if (hasThread) {
|
|
10
10
|
const deviceStatus = getDeviceStatus();
|
|
11
|
-
if (deviceStatus.
|
|
11
|
+
if (deviceStatus.onlineTypes.includes("cloud") ||
|
|
12
12
|
config.communication.length === 1) {
|
|
13
13
|
return true;
|
|
14
14
|
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
const dpCodes = {
|
|
2
|
-
lockMotorState:
|
|
2
|
+
lockMotorState: "lock_motor_state",
|
|
3
3
|
remoteNoDpKey: "remote_no_dp_key",
|
|
4
4
|
remoteNoPdSetkey: "remote_no_pd_setkey",
|
|
5
5
|
synchMethodW: "synch_method_w",
|
|
@@ -58,6 +58,7 @@ const dpCodes = {
|
|
|
58
58
|
doNotDisturb: "do_not_disturb",
|
|
59
59
|
muteModePeriod: "mute_mode_period",
|
|
60
60
|
matterLanUnlock: "matter_lan_unlock",
|
|
61
|
+
unlockMatterKw: "unlock_matter_kw",
|
|
61
62
|
doorlockStatus: "doorlock_status",
|
|
62
63
|
unlockInside: "unlock_inside",
|
|
63
64
|
doorOpened: "door_opened",
|
|
@@ -161,7 +161,7 @@ declare const remove: readonly [{
|
|
|
161
161
|
}, {
|
|
162
162
|
readonly name: "unlockId";
|
|
163
163
|
}, {
|
|
164
|
-
readonly name: "
|
|
164
|
+
readonly name: "operation";
|
|
165
165
|
}];
|
|
166
166
|
declare const reportRemove: ({
|
|
167
167
|
readonly name: "type";
|
|
@@ -176,7 +176,7 @@ declare const reportRemove: ({
|
|
|
176
176
|
} | {
|
|
177
177
|
readonly name: "unlockId";
|
|
178
178
|
} | {
|
|
179
|
-
readonly name: "
|
|
179
|
+
readonly name: "operation";
|
|
180
180
|
} | {
|
|
181
181
|
name: string;
|
|
182
182
|
})[];
|
|
@@ -649,7 +649,7 @@ declare const _default: {
|
|
|
649
649
|
}, {
|
|
650
650
|
readonly name: "unlockId";
|
|
651
651
|
}, {
|
|
652
|
-
readonly name: "
|
|
652
|
+
readonly name: "operation";
|
|
653
653
|
}];
|
|
654
654
|
reportRemove: ({
|
|
655
655
|
readonly name: "type";
|
|
@@ -664,7 +664,7 @@ declare const _default: {
|
|
|
664
664
|
} | {
|
|
665
665
|
readonly name: "unlockId";
|
|
666
666
|
} | {
|
|
667
|
-
readonly name: "
|
|
667
|
+
readonly name: "operation";
|
|
668
668
|
} | {
|
|
669
669
|
name: string;
|
|
670
670
|
})[];
|
package/lib/index.d.ts
CHANGED
|
@@ -2,6 +2,7 @@ import { hasCapability, hasDp, updateConfig } from "./config";
|
|
|
2
2
|
import { LockSDKOption } from "./interface";
|
|
3
3
|
import { getCurrentUser, getDeviceStatus, onDeviceStatusChange, offDeviceStatusChange, getCurrentUserSync, getMediaRotate } from "./state";
|
|
4
4
|
import { syncUnlockMethod } from "./sync/unlock-method";
|
|
5
|
+
import syncDeleteUsers from "./sync/user";
|
|
5
6
|
import { publishDps } from "./utils/publishDps";
|
|
6
7
|
import { publishOfflineDps, getOfflineDps, isOfflineDpSyncing, onOfflineDpsUpdate, offOfflineDpsUpdate, getOfflineDpCache } from "./offline-dps";
|
|
7
8
|
export * from "./user";
|
|
@@ -19,4 +20,4 @@ export * from "./linkage";
|
|
|
19
20
|
export * from "./capability";
|
|
20
21
|
export declare const init: (options?: LockSDKOption) => Promise<void>;
|
|
21
22
|
export declare const destroy: () => void;
|
|
22
|
-
export { getCurrentUser, getMediaRotate, getCurrentUserSync, syncUnlockMethod, getDeviceStatus, onDeviceStatusChange, offDeviceStatusChange, updateConfig, hasCapability, hasDp, publishDps, publishOfflineDps, getOfflineDps, isOfflineDpSyncing, onOfflineDpsUpdate, offOfflineDpsUpdate, getOfflineDpCache, };
|
|
23
|
+
export { getCurrentUser, getMediaRotate, getCurrentUserSync, syncUnlockMethod, syncDeleteUsers, getDeviceStatus, onDeviceStatusChange, offDeviceStatusChange, updateConfig, hasCapability, hasDp, publishDps, publishOfflineDps, getOfflineDps, isOfflineDpSyncing, onOfflineDpsUpdate, offOfflineDpsUpdate, getOfflineDpCache, };
|
package/lib/index.js
CHANGED
|
@@ -2,8 +2,9 @@ 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
|
-
import { getDeviceInfo, getLaunchOptionsSync } from "./utils/device";
|
|
5
|
+
import { getDeviceInfo, getLaunchOptionsSync, trackEvent, } from "./utils/device";
|
|
6
6
|
import { syncUnlockMethod } from "./sync/unlock-method";
|
|
7
|
+
import syncDeleteUsers from "./sync/user";
|
|
7
8
|
import { publishDps } from "./utils/publishDps";
|
|
8
9
|
import { publishOfflineDps, getOfflineDps, isOfflineDpSyncing, onOfflineDpsUpdate, offOfflineDpsUpdate, getOfflineDpCache, } from "./offline-dps";
|
|
9
10
|
export * from "./user";
|
|
@@ -63,10 +64,13 @@ export const init = async (options) => {
|
|
|
63
64
|
config.preFetch = options?.preFetch ?? false;
|
|
64
65
|
config.communication = getCapabilities(devInfo.capability).map((item) => item.id);
|
|
65
66
|
addEvents();
|
|
67
|
+
trackEvent("t$y_UztB3Lj9Qns375R0r7dA0L5Kr2VytH3J".replace("$", ""), {
|
|
68
|
+
pid: devInfo.productId,
|
|
69
|
+
});
|
|
66
70
|
await initState();
|
|
67
71
|
};
|
|
68
72
|
export const destroy = () => {
|
|
69
73
|
clearState();
|
|
70
74
|
removeEvents();
|
|
71
75
|
};
|
|
72
|
-
export { getCurrentUser, getMediaRotate, getCurrentUserSync, syncUnlockMethod, getDeviceStatus, onDeviceStatusChange, offDeviceStatusChange, updateConfig, hasCapability, hasDp, publishDps, publishOfflineDps, getOfflineDps, isOfflineDpSyncing, onOfflineDpsUpdate, offOfflineDpsUpdate, getOfflineDpCache, };
|
|
76
|
+
export { getCurrentUser, getMediaRotate, getCurrentUserSync, syncUnlockMethod, syncDeleteUsers, getDeviceStatus, onDeviceStatusChange, offDeviceStatusChange, updateConfig, hasCapability, hasDp, publishDps, publishOfflineDps, getOfflineDps, isOfflineDpSyncing, onOfflineDpsUpdate, offOfflineDpsUpdate, getOfflineDpCache, };
|
package/lib/interface.d.ts
CHANGED
|
@@ -43,6 +43,7 @@ export interface DeviceInfo {
|
|
|
43
43
|
activeTime: number;
|
|
44
44
|
dpsTime: Record<string, string>;
|
|
45
45
|
parentId?: string;
|
|
46
|
+
isMatter?: boolean;
|
|
46
47
|
}
|
|
47
48
|
export interface DpSchema {
|
|
48
49
|
type: "raw" | "obj";
|
|
@@ -194,6 +195,7 @@ export interface DeviceStatus {
|
|
|
194
195
|
end: number;
|
|
195
196
|
};
|
|
196
197
|
isWifiActive: boolean;
|
|
198
|
+
isWifiMatter: boolean;
|
|
197
199
|
}
|
|
198
200
|
export interface UnionUnlockInfo {
|
|
199
201
|
userId: string;
|
|
@@ -265,6 +267,11 @@ export interface LogData {
|
|
|
265
267
|
localRecord?: LocalOperateData;
|
|
266
268
|
isHijack?: boolean;
|
|
267
269
|
unlockMethod?: UnlockMethodType;
|
|
270
|
+
matterRecord?: {
|
|
271
|
+
sn: number;
|
|
272
|
+
source: number;
|
|
273
|
+
type: number;
|
|
274
|
+
};
|
|
268
275
|
}
|
|
269
276
|
export type TemporaryPasswordType = "custom" | "once" | "limit" | "clear" | "clearOne";
|
|
270
277
|
export interface TempPasswordResult {
|
package/lib/log.js
CHANGED
|
@@ -42,7 +42,7 @@ export const getLatestLogs = async () => {
|
|
|
42
42
|
unlockName = item.userName;
|
|
43
43
|
userName = "";
|
|
44
44
|
}
|
|
45
|
-
|
|
45
|
+
const log = {
|
|
46
46
|
type,
|
|
47
47
|
logId: item.logId,
|
|
48
48
|
dpId: item.dpId,
|
|
@@ -66,6 +66,14 @@ export const getLatestLogs = async () => {
|
|
|
66
66
|
currentUser: !!item.currentUser,
|
|
67
67
|
bindable: item.memberBindableFlag,
|
|
68
68
|
};
|
|
69
|
+
if (item.matterRecordInfo) {
|
|
70
|
+
log.matterRecord = {
|
|
71
|
+
sn: item.matterRecordInfo.matterSn,
|
|
72
|
+
type: item.matterRecordInfo.matterType,
|
|
73
|
+
source: item.matterRecordInfo.matterSource,
|
|
74
|
+
};
|
|
75
|
+
}
|
|
76
|
+
return log;
|
|
69
77
|
});
|
|
70
78
|
return {
|
|
71
79
|
data: list,
|
|
@@ -106,6 +114,7 @@ export const openDps = [
|
|
|
106
114
|
dpCodes.unlockInside,
|
|
107
115
|
dpCodes.doorOpened,
|
|
108
116
|
dpCodes.unlockApp,
|
|
117
|
+
dpCodes.unlockMatterKw,
|
|
109
118
|
];
|
|
110
119
|
const closeTypes = [
|
|
111
120
|
"UNDEFINED",
|
|
@@ -154,7 +163,7 @@ export const getLogs = async (params) => {
|
|
|
154
163
|
unlockName = record.userName;
|
|
155
164
|
userName = "";
|
|
156
165
|
}
|
|
157
|
-
|
|
166
|
+
const log = {
|
|
158
167
|
type,
|
|
159
168
|
logId: record.historyId.toString(),
|
|
160
169
|
userId: record.userId,
|
|
@@ -178,6 +187,14 @@ export const getLogs = async (params) => {
|
|
|
178
187
|
unlockMethod: type === "unlock_record" ? unlockDp2Type[dpCode] : undefined,
|
|
179
188
|
localRecord: handleLocalOperation(record.localOperateRecordInfo, dpValue),
|
|
180
189
|
};
|
|
190
|
+
if (record.matterRecordInfo) {
|
|
191
|
+
log.matterRecord = {
|
|
192
|
+
sn: record.matterRecordInfo.matterSn,
|
|
193
|
+
type: record.matterRecordInfo.matterType,
|
|
194
|
+
source: record.matterRecordInfo.matterSource,
|
|
195
|
+
};
|
|
196
|
+
}
|
|
197
|
+
return log;
|
|
181
198
|
});
|
|
182
199
|
return {
|
|
183
200
|
list: result,
|
package/lib/offline-dps.js
CHANGED
|
@@ -29,14 +29,14 @@ export const checkOfflineDpUpdate = async (dps, isForce) => {
|
|
|
29
29
|
if (!config.supportOfflineDps) {
|
|
30
30
|
return;
|
|
31
31
|
}
|
|
32
|
-
const hasOne = Object.keys(dps).some((code) => cache[code]?.pushStatus === false);
|
|
32
|
+
const hasOne = Object.keys(dps).some((code) => cache?.[code]?.pushStatus === false);
|
|
33
33
|
if (hasOne || isForce) {
|
|
34
34
|
const res = await getOfflineDps(true);
|
|
35
35
|
emitter.emit(OFFLINE_DPS_UPDATE, res);
|
|
36
36
|
}
|
|
37
37
|
};
|
|
38
38
|
export const getOfflineDpCache = (code) => {
|
|
39
|
-
return cache[code];
|
|
39
|
+
return cache?.[code];
|
|
40
40
|
};
|
|
41
41
|
export const publishOfflineDps = async (dps) => {
|
|
42
42
|
const { devInfo, dpSchema } = config;
|
|
@@ -52,20 +52,12 @@ export const publishOfflineDps = async (dps) => {
|
|
|
52
52
|
return acc;
|
|
53
53
|
}, {});
|
|
54
54
|
await publishOfflineDpData(devInfo.devId, dpData);
|
|
55
|
-
|
|
56
|
-
await checkOfflineDpUpdate({}, true);
|
|
57
|
-
}
|
|
58
|
-
catch {
|
|
59
|
-
}
|
|
55
|
+
checkOfflineDpUpdate({}, true);
|
|
60
56
|
};
|
|
61
57
|
export const clearOfflineDps = async () => {
|
|
62
58
|
const { devInfo } = config;
|
|
63
59
|
await clearOfflineDpData(devInfo.devId);
|
|
64
|
-
|
|
65
|
-
await checkOfflineDpUpdate({}, true);
|
|
66
|
-
}
|
|
67
|
-
catch {
|
|
68
|
-
}
|
|
60
|
+
checkOfflineDpUpdate({}, true);
|
|
69
61
|
};
|
|
70
62
|
const OFFLINE_DPS_UPDATE = "offline_dps_update";
|
|
71
63
|
export const onOfflineDpsUpdate = (callback) => {
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
export declare const isDedicatedBleHexSuccess: (raw: string) => boolean;
|
|
2
|
+
export declare const resolveDedicatedBleCommandDp: () => string | null;
|
|
3
|
+
export declare const executeDedicatedBleManualLock: (timeout: number) => Promise<void>;
|
|
4
|
+
export declare const executeDedicatedBleRawAction: (isOpen: boolean, timeout: number) => Promise<void>;
|
|
@@ -0,0 +1,148 @@
|
|
|
1
|
+
import dpUtils from "@ray-js/tuya-dp-transform";
|
|
2
|
+
import { getDoorKey } from "../api/lock";
|
|
3
|
+
import config, { hasDp } from "../config";
|
|
4
|
+
import dpCodes from "../config/dp-code";
|
|
5
|
+
import { open as openMap, reportOpen as reportOpenMap, } from "../config/dp-map/open";
|
|
6
|
+
import syncRemoteSerectKey from "../sync/remote-serect-key";
|
|
7
|
+
import { stringToBytes } from "../utils/byte";
|
|
8
|
+
import { decrypt } from "../utils/device";
|
|
9
|
+
import { getError } from "../utils/errors";
|
|
10
|
+
import { publishDps } from "../utils/publishDps";
|
|
11
|
+
import { getOpenDoorMemberId } from "./ble-remote-no-dp-key";
|
|
12
|
+
import { mapRemoteOpenReportStatus } from "./report-status";
|
|
13
|
+
const normalizeHex = (raw) => raw.replace(/\s/g, "").toLowerCase();
|
|
14
|
+
export const isDedicatedBleHexSuccess = (raw) => {
|
|
15
|
+
const n = normalizeHex(raw);
|
|
16
|
+
if (n.length < 2) {
|
|
17
|
+
return false;
|
|
18
|
+
}
|
|
19
|
+
return n.startsWith("00") || n.endsWith("00");
|
|
20
|
+
};
|
|
21
|
+
const parseDedicatedBleHexStatus = (raw) => {
|
|
22
|
+
const n = normalizeHex(raw);
|
|
23
|
+
if (n.length < 2) {
|
|
24
|
+
return false;
|
|
25
|
+
}
|
|
26
|
+
if (isDedicatedBleHexSuccess(raw)) {
|
|
27
|
+
return { status: 0 };
|
|
28
|
+
}
|
|
29
|
+
if (n.includes("06")) {
|
|
30
|
+
return { status: 0x06 };
|
|
31
|
+
}
|
|
32
|
+
return { status: 0x01 };
|
|
33
|
+
};
|
|
34
|
+
const tryParseStandardUnlockReport = (raw, memberId) => {
|
|
35
|
+
try {
|
|
36
|
+
const result = dpUtils.parse(raw, reportOpenMap);
|
|
37
|
+
if (result.memberId !== memberId) {
|
|
38
|
+
return false;
|
|
39
|
+
}
|
|
40
|
+
if (hasDp(dpCodes.lockMotorState) && result.status === 0) {
|
|
41
|
+
return false;
|
|
42
|
+
}
|
|
43
|
+
return result;
|
|
44
|
+
}
|
|
45
|
+
catch {
|
|
46
|
+
return false;
|
|
47
|
+
}
|
|
48
|
+
};
|
|
49
|
+
export const resolveDedicatedBleCommandDp = () => {
|
|
50
|
+
if (hasDp(dpCodes.bleUnlockCheck)) {
|
|
51
|
+
return dpCodes.bleUnlockCheck;
|
|
52
|
+
}
|
|
53
|
+
if (hasDp(dpCodes.bluetoothUnlock)) {
|
|
54
|
+
return dpCodes.bluetoothUnlock;
|
|
55
|
+
}
|
|
56
|
+
if (hasDp(dpCodes.unlockBle)) {
|
|
57
|
+
return dpCodes.unlockBle;
|
|
58
|
+
}
|
|
59
|
+
return null;
|
|
60
|
+
};
|
|
61
|
+
const createDedicatedBleCheckReport = (commandDp, memberId) => {
|
|
62
|
+
return (dpData) => {
|
|
63
|
+
if (hasDp(dpCodes.lockMotorState)) {
|
|
64
|
+
if (typeof dpData[dpCodes.lockMotorState] !== "undefined") {
|
|
65
|
+
return { status: 0 };
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
if (typeof dpData[commandDp] !== "undefined") {
|
|
69
|
+
const raw = dpData[commandDp];
|
|
70
|
+
const standard = tryParseStandardUnlockReport(raw, memberId);
|
|
71
|
+
if (standard) {
|
|
72
|
+
return standard;
|
|
73
|
+
}
|
|
74
|
+
const hexStatus = parseDedicatedBleHexStatus(raw);
|
|
75
|
+
if (hexStatus !== false) {
|
|
76
|
+
return hexStatus;
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
if (typeof dpData[dpCodes.remoteNoDpKey] !== "undefined") {
|
|
80
|
+
const result = dpUtils.parse(dpData[dpCodes.remoteNoDpKey], reportOpenMap);
|
|
81
|
+
if (result.memberId === memberId) {
|
|
82
|
+
if (hasDp(dpCodes.lockMotorState) && result.status === 0) {
|
|
83
|
+
return false;
|
|
84
|
+
}
|
|
85
|
+
return result;
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
return false;
|
|
89
|
+
};
|
|
90
|
+
};
|
|
91
|
+
export const executeDedicatedBleManualLock = async (timeout) => {
|
|
92
|
+
if (!hasDp(dpCodes.manualLock)) {
|
|
93
|
+
throw getError(1014);
|
|
94
|
+
}
|
|
95
|
+
await publishDps({
|
|
96
|
+
[dpCodes.manualLock]: true,
|
|
97
|
+
}, {
|
|
98
|
+
timeout,
|
|
99
|
+
checkReport: (dpData) => {
|
|
100
|
+
if (hasDp(dpCodes.lockMotorState)) {
|
|
101
|
+
if (typeof dpData[dpCodes.lockMotorState] !== "undefined") {
|
|
102
|
+
return { status: 0 };
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
if (typeof dpData[dpCodes.manualLock] !== "undefined") {
|
|
106
|
+
return { status: 0 };
|
|
107
|
+
}
|
|
108
|
+
return false;
|
|
109
|
+
},
|
|
110
|
+
});
|
|
111
|
+
};
|
|
112
|
+
export const executeDedicatedBleRawAction = async (isOpen, timeout) => {
|
|
113
|
+
if (!isOpen && hasDp(dpCodes.manualLock)) {
|
|
114
|
+
await executeDedicatedBleManualLock(timeout);
|
|
115
|
+
return;
|
|
116
|
+
}
|
|
117
|
+
const commandDp = resolveDedicatedBleCommandDp();
|
|
118
|
+
if (!commandDp) {
|
|
119
|
+
throw getError(1014);
|
|
120
|
+
}
|
|
121
|
+
await syncRemoteSerectKey();
|
|
122
|
+
let pw = "";
|
|
123
|
+
try {
|
|
124
|
+
const { password } = await getDoorKey(config.devInfo.devId);
|
|
125
|
+
pw = await decrypt(config.devInfo.devId, password);
|
|
126
|
+
}
|
|
127
|
+
catch {
|
|
128
|
+
await syncRemoteSerectKey(true);
|
|
129
|
+
const { password } = await getDoorKey(config.devInfo.devId);
|
|
130
|
+
pw = await decrypt(config.devInfo.devId, password);
|
|
131
|
+
}
|
|
132
|
+
const memberId = await getOpenDoorMemberId();
|
|
133
|
+
const payload = dpUtils.format({
|
|
134
|
+
status: Number(isOpen),
|
|
135
|
+
memberId,
|
|
136
|
+
key: stringToBytes(pw),
|
|
137
|
+
type: 3,
|
|
138
|
+
}, openMap);
|
|
139
|
+
const response = (await publishDps({
|
|
140
|
+
[commandDp]: payload,
|
|
141
|
+
}, {
|
|
142
|
+
timeout,
|
|
143
|
+
checkReport: createDedicatedBleCheckReport(commandDp, memberId),
|
|
144
|
+
}));
|
|
145
|
+
if (response.status !== 0) {
|
|
146
|
+
throw mapRemoteOpenReportStatus(response.status);
|
|
147
|
+
}
|
|
148
|
+
};
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import { DpValue } from "../interface";
|
|
2
|
+
export declare const createRemoteNoDpKeyBleCheckReport: (memberId: number) => (dpData: Record<string, DpValue>) => any;
|
|
3
|
+
export declare const executeBleRemoteNoDpKeyAction: (isOpen: boolean, timeout: number, memberId: number) => Promise<void>;
|
|
4
|
+
export declare const getOpenDoorMemberId: () => Promise<number>;
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
import dpUtils from "@ray-js/tuya-dp-transform";
|
|
2
|
+
import { getDoorKey } from "../api/lock";
|
|
3
|
+
import config, { hasDp } from "../config";
|
|
4
|
+
import dpCodes from "../config/dp-code";
|
|
5
|
+
import { open as openMap, reportOpen as reportOpenMap, } from "../config/dp-map/open";
|
|
6
|
+
import { getCurrentUser } from "../state";
|
|
7
|
+
import syncRemoteSerectKey from "../sync/remote-serect-key";
|
|
8
|
+
import { stringToBytes } from "../utils/byte";
|
|
9
|
+
import { decrypt } from "../utils/device";
|
|
10
|
+
import { publishDps } from "../utils/publishDps";
|
|
11
|
+
import { mapRemoteOpenReportStatus } from "./report-status";
|
|
12
|
+
export const createRemoteNoDpKeyBleCheckReport = (memberId) => {
|
|
13
|
+
return (dpData) => {
|
|
14
|
+
if (hasDp(dpCodes.lockMotorState)) {
|
|
15
|
+
if (typeof dpData[dpCodes.lockMotorState] !== "undefined") {
|
|
16
|
+
return {
|
|
17
|
+
status: 0,
|
|
18
|
+
};
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
if (typeof dpData[dpCodes.remoteNoDpKey] !== "undefined") {
|
|
22
|
+
const result = dpUtils.parse(dpData[dpCodes.remoteNoDpKey], reportOpenMap);
|
|
23
|
+
if (result.memberId === memberId) {
|
|
24
|
+
if (hasDp(dpCodes.lockMotorState) && result.status === 0) {
|
|
25
|
+
return false;
|
|
26
|
+
}
|
|
27
|
+
return result;
|
|
28
|
+
}
|
|
29
|
+
else {
|
|
30
|
+
console.warn("An incorrect member id was returned");
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
return false;
|
|
34
|
+
};
|
|
35
|
+
};
|
|
36
|
+
export const executeBleRemoteNoDpKeyAction = async (isOpen, timeout, memberId) => {
|
|
37
|
+
await syncRemoteSerectKey();
|
|
38
|
+
let pw = "";
|
|
39
|
+
try {
|
|
40
|
+
const { password } = await getDoorKey(config.devInfo.devId);
|
|
41
|
+
pw = await decrypt(config.devInfo.devId, password);
|
|
42
|
+
}
|
|
43
|
+
catch {
|
|
44
|
+
await syncRemoteSerectKey(true);
|
|
45
|
+
const { password } = await getDoorKey(config.devInfo.devId);
|
|
46
|
+
pw = await decrypt(config.devInfo.devId, password);
|
|
47
|
+
}
|
|
48
|
+
const response = (await publishDps({
|
|
49
|
+
[dpCodes.remoteNoDpKey]: dpUtils.format({
|
|
50
|
+
status: Number(isOpen),
|
|
51
|
+
memberId,
|
|
52
|
+
key: stringToBytes(pw),
|
|
53
|
+
type: 3,
|
|
54
|
+
}, openMap),
|
|
55
|
+
}, {
|
|
56
|
+
timeout,
|
|
57
|
+
checkReport: createRemoteNoDpKeyBleCheckReport(memberId),
|
|
58
|
+
}));
|
|
59
|
+
if (response.status !== 0) {
|
|
60
|
+
throw mapRemoteOpenReportStatus(response.status);
|
|
61
|
+
}
|
|
62
|
+
};
|
|
63
|
+
export const getOpenDoorMemberId = async () => {
|
|
64
|
+
const currentUser = await getCurrentUser();
|
|
65
|
+
if (currentUser.lockUserId !== 0) {
|
|
66
|
+
return Number(currentUser.lockUserId);
|
|
67
|
+
}
|
|
68
|
+
return Number(currentUser.userId);
|
|
69
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const mapRemoteOpenReportStatus: (status: number) => import("..").ErrorData;
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { getError } from "../utils/errors";
|
|
2
|
+
export const mapRemoteOpenReportStatus = (status) => {
|
|
3
|
+
let error = getError(1004);
|
|
4
|
+
switch (status) {
|
|
5
|
+
case 0x02:
|
|
6
|
+
error = getError(1005);
|
|
7
|
+
break;
|
|
8
|
+
case 0x03:
|
|
9
|
+
error = getError(1006);
|
|
10
|
+
break;
|
|
11
|
+
case 0x04:
|
|
12
|
+
error = getError(1007);
|
|
13
|
+
break;
|
|
14
|
+
case 0x05:
|
|
15
|
+
error = getError(1008);
|
|
16
|
+
break;
|
|
17
|
+
case 0x06:
|
|
18
|
+
error = getError(1070);
|
|
19
|
+
break;
|
|
20
|
+
default:
|
|
21
|
+
}
|
|
22
|
+
return error;
|
|
23
|
+
};
|
package/lib/open.js
CHANGED
|
@@ -48,6 +48,9 @@ export const checkRemoteEnabled = parallelMerge(async () => {
|
|
|
48
48
|
if (isThreadLocalOnline || deviceStatus.onlineTypes.includes("ble")) {
|
|
49
49
|
return;
|
|
50
50
|
}
|
|
51
|
+
if (deviceStatus.isWifiMatter && isLocalOnline) {
|
|
52
|
+
return;
|
|
53
|
+
}
|
|
51
54
|
if (isLocalOnline) {
|
|
52
55
|
throw getError(1064);
|
|
53
56
|
}
|
|
@@ -94,9 +97,17 @@ const _doAction = async (isOpen, timeout) => {
|
|
|
94
97
|
}
|
|
95
98
|
return false;
|
|
96
99
|
};
|
|
97
|
-
|
|
100
|
+
console.log("-------", deviceStatus.isWifiMatter, deviceStatus.onlineTypes);
|
|
101
|
+
if ((hasThread || deviceStatus.isWifiMatter) &&
|
|
102
|
+
deviceStatus.onlineTypes.includes("local") &&
|
|
103
|
+
deviceStatus.onlineTypes.length === 1) {
|
|
98
104
|
await publishDps({ [dpCodes.matterLanUnlock]: isOpen }, {
|
|
99
105
|
checkReport: (dps) => {
|
|
106
|
+
if (hasDp(dpCodes.lockMotorState)) {
|
|
107
|
+
if (typeof dps[dpCodes.lockMotorState] !== "undefined") {
|
|
108
|
+
return true;
|
|
109
|
+
}
|
|
110
|
+
}
|
|
100
111
|
return typeof dps[dpCodes.matterLanUnlock] !== "undefined";
|
|
101
112
|
},
|
|
102
113
|
});
|
package/lib/other.js
CHANGED
|
@@ -260,7 +260,7 @@ export const connectDevice = async () => {
|
|
|
260
260
|
}
|
|
261
261
|
}
|
|
262
262
|
if (isSupportBleControl()) {
|
|
263
|
-
if (deviceStatus.type === "online" && deviceStatus.
|
|
263
|
+
if (deviceStatus.type === "online" && deviceStatus.onlineTypes.includes("ble")) {
|
|
264
264
|
return true;
|
|
265
265
|
}
|
|
266
266
|
return await connectBle();
|