@ray-js/lock-sdk 1.1.1 → 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/config/dp-code/index.d.ts +1 -0
- package/lib/config/dp-code/index.js +2 -1
- package/lib/interface.d.ts +7 -0
- package/lib/log.js +19 -2
- package/lib/open.js +12 -1
- package/lib/state.js +15 -6
- package/lib/sync/user.js +3 -0
- package/lib/utils/device.js +12 -0
- 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[];
|
|
@@ -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",
|
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/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/state.js
CHANGED
|
@@ -38,19 +38,21 @@ const updateOnlineType = async () => {
|
|
|
38
38
|
updateDeviceStatus();
|
|
39
39
|
};
|
|
40
40
|
export const getDeviceStatus = () => {
|
|
41
|
-
const { onlineType, devInfo: { isCloudOnline, isOnline, wifiEnableState }, } = config;
|
|
41
|
+
const { onlineType, devInfo: { isCloudOnline, isOnline, wifiEnableState, isMatter }, } = config;
|
|
42
|
+
const supportWifi = hasCapability(ProductCommunicationType.WIFI);
|
|
43
|
+
const supportBle = hasCapability(ProductCommunicationType.BLUETOOTH);
|
|
44
|
+
const supportThread = hasCapability(ProductCommunicationType.THREAD);
|
|
42
45
|
const status = {
|
|
43
46
|
type: isOnline ? "online" : "offline",
|
|
44
47
|
connectEnable: false,
|
|
45
48
|
onlineType: "unknown",
|
|
46
49
|
onlineTypes: [],
|
|
47
50
|
isWifiActive: wifiEnableState !== 1,
|
|
51
|
+
isWifiMatter: !!isMatter && supportWifi,
|
|
48
52
|
};
|
|
49
53
|
const isBleOnline = isOnlineByType(onlineType, 2);
|
|
54
|
+
const isMatterLocal = isOnlineByType(onlineType, 8);
|
|
50
55
|
const isLocalOnline = !isCloudOnline && isOnlineByType(onlineType, 1);
|
|
51
|
-
const supportWifi = hasCapability(ProductCommunicationType.WIFI);
|
|
52
|
-
const supportBle = hasCapability(ProductCommunicationType.BLUETOOTH);
|
|
53
|
-
const supportThread = hasCapability(ProductCommunicationType.THREAD);
|
|
54
56
|
const hasWirelessAwakeDp = hasDp(dpCodes.wirelessAwake);
|
|
55
57
|
const wirelessAwake = getDpValue(dpCodes.wirelessAwake);
|
|
56
58
|
status.connectEnable = isSupportBleControl() && !isOnline;
|
|
@@ -76,9 +78,14 @@ export const getDeviceStatus = () => {
|
|
|
76
78
|
status.onlineTypes.push("cloud");
|
|
77
79
|
}
|
|
78
80
|
}
|
|
79
|
-
|
|
81
|
+
if (isLocalOnline) {
|
|
80
82
|
status.onlineTypes.push("local");
|
|
81
83
|
}
|
|
84
|
+
if (isMatterLocal) {
|
|
85
|
+
if (!status.onlineTypes.includes("local")) {
|
|
86
|
+
status.onlineTypes.push("local");
|
|
87
|
+
}
|
|
88
|
+
}
|
|
82
89
|
if (isBleOnline) {
|
|
83
90
|
status.onlineTypes.push("ble");
|
|
84
91
|
}
|
|
@@ -89,7 +96,9 @@ export const getDeviceStatus = () => {
|
|
|
89
96
|
if (supportThread && supportBle) {
|
|
90
97
|
const isShareThread = isShareThead();
|
|
91
98
|
if (isShareThread && isOnline) {
|
|
92
|
-
status.onlineTypes
|
|
99
|
+
if (!status.onlineTypes.includes("local")) {
|
|
100
|
+
status.onlineTypes = ["local"];
|
|
101
|
+
}
|
|
93
102
|
}
|
|
94
103
|
}
|
|
95
104
|
if (status.onlineTypes.includes("ble")) {
|
package/lib/sync/user.js
CHANGED
package/lib/utils/device.js
CHANGED
|
@@ -42,6 +42,18 @@ export const setDeviceProperty = async (devId, code, value) => {
|
|
|
42
42
|
});
|
|
43
43
|
};
|
|
44
44
|
export const publishDeviceDps = (params) => {
|
|
45
|
+
if (params.pipelines && params.pipelines.length) {
|
|
46
|
+
return new Promise((resolve, reject) => {
|
|
47
|
+
ty.device.publishDpsWithPipeType({
|
|
48
|
+
mode: 2,
|
|
49
|
+
pipelines: [],
|
|
50
|
+
options: {},
|
|
51
|
+
...params,
|
|
52
|
+
success: resolve,
|
|
53
|
+
fail: reject,
|
|
54
|
+
});
|
|
55
|
+
});
|
|
56
|
+
}
|
|
45
57
|
return new Promise((resolve, reject) => {
|
|
46
58
|
ty.device.publishDps({
|
|
47
59
|
mode: 2,
|
package/lib/utils/publishDps.js
CHANGED
|
@@ -5,11 +5,15 @@ import emitter from "./event";
|
|
|
5
5
|
import { DPCHANGE } from "./constant";
|
|
6
6
|
import { getError } from "./errors";
|
|
7
7
|
export const publishDpsOnly = async (dpData) => {
|
|
8
|
-
const { devInfo, idsByCode } = config;
|
|
8
|
+
const { devInfo, idsByCode, deviceStatus } = config;
|
|
9
9
|
const option = {};
|
|
10
10
|
if (config.deviceStatus.type === "offline") {
|
|
11
11
|
throw getError(1001);
|
|
12
12
|
}
|
|
13
|
+
console.log("onlineType", config.onlineType);
|
|
14
|
+
if (deviceStatus.isWifiMatter && deviceStatus.onlineTypes.includes("cloud")) {
|
|
15
|
+
option.pipelines = [1];
|
|
16
|
+
}
|
|
13
17
|
if (isOnlineByType(config.onlineType, 2)) {
|
|
14
18
|
option.pipelines = [3];
|
|
15
19
|
}
|
|
@@ -20,6 +24,7 @@ export const publishDpsOnly = async (dpData) => {
|
|
|
20
24
|
}
|
|
21
25
|
return acc;
|
|
22
26
|
}, {});
|
|
27
|
+
console.log("--------publishDeviceDps----", option, dps);
|
|
23
28
|
if (Object.keys(dps).length > 0) {
|
|
24
29
|
await publishDeviceDps({
|
|
25
30
|
deviceId: devInfo.devId,
|