@ray-js/robot-data-stream 0.0.13-beta-6 → 0.0.13-beta-7
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 +12 -2
- package/lib/api/index.js +172 -1
- package/lib/api/p2pApi.d.ts +27 -8
- package/lib/api/p2pApi.js +169 -271
- package/lib/api/sweeperP2p.d.ts +21 -54
- package/lib/api/sweeperP2p.js +245 -324
- package/lib/constant.d.ts +52 -0
- package/lib/constant.js +54 -0
- package/lib/index.d.ts +1 -11
- package/lib/index.js +2 -166
- package/lib/mqtt/createCommonOptions.d.ts +56 -15
- package/lib/mqtt/createCommonOptions.js +44 -8
- package/lib/mqtt/mqttProvider.d.ts +23 -15
- package/lib/mqtt/mqttProvider.js +63 -26
- package/lib/mqtt/promise.js +8 -3
- package/lib/mqtt/type/index.d.ts +9 -0
- package/lib/mqtt/type/index.js +8 -0
- package/lib/mqtt/type/requestType.d.ts +3 -0
- package/lib/mqtt/type/requestType.js +4 -0
- package/lib/mqtt/useDevInfo.d.ts +2 -7
- package/lib/mqtt/useDevInfo.js +25 -9
- package/lib/mqtt/useHistoryMap.d.ts +13 -21
- package/lib/mqtt/useHistoryMap.js +82 -32
- package/lib/mqtt/usePartDivision.d.ts +5 -7
- package/lib/mqtt/usePartDivision.js +41 -16
- package/lib/mqtt/usePartMerge.d.ts +5 -7
- package/lib/mqtt/usePartMerge.js +36 -18
- package/lib/mqtt/usePassword.js +59 -28
- package/lib/mqtt/useQuiteHours.d.ts +9 -24
- package/lib/mqtt/useQuiteHours.js +95 -52
- package/lib/mqtt/useResetMap.d.ts +10 -7
- package/lib/mqtt/useResetMap.js +40 -11
- package/lib/mqtt/useRoomProperty.js +23 -16
- package/lib/mqtt/useSchedule.d.ts +17 -4
- package/lib/mqtt/useSchedule.js +101 -49
- package/lib/mqtt/useSelectRoomClean.d.ts +20 -16
- package/lib/mqtt/useSelectRoomClean.js +145 -49
- package/lib/mqtt/useSpotClean.d.ts +3 -3
- package/lib/mqtt/useSpotClean.js +71 -50
- package/lib/mqtt/useVirtualArea.d.ts +6 -9
- package/lib/mqtt/useVirtualArea.js +112 -42
- package/lib/mqtt/useVirtualWall.d.ts +13 -10
- package/lib/mqtt/useVirtualWall.js +97 -34
- package/lib/mqtt/useVoice.d.ts +3 -6
- package/lib/mqtt/useVoice.js +73 -33
- package/lib/mqtt/useWifiMap.js +34 -18
- package/lib/mqtt/useZoneClean.d.ts +13 -13
- package/lib/mqtt/useZoneClean.js +149 -76
- package/lib/ttt/index.d.ts +153 -0
- package/lib/ttt/index.js +458 -0
- package/lib/utils/index.d.ts +20 -1
- package/lib/utils/index.js +19 -0
- package/package.json +1 -1
- package/lib/mqtt/myError.d.ts +0 -4
- package/lib/mqtt/myError.js +0 -6
|
@@ -104,4 +104,8 @@ 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;
|
|
107
111
|
}({});
|
package/lib/mqtt/useDevInfo.d.ts
CHANGED
|
@@ -1,12 +1,7 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
version?: string;
|
|
1
|
+
import { BaseResponse } from './type';
|
|
2
|
+
export interface DevInfoResponse extends BaseResponse {
|
|
4
3
|
info: string;
|
|
5
|
-
success?: boolean;
|
|
6
|
-
errCode?: number;
|
|
7
|
-
taskId?: string;
|
|
8
4
|
}
|
|
9
5
|
export declare const useDevInfo: (devId: string) => {
|
|
10
6
|
requestDevInfo: () => Promise<DevInfoResponse>;
|
|
11
7
|
};
|
|
12
|
-
export {};
|
package/lib/mqtt/useDevInfo.js
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
|
+
import { hexToUriDecodedString } from '@ray-js/robot-protocol';
|
|
1
2
|
import { useContext } from 'react';
|
|
2
3
|
import { createSetCommonParams } from './createCommonOptions';
|
|
3
4
|
import { SingletonContext } from './mqttProvider';
|
|
4
5
|
import { normalResolve } from './promise';
|
|
5
|
-
import {
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
}(DevInfoEnum || {});
|
|
6
|
+
import { DevInfoEnum } from './type';
|
|
7
|
+
|
|
8
|
+
// 设备信息响应类型
|
|
9
|
+
|
|
10
10
|
// 请求设备信息
|
|
11
11
|
export const useDevInfo = devId => {
|
|
12
12
|
const {
|
|
@@ -27,10 +27,26 @@ export const useDevInfo = devId => {
|
|
|
27
27
|
} = params.message;
|
|
28
28
|
return normalResolve(DevInfoEnum.query, taskId);
|
|
29
29
|
}
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
30
|
+
|
|
31
|
+
// 非 MQTT 模式:从设备属性中获取设备信息
|
|
32
|
+
try {
|
|
33
|
+
var _devices$common$model;
|
|
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
|
+
}
|
|
34
50
|
}
|
|
35
51
|
};
|
|
36
52
|
};
|
|
@@ -1,26 +1,18 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
}>;
|
|
8
|
-
type TChangeCurrentMap = (mapId: number, url: string) => Promise<{
|
|
9
|
-
success: boolean;
|
|
10
|
-
errCode: number;
|
|
11
|
-
reqType: string;
|
|
1
|
+
import { BaseResponse, DeleteMapEnum, SaveCurrentMapEnum, UseMapEnum } from './type';
|
|
2
|
+
interface DeleteMapResponse extends BaseResponse {
|
|
3
|
+
reqType: DeleteMapEnum.rst;
|
|
4
|
+
}
|
|
5
|
+
interface SaveMapResponse extends BaseResponse {
|
|
6
|
+
reqType: SaveCurrentMapEnum.query;
|
|
12
7
|
mapId: number;
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
type TSaveMap = () => Promise<{
|
|
17
|
-
success: boolean;
|
|
18
|
-
errCode: number;
|
|
19
|
-
reqType: string;
|
|
8
|
+
}
|
|
9
|
+
interface UseMapResponse extends BaseResponse {
|
|
10
|
+
reqType: UseMapEnum.query;
|
|
20
11
|
mapId: number;
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
12
|
+
}
|
|
13
|
+
type TDeleteHistoryMap = (mapId: number) => Promise<DeleteMapResponse>;
|
|
14
|
+
type TSaveMap = () => Promise<SaveMapResponse>;
|
|
15
|
+
type TChangeCurrentMap = (mapId: number, url: string) => Promise<UseMapResponse>;
|
|
24
16
|
/**
|
|
25
17
|
* 自定义 Hook,用于管理历史地图
|
|
26
18
|
* @param devId 设备ID
|
|
@@ -6,8 +6,16 @@ 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
|
+
|
|
9
15
|
// 删除历史地图函数类型定义
|
|
10
16
|
|
|
17
|
+
// 保存当前地图函数类型定义
|
|
18
|
+
|
|
11
19
|
// 更改当前使用的地图函数类型定义
|
|
12
20
|
|
|
13
21
|
/**
|
|
@@ -18,32 +26,36 @@ import { encodeDeleteMap0x2c, encodeSaveMap0x2a, encodeUseMap0x2e } from '@ray-j
|
|
|
18
26
|
export const useHistoryMap = devId => {
|
|
19
27
|
const {
|
|
20
28
|
useMqtt,
|
|
21
|
-
devices
|
|
29
|
+
devices,
|
|
30
|
+
commandVersion
|
|
22
31
|
} = useContext(SingletonContext);
|
|
32
|
+
|
|
23
33
|
/**
|
|
24
34
|
* 删除历史地图
|
|
25
35
|
* @param mapId 地图ID
|
|
26
|
-
* @returns Promise<
|
|
36
|
+
* @returns Promise<DeleteMapResponse> 响应结果
|
|
27
37
|
*/
|
|
28
38
|
|
|
29
39
|
/**
|
|
30
40
|
* 保存当前地图
|
|
31
|
-
* @returns Promise<
|
|
41
|
+
* @returns Promise<SaveMapResponse> 响应结果
|
|
32
42
|
*/
|
|
33
43
|
|
|
34
44
|
/**
|
|
35
45
|
* 更改当前使用的地图
|
|
36
46
|
* @param mapId 地图ID
|
|
37
47
|
* @param url 地图URL
|
|
38
|
-
* @returns Promise<
|
|
48
|
+
* @returns Promise<UseMapResponse> 响应结果
|
|
39
49
|
*/
|
|
40
50
|
|
|
41
51
|
return {
|
|
42
52
|
deleteHistoryMap: async mapId => {
|
|
53
|
+
// 参数验证
|
|
54
|
+
if (!mapId || typeof mapId !== 'number') {
|
|
55
|
+
throw new Error('mapId is required and must be a number');
|
|
56
|
+
}
|
|
43
57
|
try {
|
|
44
|
-
|
|
45
|
-
return Promise.reject(new Error('mapId is required'));
|
|
46
|
-
}
|
|
58
|
+
// 先删除地图文件
|
|
47
59
|
await deleteMultipleMapFile(mapId, devId);
|
|
48
60
|
if (useMqtt) {
|
|
49
61
|
const params = createSetCommonParams({
|
|
@@ -59,28 +71,41 @@ export const useHistoryMap = devId => {
|
|
|
59
71
|
} = params.message;
|
|
60
72
|
return normalResolve(DeleteMapEnum.rst, taskId);
|
|
61
73
|
}
|
|
74
|
+
|
|
75
|
+
// 非 MQTT 模式:使用命令传输
|
|
62
76
|
const command = encodeDeleteMap0x2c({
|
|
63
77
|
id: mapId
|
|
64
78
|
});
|
|
65
79
|
devices.common.model.actions.command_trans.set(command);
|
|
66
|
-
return Promise.resolve(
|
|
67
|
-
|
|
68
|
-
|
|
80
|
+
return Promise.resolve({
|
|
81
|
+
success: true,
|
|
82
|
+
errCode: 0,
|
|
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');
|
|
69
89
|
}
|
|
70
90
|
},
|
|
71
91
|
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
|
+
}
|
|
72
99
|
try {
|
|
73
100
|
if (useMqtt) {
|
|
74
|
-
const sendData = {
|
|
75
|
-
reqType: UseMapEnum.set,
|
|
76
|
-
mapId,
|
|
77
|
-
url,
|
|
78
|
-
urlLen: url.length
|
|
79
|
-
};
|
|
80
101
|
const params = createSetCommonParams({
|
|
81
102
|
deviceId: devId,
|
|
82
103
|
reqType: UseMapEnum.set,
|
|
83
|
-
message:
|
|
104
|
+
message: {
|
|
105
|
+
mapId,
|
|
106
|
+
url,
|
|
107
|
+
urlLen: url.length // URL 长度
|
|
108
|
+
}
|
|
84
109
|
});
|
|
85
110
|
ty.device.sendMqttMessage(params);
|
|
86
111
|
const {
|
|
@@ -88,31 +113,56 @@ export const useHistoryMap = devId => {
|
|
|
88
113
|
} = params.message;
|
|
89
114
|
return normalResolve(UseMapEnum.query, taskId);
|
|
90
115
|
}
|
|
116
|
+
|
|
117
|
+
// 非 MQTT 模式:使用命令传输
|
|
91
118
|
const command = encodeUseMap0x2e({
|
|
92
119
|
mapId,
|
|
93
120
|
url
|
|
94
121
|
});
|
|
95
122
|
devices.common.model.actions.command_trans.set(command);
|
|
96
|
-
return Promise.resolve(
|
|
97
|
-
|
|
98
|
-
|
|
123
|
+
return Promise.resolve({
|
|
124
|
+
success: true,
|
|
125
|
+
errCode: 0,
|
|
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');
|
|
99
133
|
}
|
|
100
134
|
},
|
|
101
135
|
saveMap: () => {
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
136
|
+
try {
|
|
137
|
+
if (useMqtt) {
|
|
138
|
+
const params = createSetCommonParams({
|
|
139
|
+
deviceId: devId,
|
|
140
|
+
reqType: SaveCurrentMapEnum.set,
|
|
141
|
+
message: {
|
|
142
|
+
oper: 0 // 操作类型:0 表示保存
|
|
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
|
|
109
162
|
});
|
|
110
|
-
|
|
111
|
-
|
|
163
|
+
} catch (error) {
|
|
164
|
+
throw error instanceof Error ? error : new Error('Failed to save current map');
|
|
112
165
|
}
|
|
113
|
-
const command = encodeSaveMap0x2a(1);
|
|
114
|
-
devices.common.model.actions.command_trans.set(command);
|
|
115
|
-
return Promise.resolve();
|
|
116
166
|
}
|
|
117
167
|
};
|
|
118
168
|
};
|
|
@@ -1,11 +1,9 @@
|
|
|
1
1
|
import { Point } from '../utils';
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
taskId: string;
|
|
8
|
-
} | void>;
|
|
2
|
+
import { BaseResponse, PartDivisionEnum } from './type';
|
|
3
|
+
interface PartDivisionResponse extends BaseResponse {
|
|
4
|
+
reqType: PartDivisionEnum.query;
|
|
5
|
+
}
|
|
6
|
+
type TSetPartDivision = (points: Point[], roomId: number, origin: Point) => Promise<PartDivisionResponse>;
|
|
9
7
|
/**
|
|
10
8
|
* 自定义 Hook,用于房间分隔
|
|
11
9
|
* @param devId 设备ID
|
|
@@ -7,6 +7,8 @@ import { PartDivisionEnum } from './type';
|
|
|
7
7
|
import { SingletonContext } from './mqttProvider';
|
|
8
8
|
import { encodePartitionDivision0x1c } from '@ray-js/robot-protocol';
|
|
9
9
|
|
|
10
|
+
// 房间分隔响应类型
|
|
11
|
+
|
|
10
12
|
// 设置房间分隔函数类型定义
|
|
11
13
|
|
|
12
14
|
/**
|
|
@@ -24,38 +26,61 @@ export const usePartDivision = devId => {
|
|
|
24
26
|
/**
|
|
25
27
|
* 设置房间分隔
|
|
26
28
|
* @param points 分隔点数组,SDK方法抛出来的坐标直接传入即可
|
|
27
|
-
* @param roomId 房间ID
|
|
29
|
+
* @param roomId 房间ID,当前要分隔的房间
|
|
28
30
|
* @param origin 地图原点坐标
|
|
29
|
-
* @returns Promise<
|
|
31
|
+
* @returns Promise<PartDivisionResponse> 响应结果
|
|
30
32
|
*/
|
|
31
33
|
|
|
32
34
|
return {
|
|
33
35
|
setPartDivision: (points, roomId, origin) => {
|
|
34
|
-
|
|
35
|
-
|
|
36
|
+
// 参数验证
|
|
37
|
+
if (!Array.isArray(points) || points.length === 0) {
|
|
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
|
+
// 将点数组转换为字符串格式
|
|
36
49
|
const pointStr = pointsToString(points, origin);
|
|
37
50
|
const params = createSetCommonParams({
|
|
38
51
|
deviceId: devId,
|
|
39
52
|
reqType: PartDivisionEnum.set,
|
|
40
53
|
message: {
|
|
41
54
|
lines: [pointStr],
|
|
42
|
-
|
|
55
|
+
// 分隔线数组
|
|
56
|
+
ids: [roomId] // 房间ID数组
|
|
43
57
|
}
|
|
44
58
|
});
|
|
45
59
|
ty.device.sendMqttMessage(params);
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
60
|
+
const {
|
|
61
|
+
taskId
|
|
62
|
+
} = params.message;
|
|
63
|
+
return normalResolve(PartDivisionEnum.query, taskId);
|
|
49
64
|
}
|
|
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');
|
|
50
83
|
}
|
|
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();
|
|
59
84
|
}
|
|
60
85
|
};
|
|
61
86
|
};
|
|
@@ -1,10 +1,8 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
taskId: string;
|
|
7
|
-
} | void>;
|
|
1
|
+
import { BaseResponse, PartMergeEnum } from './type';
|
|
2
|
+
interface PartMergeResponse extends BaseResponse {
|
|
3
|
+
reqType: PartMergeEnum.query;
|
|
4
|
+
}
|
|
5
|
+
type TSetPartMerge = (ids: number[]) => Promise<PartMergeResponse>;
|
|
8
6
|
/**
|
|
9
7
|
* 自定义 Hook,用于分区合并
|
|
10
8
|
* @param devId 设备ID
|
package/lib/mqtt/usePartMerge.js
CHANGED
|
@@ -8,6 +8,8 @@ import { PartMergeEnum } from './type';
|
|
|
8
8
|
import { SingletonContext } from './mqttProvider';
|
|
9
9
|
import { encodePartitionMerge0x1e } from '@ray-js/robot-protocol';
|
|
10
10
|
|
|
11
|
+
// 分区合并响应类型
|
|
12
|
+
|
|
11
13
|
// 设置分区合并函数类型定义
|
|
12
14
|
|
|
13
15
|
/**
|
|
@@ -24,34 +26,50 @@ export const usePartMerge = devId => {
|
|
|
24
26
|
/**
|
|
25
27
|
* 设置分区合并
|
|
26
28
|
* @param ids 要合并的分区ID数组
|
|
27
|
-
* @returns Promise<
|
|
29
|
+
* @returns Promise<PartMergeResponse> 响应结果
|
|
28
30
|
*/
|
|
29
31
|
|
|
30
32
|
return {
|
|
31
33
|
setPartMerge: ids => {
|
|
34
|
+
// 参数验证
|
|
32
35
|
if (!ids || ids.length < 2) {
|
|
33
|
-
|
|
36
|
+
throw new Error('ids is required and length must be greater than 1');
|
|
34
37
|
}
|
|
35
38
|
if (ids.some(id => typeof id !== 'number')) {
|
|
36
|
-
|
|
39
|
+
throw new Error('ids must be an array of numbers');
|
|
37
40
|
}
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
41
|
+
try {
|
|
42
|
+
if (useMqtt) {
|
|
43
|
+
const params = createSetCommonParams({
|
|
44
|
+
deviceId: devId,
|
|
45
|
+
reqType: PartMergeEnum.set,
|
|
46
|
+
message: {
|
|
47
|
+
ids
|
|
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()}`
|
|
45
69
|
});
|
|
46
|
-
|
|
47
|
-
|
|
70
|
+
} catch (error) {
|
|
71
|
+
throw error instanceof Error ? error : new Error('Failed to set part merge');
|
|
48
72
|
}
|
|
49
|
-
const command = encodePartitionMerge0x1e({
|
|
50
|
-
version: commandVersion,
|
|
51
|
-
roomIds: ids
|
|
52
|
-
});
|
|
53
|
-
devices.common.model.actions.command_trans.set(command);
|
|
54
|
-
return Promise.resolve();
|
|
55
73
|
}
|
|
56
74
|
};
|
|
57
75
|
};
|
package/lib/mqtt/usePassword.js
CHANGED
|
@@ -17,13 +17,22 @@ export const usePassword = devId => {
|
|
|
17
17
|
|
|
18
18
|
return {
|
|
19
19
|
requestPassword: () => {
|
|
20
|
-
if (!useMqtt)
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
20
|
+
if (!useMqtt) {
|
|
21
|
+
return Promise.reject(new Error('useMqtt is not used'));
|
|
22
|
+
}
|
|
23
|
+
try {
|
|
24
|
+
const params = createSetCommonParams({
|
|
25
|
+
deviceId: devId,
|
|
26
|
+
reqType: PasswordEnum.query
|
|
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
|
+
}
|
|
27
36
|
},
|
|
28
37
|
setPassword: _ref => {
|
|
29
38
|
let {
|
|
@@ -31,33 +40,55 @@ export const usePassword = devId => {
|
|
|
31
40
|
oldPassword,
|
|
32
41
|
taskId
|
|
33
42
|
} = _ref;
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
43
|
+
// 参数验证
|
|
44
|
+
if (!password || typeof password !== 'string') {
|
|
45
|
+
throw new Error('password is required and must be a string');
|
|
46
|
+
}
|
|
47
|
+
try {
|
|
48
|
+
const params = createSetCommonParams({
|
|
49
|
+
deviceId: devId,
|
|
50
|
+
reqType: PasswordEnum.set,
|
|
51
|
+
message: {
|
|
52
|
+
taskId: taskId !== null && taskId !== void 0 ? taskId : String(Date.now()),
|
|
53
|
+
password: md5(password).toString(),
|
|
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
|
+
}
|
|
45
65
|
},
|
|
46
66
|
checkPassword: _ref2 => {
|
|
47
67
|
let {
|
|
48
68
|
password,
|
|
49
69
|
taskId
|
|
50
70
|
} = _ref2;
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
71
|
+
// 参数验证
|
|
72
|
+
if (!password || typeof password !== 'string') {
|
|
73
|
+
throw new Error('password is required and must be a string');
|
|
74
|
+
}
|
|
75
|
+
try {
|
|
76
|
+
const params = createSetCommonParams({
|
|
77
|
+
deviceId: devId,
|
|
78
|
+
reqType: PasswordEnum.check,
|
|
79
|
+
message: {
|
|
80
|
+
taskId: taskId !== null && taskId !== void 0 ? taskId : String(Date.now()),
|
|
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
|
+
}
|
|
61
92
|
}
|
|
62
93
|
};
|
|
63
94
|
};
|
|
@@ -1,9 +1,6 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
* 版本号
|
|
5
|
-
*/
|
|
6
|
-
version: string;
|
|
1
|
+
import { BaseResponse, QuietHoursEnum } from './type';
|
|
2
|
+
interface QuietHoursResponse extends BaseResponse {
|
|
3
|
+
reqType: QuietHoursEnum.query;
|
|
7
4
|
/**
|
|
8
5
|
* 是否激活
|
|
9
6
|
* 0 表示未激活,1 表示激活
|
|
@@ -17,20 +14,8 @@ type Response = {
|
|
|
17
14
|
* 星期几,1 表示星期一,2 表示星期二,以此类推
|
|
18
15
|
*/
|
|
19
16
|
day: number;
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
*/
|
|
23
|
-
success: boolean;
|
|
24
|
-
/**
|
|
25
|
-
* 错误代码,0 表示无错误
|
|
26
|
-
*/
|
|
27
|
-
errCode: number;
|
|
28
|
-
/**
|
|
29
|
-
* 任务ID
|
|
30
|
-
*/
|
|
31
|
-
taskId: string;
|
|
32
|
-
};
|
|
33
|
-
type TSetQuiteHours = (params: {
|
|
17
|
+
}
|
|
18
|
+
interface SetQuiteHoursParams {
|
|
34
19
|
startTime: {
|
|
35
20
|
hour: number;
|
|
36
21
|
minute: number;
|
|
@@ -42,9 +27,9 @@ type TSetQuiteHours = (params: {
|
|
|
42
27
|
active: number;
|
|
43
28
|
day: number;
|
|
44
29
|
version?: string;
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
|
|
30
|
+
}
|
|
31
|
+
type TSetQuiteHours = (params: SetQuiteHoursParams) => Promise<QuietHoursResponse>;
|
|
32
|
+
type TRequestQuiteHours = () => Promise<QuietHoursResponse>;
|
|
48
33
|
/**
|
|
49
34
|
* 自定义 Hook,用于勿扰模式
|
|
50
35
|
* @param devId 设备ID
|
|
@@ -52,6 +37,6 @@ type TSetQuiteHours = (params: {
|
|
|
52
37
|
*/
|
|
53
38
|
export declare const useQuiteHours: (devId: string) => {
|
|
54
39
|
setQuiteHours: TSetQuiteHours;
|
|
55
|
-
requestQuiteHours:
|
|
40
|
+
requestQuiteHours: TRequestQuiteHours;
|
|
56
41
|
};
|
|
57
42
|
export {};
|