@ray-js/robot-data-stream 0.0.13-beta-7 → 0.0.13-beta-8
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 +2 -12
- package/lib/api/index.js +1 -172
- package/lib/api/p2pApi.d.ts +8 -27
- package/lib/api/p2pApi.js +271 -169
- package/lib/api/sweeperP2p.d.ts +54 -21
- package/lib/api/sweeperP2p.js +324 -245
- package/lib/constant.d.ts +0 -52
- package/lib/constant.js +0 -54
- package/lib/index.d.ts +11 -1
- package/lib/index.js +166 -2
- package/lib/mqtt/createCommonOptions.d.ts +15 -56
- package/lib/mqtt/createCommonOptions.js +8 -44
- package/lib/mqtt/mqttProvider.d.ts +15 -23
- package/lib/mqtt/mqttProvider.js +26 -63
- package/lib/mqtt/myError.d.ts +4 -0
- package/lib/mqtt/myError.js +6 -0
- package/lib/mqtt/promise.js +3 -8
- package/lib/mqtt/type/index.d.ts +0 -9
- package/lib/mqtt/type/index.js +0 -8
- package/lib/mqtt/type/requestType.d.ts +0 -3
- package/lib/mqtt/type/requestType.js +0 -4
- package/lib/mqtt/useDevInfo.d.ts +7 -2
- package/lib/mqtt/useDevInfo.js +9 -25
- package/lib/mqtt/useHistoryMap.d.ts +21 -13
- package/lib/mqtt/useHistoryMap.js +32 -82
- package/lib/mqtt/usePartDivision.d.ts +7 -5
- package/lib/mqtt/usePartDivision.js +16 -41
- package/lib/mqtt/usePartMerge.d.ts +7 -5
- package/lib/mqtt/usePartMerge.js +18 -36
- package/lib/mqtt/usePassword.js +28 -59
- package/lib/mqtt/useQuiteHours.d.ts +24 -9
- package/lib/mqtt/useQuiteHours.js +52 -95
- package/lib/mqtt/useResetMap.d.ts +7 -10
- package/lib/mqtt/useResetMap.js +11 -40
- package/lib/mqtt/useRoomProperty.js +16 -23
- package/lib/mqtt/useSchedule.d.ts +4 -17
- package/lib/mqtt/useSchedule.js +49 -101
- package/lib/mqtt/useSelectRoomClean.d.ts +16 -20
- package/lib/mqtt/useSelectRoomClean.js +49 -145
- package/lib/mqtt/useSpotClean.d.ts +3 -3
- package/lib/mqtt/useSpotClean.js +51 -71
- package/lib/mqtt/useVirtualArea.d.ts +9 -6
- package/lib/mqtt/useVirtualArea.js +42 -112
- package/lib/mqtt/useVirtualWall.d.ts +10 -13
- package/lib/mqtt/useVirtualWall.js +34 -97
- package/lib/mqtt/useVoice.d.ts +6 -3
- package/lib/mqtt/useVoice.js +33 -73
- package/lib/mqtt/useWifiMap.js +18 -34
- package/lib/mqtt/useZoneClean.d.ts +13 -13
- package/lib/mqtt/useZoneClean.js +76 -149
- package/lib/utils/index.d.ts +1 -20
- package/lib/utils/index.js +0 -19
- package/package.json +1 -1
- package/lib/ttt/index.d.ts +0 -153
- package/lib/ttt/index.js +0 -458
package/lib/mqtt/type/index.js
CHANGED
|
@@ -1,14 +1,6 @@
|
|
|
1
1
|
export * from './requestType';
|
|
2
2
|
// 设备接口响应的统一标准结构
|
|
3
3
|
|
|
4
|
-
/**
|
|
5
|
-
* MQTT 协议号枚举
|
|
6
|
-
*/
|
|
7
|
-
export let ProtocolEnum = /*#__PURE__*/function (ProtocolEnum) {
|
|
8
|
-
ProtocolEnum[ProtocolEnum["appToRobot"] = 64] = "appToRobot";
|
|
9
|
-
ProtocolEnum[ProtocolEnum["robotToApp"] = 65] = "robotToApp";
|
|
10
|
-
return ProtocolEnum;
|
|
11
|
-
}({});
|
|
12
4
|
export let PasswordEnum = /*#__PURE__*/function (PasswordEnum) {
|
|
13
5
|
PasswordEnum["query"] = "passwordQry";
|
|
14
6
|
PasswordEnum["set"] = "passwordSet";
|
|
@@ -104,8 +104,4 @@ export let UseMapEnum = /*#__PURE__*/function (UseMapEnum) {
|
|
|
104
104
|
UseMapEnum["query"] = "useMapRst";
|
|
105
105
|
UseMapEnum["set"] = "useMapSet";
|
|
106
106
|
return UseMapEnum;
|
|
107
|
-
}({});
|
|
108
|
-
export let DevInfoEnum = /*#__PURE__*/function (DevInfoEnum) {
|
|
109
|
-
DevInfoEnum["query"] = "devInfoQry";
|
|
110
|
-
return DevInfoEnum;
|
|
111
107
|
}({});
|
package/lib/mqtt/useDevInfo.d.ts
CHANGED
|
@@ -1,7 +1,12 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
interface DevInfoResponse {
|
|
2
|
+
reqType?: string;
|
|
3
|
+
version?: string;
|
|
3
4
|
info: string;
|
|
5
|
+
success?: boolean;
|
|
6
|
+
errCode?: number;
|
|
7
|
+
taskId?: string;
|
|
4
8
|
}
|
|
5
9
|
export declare const useDevInfo: (devId: string) => {
|
|
6
10
|
requestDevInfo: () => Promise<DevInfoResponse>;
|
|
7
11
|
};
|
|
12
|
+
export {};
|
package/lib/mqtt/useDevInfo.js
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
|
-
import { hexToUriDecodedString } from '@ray-js/robot-protocol';
|
|
2
1
|
import { useContext } from 'react';
|
|
3
2
|
import { createSetCommonParams } from './createCommonOptions';
|
|
4
3
|
import { SingletonContext } from './mqttProvider';
|
|
5
4
|
import { normalResolve } from './promise';
|
|
6
|
-
import {
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
5
|
+
import { hexToUriDecodedString } from '@ray-js/robot-protocol';
|
|
6
|
+
var DevInfoEnum = /*#__PURE__*/function (DevInfoEnum) {
|
|
7
|
+
DevInfoEnum["query"] = "devInfoQry";
|
|
8
|
+
return DevInfoEnum;
|
|
9
|
+
}(DevInfoEnum || {});
|
|
10
10
|
// 请求设备信息
|
|
11
11
|
export const useDevInfo = devId => {
|
|
12
12
|
const {
|
|
@@ -27,26 +27,10 @@ export const useDevInfo = devId => {
|
|
|
27
27
|
} = params.message;
|
|
28
28
|
return normalResolve(DevInfoEnum.query, taskId);
|
|
29
29
|
}
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
const dpDevInfo = (_devices$common$model = devices.common.model.props) === null || _devices$common$model === void 0 ? void 0 : _devices$common$model.device_info;
|
|
35
|
-
if (!dpDevInfo) {
|
|
36
|
-
return Promise.reject(new Error('Device info is not available in device properties'));
|
|
37
|
-
}
|
|
38
|
-
const info = hexToUriDecodedString(dpDevInfo);
|
|
39
|
-
return Promise.resolve({
|
|
40
|
-
info,
|
|
41
|
-
success: true,
|
|
42
|
-
errCode: 0,
|
|
43
|
-
reqType: DevInfoEnum.query,
|
|
44
|
-
version: '1.0.0',
|
|
45
|
-
taskId: `${Date.now()}`
|
|
46
|
-
});
|
|
47
|
-
} catch (error) {
|
|
48
|
-
return Promise.reject(error instanceof Error ? error : new Error('Failed to get device info from device properties'));
|
|
49
|
-
}
|
|
30
|
+
const dpDevInfo = devices.common.model.props.device_info;
|
|
31
|
+
return Promise.resolve({
|
|
32
|
+
info: hexToUriDecodedString(dpDevInfo)
|
|
33
|
+
});
|
|
50
34
|
}
|
|
51
35
|
};
|
|
52
36
|
};
|
|
@@ -1,18 +1,26 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
1
|
+
type TDeleteHistoryMap = (mapId: number) => Promise<{
|
|
2
|
+
success: boolean;
|
|
3
|
+
errCode: number;
|
|
4
|
+
reqType: string;
|
|
5
|
+
version: string;
|
|
6
|
+
taskId: string;
|
|
7
|
+
}>;
|
|
8
|
+
type TChangeCurrentMap = (mapId: number, url: string) => Promise<{
|
|
9
|
+
success: boolean;
|
|
10
|
+
errCode: number;
|
|
11
|
+
reqType: string;
|
|
7
12
|
mapId: number;
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
13
|
+
version: string;
|
|
14
|
+
taskId: string;
|
|
15
|
+
}>;
|
|
16
|
+
type TSaveMap = () => Promise<{
|
|
17
|
+
success: boolean;
|
|
18
|
+
errCode: number;
|
|
19
|
+
reqType: string;
|
|
11
20
|
mapId: number;
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
type TChangeCurrentMap = (mapId: number, url: string) => Promise<UseMapResponse>;
|
|
21
|
+
version: string;
|
|
22
|
+
taskId: string;
|
|
23
|
+
} | void>;
|
|
16
24
|
/**
|
|
17
25
|
* 自定义 Hook,用于管理历史地图
|
|
18
26
|
* @param devId 设备ID
|
|
@@ -6,16 +6,8 @@ import { DeleteMapEnum, SaveCurrentMapEnum, UseMapEnum } from './type';
|
|
|
6
6
|
import { SingletonContext } from './mqttProvider';
|
|
7
7
|
import { encodeDeleteMap0x2c, encodeSaveMap0x2a, encodeUseMap0x2e } from '@ray-js/robot-protocol';
|
|
8
8
|
|
|
9
|
-
// 删除历史地图响应类型
|
|
10
|
-
|
|
11
|
-
// 保存地图响应类型
|
|
12
|
-
|
|
13
|
-
// 更改当前地图响应类型
|
|
14
|
-
|
|
15
9
|
// 删除历史地图函数类型定义
|
|
16
10
|
|
|
17
|
-
// 保存当前地图函数类型定义
|
|
18
|
-
|
|
19
11
|
// 更改当前使用的地图函数类型定义
|
|
20
12
|
|
|
21
13
|
/**
|
|
@@ -26,36 +18,32 @@ import { encodeDeleteMap0x2c, encodeSaveMap0x2a, encodeUseMap0x2e } from '@ray-j
|
|
|
26
18
|
export const useHistoryMap = devId => {
|
|
27
19
|
const {
|
|
28
20
|
useMqtt,
|
|
29
|
-
devices
|
|
30
|
-
commandVersion
|
|
21
|
+
devices
|
|
31
22
|
} = useContext(SingletonContext);
|
|
32
|
-
|
|
33
23
|
/**
|
|
34
24
|
* 删除历史地图
|
|
35
25
|
* @param mapId 地图ID
|
|
36
|
-
* @returns Promise<
|
|
26
|
+
* @returns Promise<{ success: boolean; errCode: number; reqType: string; version: string; taskId: string; }> 响应结果
|
|
37
27
|
*/
|
|
38
28
|
|
|
39
29
|
/**
|
|
40
30
|
* 保存当前地图
|
|
41
|
-
* @returns Promise<
|
|
31
|
+
* @returns Promise<void> 响应结果
|
|
42
32
|
*/
|
|
43
33
|
|
|
44
34
|
/**
|
|
45
35
|
* 更改当前使用的地图
|
|
46
36
|
* @param mapId 地图ID
|
|
47
37
|
* @param url 地图URL
|
|
48
|
-
* @returns Promise<
|
|
38
|
+
* @returns Promise<{ success: boolean; errCode: number; reqType: string; mapId: number; version: string; taskId: string; }> 响应结果
|
|
49
39
|
*/
|
|
50
40
|
|
|
51
41
|
return {
|
|
52
42
|
deleteHistoryMap: async mapId => {
|
|
53
|
-
// 参数验证
|
|
54
|
-
if (!mapId || typeof mapId !== 'number') {
|
|
55
|
-
throw new Error('mapId is required and must be a number');
|
|
56
|
-
}
|
|
57
43
|
try {
|
|
58
|
-
|
|
44
|
+
if (!mapId) {
|
|
45
|
+
return Promise.reject(new Error('mapId is required'));
|
|
46
|
+
}
|
|
59
47
|
await deleteMultipleMapFile(mapId, devId);
|
|
60
48
|
if (useMqtt) {
|
|
61
49
|
const params = createSetCommonParams({
|
|
@@ -71,41 +59,28 @@ export const useHistoryMap = devId => {
|
|
|
71
59
|
} = params.message;
|
|
72
60
|
return normalResolve(DeleteMapEnum.rst, taskId);
|
|
73
61
|
}
|
|
74
|
-
|
|
75
|
-
// 非 MQTT 模式:使用命令传输
|
|
76
62
|
const command = encodeDeleteMap0x2c({
|
|
77
63
|
id: mapId
|
|
78
64
|
});
|
|
79
65
|
devices.common.model.actions.command_trans.set(command);
|
|
80
|
-
return Promise.resolve(
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
reqType: DeleteMapEnum.rst,
|
|
84
|
-
version: commandVersion,
|
|
85
|
-
taskId: `${Date.now()}`
|
|
86
|
-
});
|
|
87
|
-
} catch (error) {
|
|
88
|
-
throw error instanceof Error ? error : new Error('Failed to delete history map');
|
|
66
|
+
return Promise.resolve();
|
|
67
|
+
} catch (err) {
|
|
68
|
+
return Promise.reject(err);
|
|
89
69
|
}
|
|
90
70
|
},
|
|
91
71
|
changeCurrentMap: async (mapId, url) => {
|
|
92
|
-
// 参数验证
|
|
93
|
-
if (!mapId || typeof mapId !== 'number') {
|
|
94
|
-
throw new Error('mapId is required and must be a number');
|
|
95
|
-
}
|
|
96
|
-
if (!url || typeof url !== 'string') {
|
|
97
|
-
throw new Error('url is required and must be a string');
|
|
98
|
-
}
|
|
99
72
|
try {
|
|
100
73
|
if (useMqtt) {
|
|
74
|
+
const sendData = {
|
|
75
|
+
reqType: UseMapEnum.set,
|
|
76
|
+
mapId,
|
|
77
|
+
url,
|
|
78
|
+
urlLen: url.length
|
|
79
|
+
};
|
|
101
80
|
const params = createSetCommonParams({
|
|
102
81
|
deviceId: devId,
|
|
103
82
|
reqType: UseMapEnum.set,
|
|
104
|
-
message:
|
|
105
|
-
mapId,
|
|
106
|
-
url,
|
|
107
|
-
urlLen: url.length // URL 长度
|
|
108
|
-
}
|
|
83
|
+
message: sendData
|
|
109
84
|
});
|
|
110
85
|
ty.device.sendMqttMessage(params);
|
|
111
86
|
const {
|
|
@@ -113,56 +88,31 @@ export const useHistoryMap = devId => {
|
|
|
113
88
|
} = params.message;
|
|
114
89
|
return normalResolve(UseMapEnum.query, taskId);
|
|
115
90
|
}
|
|
116
|
-
|
|
117
|
-
// 非 MQTT 模式:使用命令传输
|
|
118
91
|
const command = encodeUseMap0x2e({
|
|
119
92
|
mapId,
|
|
120
93
|
url
|
|
121
94
|
});
|
|
122
95
|
devices.common.model.actions.command_trans.set(command);
|
|
123
|
-
return Promise.resolve(
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
reqType: UseMapEnum.query,
|
|
127
|
-
version: commandVersion,
|
|
128
|
-
taskId: `${Date.now()}`,
|
|
129
|
-
mapId
|
|
130
|
-
});
|
|
131
|
-
} catch (error) {
|
|
132
|
-
throw error instanceof Error ? error : new Error('Failed to change current map');
|
|
96
|
+
return Promise.resolve();
|
|
97
|
+
} catch (err) {
|
|
98
|
+
return Promise.reject(err);
|
|
133
99
|
}
|
|
134
100
|
},
|
|
135
101
|
saveMap: () => {
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
}
|
|
144
|
-
});
|
|
145
|
-
ty.device.sendMqttMessage(params);
|
|
146
|
-
const {
|
|
147
|
-
taskId
|
|
148
|
-
} = params.message;
|
|
149
|
-
return normalResolve(SaveCurrentMapEnum.query, taskId);
|
|
150
|
-
}
|
|
151
|
-
|
|
152
|
-
// 非 MQTT 模式:使用命令传输
|
|
153
|
-
const command = encodeSaveMap0x2a(1);
|
|
154
|
-
devices.common.model.actions.command_trans.set(command);
|
|
155
|
-
return Promise.resolve({
|
|
156
|
-
success: true,
|
|
157
|
-
errCode: 0,
|
|
158
|
-
reqType: SaveCurrentMapEnum.query,
|
|
159
|
-
version: commandVersion,
|
|
160
|
-
taskId: `${Date.now()}`,
|
|
161
|
-
mapId: 0 // 非 MQTT 模式下无法获取 mapId
|
|
102
|
+
if (useMqtt) {
|
|
103
|
+
const params = createSetCommonParams({
|
|
104
|
+
deviceId: devId,
|
|
105
|
+
reqType: SaveCurrentMapEnum.set,
|
|
106
|
+
message: {
|
|
107
|
+
oper: 0
|
|
108
|
+
}
|
|
162
109
|
});
|
|
163
|
-
|
|
164
|
-
|
|
110
|
+
ty.device.sendMqttMessage(params);
|
|
111
|
+
return normalResolve(SaveCurrentMapEnum.query, params.message.taskId);
|
|
165
112
|
}
|
|
113
|
+
const command = encodeSaveMap0x2a(1);
|
|
114
|
+
devices.common.model.actions.command_trans.set(command);
|
|
115
|
+
return Promise.resolve();
|
|
166
116
|
}
|
|
167
117
|
};
|
|
168
118
|
};
|
|
@@ -1,9 +1,11 @@
|
|
|
1
1
|
import { Point } from '../utils';
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
2
|
+
type TSetPartDivision = (points: Point[], roomId: number, origin: Point) => Promise<{
|
|
3
|
+
success: boolean;
|
|
4
|
+
errCode: number;
|
|
5
|
+
reqType: string;
|
|
6
|
+
version: string;
|
|
7
|
+
taskId: string;
|
|
8
|
+
} | void>;
|
|
7
9
|
/**
|
|
8
10
|
* 自定义 Hook,用于房间分隔
|
|
9
11
|
* @param devId 设备ID
|
|
@@ -7,8 +7,6 @@ import { PartDivisionEnum } from './type';
|
|
|
7
7
|
import { SingletonContext } from './mqttProvider';
|
|
8
8
|
import { encodePartitionDivision0x1c } from '@ray-js/robot-protocol';
|
|
9
9
|
|
|
10
|
-
// 房间分隔响应类型
|
|
11
|
-
|
|
12
10
|
// 设置房间分隔函数类型定义
|
|
13
11
|
|
|
14
12
|
/**
|
|
@@ -26,61 +24,38 @@ export const usePartDivision = devId => {
|
|
|
26
24
|
/**
|
|
27
25
|
* 设置房间分隔
|
|
28
26
|
* @param points 分隔点数组,SDK方法抛出来的坐标直接传入即可
|
|
29
|
-
* @param roomId 房间ID
|
|
27
|
+
* @param roomId 房间ID,当前要分隔的房间
|
|
30
28
|
* @param origin 地图原点坐标
|
|
31
|
-
* @returns Promise<
|
|
29
|
+
* @returns Promise<Response> 响应结果
|
|
32
30
|
*/
|
|
33
31
|
|
|
34
32
|
return {
|
|
35
33
|
setPartDivision: (points, roomId, origin) => {
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
throw new Error('points is required and must be a non-empty array');
|
|
39
|
-
}
|
|
40
|
-
if (typeof roomId !== 'number' || isNaN(roomId)) {
|
|
41
|
-
throw new Error('roomId is required and must be a valid number');
|
|
42
|
-
}
|
|
43
|
-
if (!origin || typeof origin.x !== 'number' || typeof origin.y !== 'number') {
|
|
44
|
-
throw new Error('origin is required and must be a valid Point object with x and y properties');
|
|
45
|
-
}
|
|
46
|
-
try {
|
|
47
|
-
if (useMqtt) {
|
|
48
|
-
// 将点数组转换为字符串格式
|
|
34
|
+
if (useMqtt) {
|
|
35
|
+
try {
|
|
49
36
|
const pointStr = pointsToString(points, origin);
|
|
50
37
|
const params = createSetCommonParams({
|
|
51
38
|
deviceId: devId,
|
|
52
39
|
reqType: PartDivisionEnum.set,
|
|
53
40
|
message: {
|
|
54
41
|
lines: [pointStr],
|
|
55
|
-
|
|
56
|
-
ids: [roomId] // 房间ID数组
|
|
42
|
+
ids: [roomId]
|
|
57
43
|
}
|
|
58
44
|
});
|
|
59
45
|
ty.device.sendMqttMessage(params);
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
return normalResolve(PartDivisionEnum.query, taskId);
|
|
46
|
+
return normalResolve(PartDivisionEnum.query, params.message.taskId);
|
|
47
|
+
} catch (e) {
|
|
48
|
+
throw new Error('房间分隔失败');
|
|
64
49
|
}
|
|
65
|
-
|
|
66
|
-
// 非 MQTT 模式:使用命令传输
|
|
67
|
-
const command = encodePartitionDivision0x1c({
|
|
68
|
-
version: commandVersion,
|
|
69
|
-
origin,
|
|
70
|
-
points,
|
|
71
|
-
roomId
|
|
72
|
-
});
|
|
73
|
-
devices.common.model.actions.command_trans.set(command);
|
|
74
|
-
return Promise.resolve({
|
|
75
|
-
success: true,
|
|
76
|
-
errCode: 0,
|
|
77
|
-
reqType: PartDivisionEnum.query,
|
|
78
|
-
version: commandVersion,
|
|
79
|
-
taskId: `${Date.now()}`
|
|
80
|
-
});
|
|
81
|
-
} catch (error) {
|
|
82
|
-
throw error instanceof Error ? error : new Error('Failed to set part division');
|
|
83
50
|
}
|
|
51
|
+
const command = encodePartitionDivision0x1c({
|
|
52
|
+
version: commandVersion,
|
|
53
|
+
origin,
|
|
54
|
+
points,
|
|
55
|
+
roomId
|
|
56
|
+
});
|
|
57
|
+
devices.common.model.actions.command_trans.set(command);
|
|
58
|
+
return Promise.resolve();
|
|
84
59
|
}
|
|
85
60
|
};
|
|
86
61
|
};
|
|
@@ -1,8 +1,10 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
1
|
+
type TSetPartMerge = (ids: number[]) => Promise<{
|
|
2
|
+
success: boolean;
|
|
3
|
+
errCode: number;
|
|
4
|
+
reqType: string;
|
|
5
|
+
version: string;
|
|
6
|
+
taskId: string;
|
|
7
|
+
} | void>;
|
|
6
8
|
/**
|
|
7
9
|
* 自定义 Hook,用于分区合并
|
|
8
10
|
* @param devId 设备ID
|
package/lib/mqtt/usePartMerge.js
CHANGED
|
@@ -8,8 +8,6 @@ import { PartMergeEnum } from './type';
|
|
|
8
8
|
import { SingletonContext } from './mqttProvider';
|
|
9
9
|
import { encodePartitionMerge0x1e } from '@ray-js/robot-protocol';
|
|
10
10
|
|
|
11
|
-
// 分区合并响应类型
|
|
12
|
-
|
|
13
11
|
// 设置分区合并函数类型定义
|
|
14
12
|
|
|
15
13
|
/**
|
|
@@ -26,50 +24,34 @@ export const usePartMerge = devId => {
|
|
|
26
24
|
/**
|
|
27
25
|
* 设置分区合并
|
|
28
26
|
* @param ids 要合并的分区ID数组
|
|
29
|
-
* @returns Promise<
|
|
27
|
+
* @returns Promise<Response> 响应结果
|
|
30
28
|
*/
|
|
31
29
|
|
|
32
30
|
return {
|
|
33
31
|
setPartMerge: ids => {
|
|
34
|
-
// 参数验证
|
|
35
32
|
if (!ids || ids.length < 2) {
|
|
36
|
-
|
|
33
|
+
return Promise.reject(new Error('ids is required and length must be greater than 1'));
|
|
37
34
|
}
|
|
38
35
|
if (ids.some(id => typeof id !== 'number')) {
|
|
39
|
-
|
|
36
|
+
return Promise.reject(new Error('ids must be an array of numbers'));
|
|
40
37
|
}
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
}
|
|
49
|
-
});
|
|
50
|
-
ty.device.sendMqttMessage(params);
|
|
51
|
-
const {
|
|
52
|
-
taskId
|
|
53
|
-
} = params.message;
|
|
54
|
-
return normalResolve(PartMergeEnum.query, taskId);
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
// 非 MQTT 模式:使用命令传输
|
|
58
|
-
const command = encodePartitionMerge0x1e({
|
|
59
|
-
version: commandVersion,
|
|
60
|
-
roomIds: ids
|
|
61
|
-
});
|
|
62
|
-
devices.common.model.actions.command_trans.set(command);
|
|
63
|
-
return Promise.resolve({
|
|
64
|
-
success: true,
|
|
65
|
-
errCode: 0,
|
|
66
|
-
reqType: PartMergeEnum.query,
|
|
67
|
-
version: commandVersion,
|
|
68
|
-
taskId: `${Date.now()}`
|
|
38
|
+
if (useMqtt) {
|
|
39
|
+
const params = createSetCommonParams({
|
|
40
|
+
deviceId: devId,
|
|
41
|
+
reqType: PartMergeEnum.set,
|
|
42
|
+
message: {
|
|
43
|
+
ids
|
|
44
|
+
}
|
|
69
45
|
});
|
|
70
|
-
|
|
71
|
-
|
|
46
|
+
ty.device.sendMqttMessage(params);
|
|
47
|
+
return normalResolve(PartMergeEnum.query, params.message.taskId);
|
|
72
48
|
}
|
|
49
|
+
const command = encodePartitionMerge0x1e({
|
|
50
|
+
version: commandVersion,
|
|
51
|
+
roomIds: ids
|
|
52
|
+
});
|
|
53
|
+
devices.common.model.actions.command_trans.set(command);
|
|
54
|
+
return Promise.resolve();
|
|
73
55
|
}
|
|
74
56
|
};
|
|
75
57
|
};
|
package/lib/mqtt/usePassword.js
CHANGED
|
@@ -17,22 +17,13 @@ export const usePassword = devId => {
|
|
|
17
17
|
|
|
18
18
|
return {
|
|
19
19
|
requestPassword: () => {
|
|
20
|
-
if (!useMqtt)
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
});
|
|
28
|
-
ty.device.sendMqttMessage(params);
|
|
29
|
-
const {
|
|
30
|
-
taskId
|
|
31
|
-
} = params.message;
|
|
32
|
-
return normalResolve(PasswordEnum.query, taskId);
|
|
33
|
-
} catch (error) {
|
|
34
|
-
return Promise.reject(error instanceof Error ? error : new Error('Failed to request password'));
|
|
35
|
-
}
|
|
20
|
+
if (!useMqtt) return Promise.reject(new Error('useMqtt is not used'));
|
|
21
|
+
const params = createSetCommonParams({
|
|
22
|
+
deviceId: devId,
|
|
23
|
+
reqType: PasswordEnum.query
|
|
24
|
+
});
|
|
25
|
+
ty.device.sendMqttMessage(params);
|
|
26
|
+
return normalResolve(PasswordEnum.query, params.message.taskId);
|
|
36
27
|
},
|
|
37
28
|
setPassword: _ref => {
|
|
38
29
|
let {
|
|
@@ -40,55 +31,33 @@ export const usePassword = devId => {
|
|
|
40
31
|
oldPassword,
|
|
41
32
|
taskId
|
|
42
33
|
} = _ref;
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
oldPassword: oldPassword ? md5(oldPassword).toString() : undefined
|
|
55
|
-
}
|
|
56
|
-
});
|
|
57
|
-
ty.device.sendMqttMessage(params);
|
|
58
|
-
const {
|
|
59
|
-
taskId: finalTaskId
|
|
60
|
-
} = params.message;
|
|
61
|
-
return normalResolve(PasswordEnum.rst, finalTaskId);
|
|
62
|
-
} catch (error) {
|
|
63
|
-
throw error instanceof Error ? error : new Error('Failed to set password');
|
|
64
|
-
}
|
|
34
|
+
const params = createSetCommonParams({
|
|
35
|
+
deviceId: devId,
|
|
36
|
+
reqType: PasswordEnum.set,
|
|
37
|
+
message: {
|
|
38
|
+
taskId: taskId !== null && taskId !== void 0 ? taskId : String(Date.now()),
|
|
39
|
+
password: md5(password).toString(),
|
|
40
|
+
oldPassword: oldPassword ? md5(oldPassword).toString() : undefined
|
|
41
|
+
}
|
|
42
|
+
});
|
|
43
|
+
ty.device.sendMqttMessage(params);
|
|
44
|
+
return normalResolve(PasswordEnum.rst, params.message.taskId);
|
|
65
45
|
},
|
|
66
46
|
checkPassword: _ref2 => {
|
|
67
47
|
let {
|
|
68
48
|
password,
|
|
69
49
|
taskId
|
|
70
50
|
} = _ref2;
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
password: md5(password).toString()
|
|
82
|
-
}
|
|
83
|
-
});
|
|
84
|
-
ty.device.sendMqttMessage(params);
|
|
85
|
-
const {
|
|
86
|
-
taskId: finalTaskId
|
|
87
|
-
} = params.message;
|
|
88
|
-
return normalResolve(PasswordEnum.checkRst, finalTaskId);
|
|
89
|
-
} catch (error) {
|
|
90
|
-
throw error instanceof Error ? error : new Error('Failed to check password');
|
|
91
|
-
}
|
|
51
|
+
const params = createSetCommonParams({
|
|
52
|
+
deviceId: devId,
|
|
53
|
+
reqType: PasswordEnum.check,
|
|
54
|
+
message: {
|
|
55
|
+
taskId: taskId !== null && taskId !== void 0 ? taskId : String(Date.now()),
|
|
56
|
+
password: md5(password).toString()
|
|
57
|
+
}
|
|
58
|
+
});
|
|
59
|
+
ty.device.sendMqttMessage(params);
|
|
60
|
+
return normalResolve(PasswordEnum.checkRst, params.message.taskId);
|
|
92
61
|
}
|
|
93
62
|
};
|
|
94
63
|
};
|