@ray-js/robot-data-stream 0.0.14 → 0.0.15-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/mqtt/createCommonOptions.d.ts +4 -2
- package/lib/mqtt/createCommonOptions.js +10 -5
- package/lib/mqtt/hooks/useStructuredMessage.d.ts +14 -0
- package/lib/mqtt/hooks/useStructuredMessage.js +131 -0
- package/lib/mqtt/mqttProvider.d.ts +19 -1
- package/lib/mqtt/mqttProvider.js +69 -8
- package/lib/mqtt/promise.d.ts +57 -4
- package/lib/mqtt/promise.js +115 -36
- package/lib/mqtt/type/fun.d.ts +49 -0
- package/lib/mqtt/type/fun.js +145 -0
- package/lib/mqtt/type/index.d.ts +0 -7
- package/lib/mqtt/type/index.js +0 -1
- package/lib/mqtt/type/protocols/base.d.ts +5 -0
- package/lib/mqtt/type/protocols/base.js +32 -0
- package/lib/mqtt/type/protocols/carpetCleanProtocol.d.ts +8 -0
- package/lib/mqtt/type/protocols/carpetCleanProtocol.js +16 -0
- package/lib/mqtt/type/protocols/carpetProtocol.d.ts +41 -0
- package/lib/mqtt/type/protocols/carpetProtocol.js +202 -0
- package/lib/mqtt/type/protocols/devInfoProtocol.d.ts +5 -0
- package/lib/mqtt/type/protocols/devInfoProtocol.js +12 -0
- package/lib/mqtt/type/protocols/deviceModelProtocol.d.ts +8 -0
- package/lib/mqtt/type/protocols/deviceModelProtocol.js +34 -0
- package/lib/mqtt/type/protocols/furnitureModelProtocol.d.ts +10 -0
- package/lib/mqtt/type/protocols/furnitureModelProtocol.js +35 -0
- package/lib/mqtt/type/protocols/historyMapProtocol.d.ts +17 -0
- package/lib/mqtt/type/protocols/historyMapProtocol.js +37 -0
- package/lib/mqtt/type/protocols/index.d.ts +20 -0
- package/lib/mqtt/type/protocols/index.js +20 -0
- package/lib/mqtt/type/protocols/partDivisionProtocol.d.ts +8 -0
- package/lib/mqtt/type/protocols/partDivisionProtocol.js +12 -0
- package/lib/mqtt/type/protocols/partMergeProtocol.d.ts +7 -0
- package/lib/mqtt/type/protocols/partMergeProtocol.js +12 -0
- package/lib/mqtt/type/protocols/passwordProtocol.d.ts +11 -0
- package/lib/mqtt/type/protocols/passwordProtocol.js +25 -0
- package/lib/mqtt/type/protocols/quietHoursProtocol.d.ts +8 -0
- package/lib/mqtt/type/protocols/quietHoursProtocol.js +35 -0
- package/lib/mqtt/type/protocols/resetMapProtocol.d.ts +4 -0
- package/lib/mqtt/type/protocols/resetMapProtocol.js +1 -0
- package/lib/mqtt/type/protocols/roomPropertyProtocol.d.ts +14 -0
- package/lib/mqtt/type/protocols/roomPropertyProtocol.js +113 -0
- package/lib/mqtt/type/protocols/scheduleProtocol.d.ts +18 -0
- package/lib/mqtt/type/protocols/scheduleProtocol.js +100 -0
- package/lib/mqtt/type/protocols/selectRoomCleanProtocol.d.ts +8 -0
- package/lib/mqtt/type/protocols/selectRoomCleanProtocol.js +40 -0
- package/lib/mqtt/type/protocols/spotCleanProtocol.d.ts +9 -0
- package/lib/mqtt/type/protocols/spotCleanProtocol.js +72 -0
- package/lib/mqtt/type/protocols/virtualAreaProtocol.d.ts +8 -0
- package/lib/mqtt/type/protocols/virtualAreaProtocol.js +36 -0
- package/lib/mqtt/type/protocols/virtualWallProtocol.d.ts +8 -0
- package/lib/mqtt/type/protocols/virtualWallProtocol.js +25 -0
- package/lib/mqtt/type/protocols/voiceProtocol.d.ts +8 -0
- package/lib/mqtt/type/protocols/voiceProtocol.js +23 -0
- package/lib/mqtt/type/protocols/wifiMapProtocol.d.ts +8 -0
- package/lib/mqtt/type/protocols/wifiMapProtocol.js +14 -0
- package/lib/mqtt/type/protocols/zoneCleanProtocol.d.ts +8 -0
- package/lib/mqtt/type/protocols/zoneCleanProtocol.js +49 -0
- package/lib/mqtt/useCarpet.d.ts +7 -67
- package/lib/mqtt/useCarpet.js +101 -181
- package/lib/mqtt/useCarpetClean.d.ts +2 -11
- package/lib/mqtt/useCarpetClean.js +24 -51
- package/lib/mqtt/useDevInfo.d.ts +8 -6
- package/lib/mqtt/useDevInfo.js +44 -36
- package/lib/mqtt/useDeviceModel.d.ts +6 -19
- package/lib/mqtt/useDeviceModel.js +29 -42
- package/lib/mqtt/useFurnitureModel.d.ts +6 -18
- package/lib/mqtt/useFurnitureModel.js +29 -43
- package/lib/mqtt/useHistoryMap.d.ts +2 -18
- package/lib/mqtt/useHistoryMap.js +102 -119
- package/lib/mqtt/usePartDivision.d.ts +2 -9
- package/lib/mqtt/usePartDivision.js +48 -57
- package/lib/mqtt/usePartMerge.d.ts +2 -8
- package/lib/mqtt/usePartMerge.js +34 -49
- package/lib/mqtt/usePassword.d.ts +6 -13
- package/lib/mqtt/usePassword.js +84 -74
- package/lib/mqtt/useQuiteHours.d.ts +4 -37
- package/lib/mqtt/useQuiteHours.js +66 -100
- package/lib/mqtt/useResetMap.d.ts +2 -8
- package/lib/mqtt/useResetMap.js +27 -34
- package/lib/mqtt/useRoomProperty.d.ts +8 -9
- package/lib/mqtt/useRoomProperty.js +67 -65
- package/lib/mqtt/useSchedule.d.ts +3 -23
- package/lib/mqtt/useSchedule.js +72 -101
- package/lib/mqtt/useSelectRoomClean.d.ts +3 -24
- package/lib/mqtt/useSelectRoomClean.js +107 -133
- package/lib/mqtt/useSpotClean.d.ts +5 -15
- package/lib/mqtt/useSpotClean.js +68 -121
- package/lib/mqtt/useVirtualArea.d.ts +6 -17
- package/lib/mqtt/useVirtualArea.js +109 -119
- package/lib/mqtt/useVirtualWall.d.ts +2 -18
- package/lib/mqtt/useVirtualWall.js +69 -90
- package/lib/mqtt/useVoice.d.ts +2 -16
- package/lib/mqtt/useVoice.js +48 -68
- package/lib/mqtt/useWifiMap.d.ts +6 -5
- package/lib/mqtt/useWifiMap.js +43 -42
- package/lib/mqtt/useZoneClean.d.ts +2 -21
- package/lib/mqtt/useZoneClean.js +125 -137
- package/lib/myLib/zod/mini/index.d.cts +1 -0
- package/lib/myLib/zod/mini/index.d.ts +1 -0
- package/lib/myLib/zod/mini/index.js +1 -0
- package/lib/myLib/zod/mini/package.json +6 -0
- package/lib/myLib/zod/src/mini/index.d.ts +1 -0
- package/lib/myLib/zod/src/mini/index.js +1 -0
- package/lib/myLib/zod/src/v4/core/api.d.ts +306 -0
- package/lib/myLib/zod/src/v4/core/api.js +1256 -0
- package/lib/myLib/zod/src/v4/core/checks.d.ts +278 -0
- package/lib/myLib/zod/src/v4/core/checks.js +816 -0
- package/lib/myLib/zod/src/v4/core/config.d.ts +9 -0
- package/lib/myLib/zod/src/v4/core/config.js +5 -0
- package/lib/myLib/zod/src/v4/core/core.d.ts +70 -0
- package/lib/myLib/zod/src/v4/core/core.js +95 -0
- package/lib/myLib/zod/src/v4/core/doc.d.ts +14 -0
- package/lib/myLib/zod/src/v4/core/doc.js +42 -0
- package/lib/myLib/zod/src/v4/core/errors.d.ts +220 -0
- package/lib/myLib/zod/src/v4/core/errors.js +232 -0
- package/lib/myLib/zod/src/v4/core/index.d.ts +15 -0
- package/lib/myLib/zod/src/v4/core/index.js +15 -0
- package/lib/myLib/zod/src/v4/core/json-schema-generator.d.ts +65 -0
- package/lib/myLib/zod/src/v4/core/json-schema-generator.js +120 -0
- package/lib/myLib/zod/src/v4/core/json-schema-processors.d.ts +49 -0
- package/lib/myLib/zod/src/v4/core/json-schema-processors.js +593 -0
- package/lib/myLib/zod/src/v4/core/json-schema.d.ts +88 -0
- package/lib/myLib/zod/src/v4/core/json-schema.js +1 -0
- package/lib/myLib/zod/src/v4/core/parse.d.ts +49 -0
- package/lib/myLib/zod/src/v4/core/parse.js +147 -0
- package/lib/myLib/zod/src/v4/core/regexes.d.ts +78 -0
- package/lib/myLib/zod/src/v4/core/regexes.js +146 -0
- package/lib/myLib/zod/src/v4/core/registries.d.ts +35 -0
- package/lib/myLib/zod/src/v4/core/registries.js +51 -0
- package/lib/myLib/zod/src/v4/core/schemas.d.ts +1136 -0
- package/lib/myLib/zod/src/v4/core/schemas.js +2745 -0
- package/lib/myLib/zod/src/v4/core/standard-schema.d.ts +126 -0
- package/lib/myLib/zod/src/v4/core/standard-schema.js +1 -0
- package/lib/myLib/zod/src/v4/core/to-json-schema.d.ts +114 -0
- package/lib/myLib/zod/src/v4/core/to-json-schema.js +488 -0
- package/lib/myLib/zod/src/v4/core/util.d.ts +199 -0
- package/lib/myLib/zod/src/v4/core/util.js +656 -0
- package/lib/myLib/zod/src/v4/core/versions.d.ts +5 -0
- package/lib/myLib/zod/src/v4/core/versions.js +5 -0
- package/lib/myLib/zod/src/v4/core/zsf.d.ts +91 -0
- package/lib/myLib/zod/src/v4/core/zsf.js +1 -0
- package/lib/myLib/zod/src/v4/mini/checks.d.ts +1 -0
- package/lib/myLib/zod/src/v4/mini/checks.js +1 -0
- package/lib/myLib/zod/src/v4/mini/coerce.d.ts +7 -0
- package/lib/myLib/zod/src/v4/mini/coerce.js +27 -0
- package/lib/myLib/zod/src/v4/mini/external.d.ts +11 -0
- package/lib/myLib/zod/src/v4/mini/external.js +16 -0
- package/lib/myLib/zod/src/v4/mini/index.d.ts +3 -0
- package/lib/myLib/zod/src/v4/mini/index.js +3 -0
- package/lib/myLib/zod/src/v4/mini/iso.d.ts +22 -0
- package/lib/myLib/zod/src/v4/mini/iso.js +46 -0
- package/lib/myLib/zod/src/v4/mini/parse.d.ts +1 -0
- package/lib/myLib/zod/src/v4/mini/parse.js +1 -0
- package/lib/myLib/zod/src/v4/mini/schemas.js +1244 -0
- package/lib/utils/index.d.ts +1 -0
- package/lib/utils/index.js +2 -1
- package/package.json +5 -3
|
@@ -1,32 +1,26 @@
|
|
|
1
1
|
// 勿扰模式
|
|
2
|
+
import { encodeDoNotDisturb0x32 } from '@ray-js/robot-protocol';
|
|
2
3
|
import { useContext } from 'react';
|
|
3
|
-
import {
|
|
4
|
-
import { normalResolve } from './promise';
|
|
5
|
-
import { QuietHoursEnum } from './type';
|
|
4
|
+
import { handleMqttError, useStructuredMessage } from './hooks/useStructuredMessage';
|
|
6
5
|
import { SingletonContext } from './mqttProvider';
|
|
7
|
-
import {
|
|
8
|
-
|
|
9
|
-
// 勿扰模式响应类型
|
|
10
|
-
|
|
11
|
-
// 设置勿扰模式参数类型
|
|
12
|
-
|
|
13
|
-
// 设置勿扰模式函数类型定义
|
|
14
|
-
|
|
15
|
-
// 请求勿扰模式函数类型定义
|
|
16
|
-
|
|
6
|
+
import { QuietHoursEnum } from './type';
|
|
7
|
+
import { validator } from './type/fun';
|
|
17
8
|
/**
|
|
18
9
|
* 自定义 Hook,用于勿扰模式
|
|
19
|
-
* @param devId 设备ID
|
|
20
10
|
* @returns 包含 setQuiteHours 和 requestQuiteHours 函数的对象
|
|
21
11
|
*/
|
|
22
|
-
export const useQuiteHours =
|
|
12
|
+
export const useQuiteHours = () => {
|
|
23
13
|
const {
|
|
24
14
|
useMqtt,
|
|
25
15
|
devices,
|
|
26
16
|
commandVersion
|
|
27
17
|
} = useContext(SingletonContext);
|
|
18
|
+
const {
|
|
19
|
+
sendStructuredMessage
|
|
20
|
+
} = useStructuredMessage();
|
|
28
21
|
/**
|
|
29
22
|
* 请求勿扰模式数据
|
|
23
|
+
* @param data 可选参数(目前为空对象)
|
|
30
24
|
* @returns Promise<QuietHoursResponse> 响应结果
|
|
31
25
|
*/
|
|
32
26
|
|
|
@@ -38,98 +32,70 @@ export const useQuiteHours = devId => {
|
|
|
38
32
|
|
|
39
33
|
return {
|
|
40
34
|
setQuiteHours: params => {
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
const {
|
|
62
|
-
hour: h0,
|
|
63
|
-
minute: m0
|
|
64
|
-
} = startTime;
|
|
65
|
-
const {
|
|
66
|
-
hour: h1,
|
|
67
|
-
minute: m1
|
|
68
|
-
} = endTime;
|
|
69
|
-
if (h0 < 0 || h0 > 23 || m0 < 0 || m0 > 59) {
|
|
70
|
-
throw new Error('startTime is invalid: hour must be 0-23, minute must be 0-59');
|
|
71
|
-
}
|
|
72
|
-
if (h1 < 0 || h1 > 23 || m1 < 0 || m1 > 59) {
|
|
73
|
-
throw new Error('endTime is invalid: hour must be 0-23, minute must be 0-59');
|
|
74
|
-
}
|
|
75
|
-
try {
|
|
76
|
-
if (useMqtt) {
|
|
77
|
-
const mqttParams = createSetCommonParams({
|
|
78
|
-
deviceId: devId,
|
|
79
|
-
reqType: QuietHoursEnum.set,
|
|
80
|
-
message: {
|
|
35
|
+
return new Promise((resolve, reject) => {
|
|
36
|
+
try {
|
|
37
|
+
// 使用 TypeBox Schema 进行参数验证
|
|
38
|
+
const validatedData = validator.validate('set_quiet_hours', params);
|
|
39
|
+
const {
|
|
40
|
+
startTime,
|
|
41
|
+
endTime,
|
|
42
|
+
active,
|
|
43
|
+
day
|
|
44
|
+
} = validatedData;
|
|
45
|
+
const {
|
|
46
|
+
hour: h0,
|
|
47
|
+
minute: m0
|
|
48
|
+
} = startTime;
|
|
49
|
+
const {
|
|
50
|
+
hour: h1,
|
|
51
|
+
minute: m1
|
|
52
|
+
} = endTime;
|
|
53
|
+
if (useMqtt) {
|
|
54
|
+
sendStructuredMessage(QuietHoursEnum.set, {
|
|
81
55
|
time: [`${h0},${m0}`, `${h1},${m1}`],
|
|
82
56
|
active,
|
|
83
57
|
day
|
|
84
|
-
}
|
|
58
|
+
}, resolve, error => reject(handleMqttError(error, 'Failed to set quiet hours')), QuietHoursEnum.query // 响应类型是 query,不是 set
|
|
59
|
+
);
|
|
60
|
+
return;
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
// 非 MQTT 模式:使用命令传输
|
|
64
|
+
const command = encodeDoNotDisturb0x32({
|
|
65
|
+
version: commandVersion,
|
|
66
|
+
startHour: h0,
|
|
67
|
+
startMinute: m0,
|
|
68
|
+
endHour: h1,
|
|
69
|
+
endMinute: m1
|
|
85
70
|
});
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
71
|
+
devices.common.model.actions.disturb_time_set.set(command);
|
|
72
|
+
resolve({
|
|
73
|
+
success: true,
|
|
74
|
+
errCode: 0,
|
|
75
|
+
reqType: QuietHoursEnum.query,
|
|
76
|
+
version: commandVersion,
|
|
77
|
+
taskId: `${Date.now()}`,
|
|
78
|
+
active,
|
|
79
|
+
time: [`${h0},${m0}`, `${h1},${m1}`],
|
|
80
|
+
day
|
|
81
|
+
});
|
|
82
|
+
} catch (error) {
|
|
83
|
+
reject(handleMqttError(error, 'Failed to set quiet hours'));
|
|
91
84
|
}
|
|
92
|
-
|
|
93
|
-
// 非 MQTT 模式:使用命令传输
|
|
94
|
-
const command = encodeDoNotDisturb0x32({
|
|
95
|
-
version: commandVersion,
|
|
96
|
-
startHour: h0,
|
|
97
|
-
startMinute: m0,
|
|
98
|
-
endHour: h1,
|
|
99
|
-
endMinute: m1
|
|
100
|
-
});
|
|
101
|
-
devices.common.model.actions.disturb_time_set.set(command);
|
|
102
|
-
return Promise.resolve({
|
|
103
|
-
success: true,
|
|
104
|
-
errCode: 0,
|
|
105
|
-
reqType: QuietHoursEnum.query,
|
|
106
|
-
version: commandVersion,
|
|
107
|
-
taskId: `${Date.now()}`,
|
|
108
|
-
active,
|
|
109
|
-
time: [`${h0},${m0}`, `${h1},${m1}`],
|
|
110
|
-
day
|
|
111
|
-
});
|
|
112
|
-
} catch (error) {
|
|
113
|
-
throw error instanceof Error ? error : new Error('Failed to set quiet hours');
|
|
114
|
-
}
|
|
85
|
+
});
|
|
115
86
|
},
|
|
116
87
|
requestQuiteHours: () => {
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
})
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
} = params.message;
|
|
129
|
-
return normalResolve(QuietHoursEnum.query, taskId);
|
|
130
|
-
} catch (error) {
|
|
131
|
-
return Promise.reject(error instanceof Error ? error : new Error('Failed to request quiet hours'));
|
|
132
|
-
}
|
|
88
|
+
return new Promise((resolve, reject) => {
|
|
89
|
+
try {
|
|
90
|
+
if (!useMqtt) {
|
|
91
|
+
reject(new Error('useMqtt is not used'));
|
|
92
|
+
return;
|
|
93
|
+
}
|
|
94
|
+
sendStructuredMessage(QuietHoursEnum.query, {}, resolve, error => reject(handleMqttError(error, 'Failed to request quiet hours')));
|
|
95
|
+
} catch (error) {
|
|
96
|
+
reject(handleMqttError(error, 'Failed to request quiet hours'));
|
|
97
|
+
}
|
|
98
|
+
});
|
|
133
99
|
}
|
|
134
100
|
};
|
|
135
101
|
};
|
|
@@ -1,14 +1,8 @@
|
|
|
1
|
-
import {
|
|
2
|
-
interface ResetMapResponse extends BaseResponse {
|
|
3
|
-
reqType: ResetCurrMapEnum.query;
|
|
4
|
-
}
|
|
5
|
-
type TSetResetMap = () => Promise<ResetMapResponse>;
|
|
1
|
+
import { type TSetResetMap } from './type/protocols';
|
|
6
2
|
/**
|
|
7
3
|
* 自定义 Hook,用于重置地图
|
|
8
|
-
* @param devId 设备ID
|
|
9
4
|
* @returns 包含 setResetMap 函数的对象
|
|
10
5
|
*/
|
|
11
|
-
export declare const useResetMap: (
|
|
6
|
+
export declare const useResetMap: () => {
|
|
12
7
|
setResetMap: TSetResetMap;
|
|
13
8
|
};
|
|
14
|
-
export {};
|
package/lib/mqtt/useResetMap.js
CHANGED
|
@@ -1,60 +1,53 @@
|
|
|
1
1
|
// 重置地图
|
|
2
2
|
import { useContext } from 'react';
|
|
3
|
-
import { createSetCommonParams } from './createCommonOptions';
|
|
4
|
-
import { normalResolve } from './promise';
|
|
5
3
|
import { ResetCurrMapEnum } from './type';
|
|
6
4
|
import { SingletonContext } from './mqttProvider';
|
|
7
5
|
import { encodeResetMap0x42 } from '@ray-js/robot-protocol';
|
|
8
|
-
|
|
9
|
-
// 重置地图响应类型
|
|
10
|
-
|
|
11
|
-
// 设置重置地图函数类型定义
|
|
12
|
-
|
|
6
|
+
import { useStructuredMessage, handleMqttError } from './hooks/useStructuredMessage';
|
|
13
7
|
/**
|
|
14
8
|
* 自定义 Hook,用于重置地图
|
|
15
|
-
* @param devId 设备ID
|
|
16
9
|
* @returns 包含 setResetMap 函数的对象
|
|
17
10
|
*/
|
|
18
|
-
export const useResetMap =
|
|
11
|
+
export const useResetMap = () => {
|
|
19
12
|
const {
|
|
20
13
|
useMqtt,
|
|
21
14
|
devices,
|
|
22
15
|
commandVersion
|
|
23
16
|
} = useContext(SingletonContext);
|
|
17
|
+
const {
|
|
18
|
+
sendStructuredMessage
|
|
19
|
+
} = useStructuredMessage();
|
|
24
20
|
/**
|
|
25
21
|
* 重置地图
|
|
22
|
+
* @param data 可选参数(目前为空对象)
|
|
26
23
|
* @returns Promise<ResetMapResponse> 响应结果
|
|
27
24
|
*/
|
|
28
25
|
|
|
29
26
|
return {
|
|
30
27
|
setResetMap: () => {
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
28
|
+
return new Promise((resolve, reject) => {
|
|
29
|
+
try {
|
|
30
|
+
if (useMqtt) {
|
|
31
|
+
sendStructuredMessage(ResetCurrMapEnum.set, {}, resolve, error => reject(handleMqttError(error, 'Failed to reset map')), ResetCurrMapEnum.query // 响应类型是 query,不是 set
|
|
32
|
+
);
|
|
33
|
+
return;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
// 非 MQTT 模式:使用命令传输
|
|
37
|
+
devices.common.model.actions.command_trans.set(encodeResetMap0x42({
|
|
38
|
+
version: commandVersion
|
|
39
|
+
}));
|
|
40
|
+
resolve({
|
|
41
|
+
success: true,
|
|
42
|
+
errCode: 0,
|
|
43
|
+
reqType: ResetCurrMapEnum.query,
|
|
44
|
+
version: commandVersion,
|
|
45
|
+
taskId: `${Date.now()}`
|
|
36
46
|
});
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
taskId
|
|
40
|
-
} = params.message;
|
|
41
|
-
return normalResolve(ResetCurrMapEnum.query, taskId);
|
|
47
|
+
} catch (error) {
|
|
48
|
+
reject(handleMqttError(error, 'Failed to reset map'));
|
|
42
49
|
}
|
|
43
|
-
|
|
44
|
-
// 非 MQTT 模式:使用命令传输
|
|
45
|
-
devices.common.model.actions.command_trans.set(encodeResetMap0x42({
|
|
46
|
-
version: commandVersion
|
|
47
|
-
}));
|
|
48
|
-
return Promise.resolve({
|
|
49
|
-
success: true,
|
|
50
|
-
errCode: 0,
|
|
51
|
-
reqType: ResetCurrMapEnum.query,
|
|
52
|
-
version: commandVersion,
|
|
53
|
-
taskId: `${Date.now()}`
|
|
54
|
-
});
|
|
55
|
-
} catch (error) {
|
|
56
|
-
throw error instanceof Error ? error : new Error('Failed to reset map');
|
|
57
|
-
}
|
|
50
|
+
});
|
|
58
51
|
}
|
|
59
52
|
};
|
|
60
53
|
};
|
|
@@ -1,11 +1,10 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
export declare const useRoomProperty: (
|
|
8
|
-
requestRoomProperty:
|
|
1
|
+
import { type TRequestRoomProperty, type TSetRoomProperty } from './type/protocols/roomPropertyProtocol';
|
|
2
|
+
/**
|
|
3
|
+
* 自定义 Hook,用于房间属性管理
|
|
4
|
+
* @param devId 设备ID(可选,如果不提供则从 MqttProvider Context 获取)
|
|
5
|
+
* @returns 包含 requestRoomProperty 和 setRoomProperty 函数的对象
|
|
6
|
+
*/
|
|
7
|
+
export declare const useRoomProperty: () => {
|
|
8
|
+
requestRoomProperty: TRequestRoomProperty;
|
|
9
9
|
setRoomProperty: TSetRoomProperty;
|
|
10
10
|
};
|
|
11
|
-
export {};
|
|
@@ -1,80 +1,82 @@
|
|
|
1
|
-
import { isArray } from 'lodash-es';
|
|
2
|
-
import { createSetCommonParams } from './createCommonOptions';
|
|
3
|
-
import { normalResolve } from './promise';
|
|
4
|
-
import { RoomPropertyEnum } from './type';
|
|
5
1
|
import { useContext } from 'react';
|
|
2
|
+
import { handleMqttError, useStructuredMessage } from './hooks/useStructuredMessage';
|
|
6
3
|
import { SingletonContext } from './mqttProvider';
|
|
7
|
-
|
|
4
|
+
import { RoomPropertyEnum } from './type';
|
|
5
|
+
import { validator } from './type/fun';
|
|
6
|
+
/**
|
|
7
|
+
* 自定义 Hook,用于房间属性管理
|
|
8
|
+
* @param devId 设备ID(可选,如果不提供则从 MqttProvider Context 获取)
|
|
9
|
+
* @returns 包含 requestRoomProperty 和 setRoomProperty 函数的对象
|
|
10
|
+
*/
|
|
11
|
+
export const useRoomProperty = () => {
|
|
8
12
|
const {
|
|
9
13
|
useMqtt
|
|
10
14
|
} = useContext(SingletonContext);
|
|
15
|
+
const {
|
|
16
|
+
sendStructuredMessage
|
|
17
|
+
} = useStructuredMessage();
|
|
11
18
|
|
|
12
|
-
|
|
19
|
+
/**
|
|
20
|
+
* 请求房间属性
|
|
21
|
+
* @param data 可选参数(目前为空对象)
|
|
22
|
+
* @returns Promise<RoomPropertyResponse> 响应结果
|
|
23
|
+
*/
|
|
13
24
|
|
|
14
|
-
|
|
25
|
+
/**
|
|
26
|
+
* 设置房间属性
|
|
27
|
+
* @param data 包含房间属性设置参数的对象
|
|
28
|
+
* @returns Promise<RoomPropertyResponse> 响应结果
|
|
29
|
+
*/
|
|
15
30
|
|
|
16
31
|
return {
|
|
17
32
|
requestRoomProperty: () => {
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
33
|
+
return new Promise((resolve, reject) => {
|
|
34
|
+
try {
|
|
35
|
+
if (!useMqtt) {
|
|
36
|
+
reject(new Error('useMqtt is not used'));
|
|
37
|
+
return;
|
|
38
|
+
}
|
|
39
|
+
sendStructuredMessage(RoomPropertyEnum.query, {}, resolve, error => reject(handleMqttError(error, 'Failed to request room property')));
|
|
40
|
+
} catch (error) {
|
|
41
|
+
reject(handleMqttError(error, 'Failed to request room property'));
|
|
42
|
+
}
|
|
22
43
|
});
|
|
23
|
-
ty.device.sendMqttMessage(params);
|
|
24
|
-
return normalResolve(RoomPropertyEnum.query, params.message.taskId);
|
|
25
44
|
},
|
|
26
|
-
setRoomProperty:
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
}
|
|
61
|
-
if (len !== suctions.length || len !== cisterns.length || len !== cleanCounts.length || len !== yMops.length || len !== sweepMopModes.length || len !== names.length) {
|
|
62
|
-
throw new Error('The length of the parameters is inconsistent');
|
|
63
|
-
}
|
|
64
|
-
try {
|
|
65
|
-
const params = createSetCommonParams({
|
|
66
|
-
deviceId: devId,
|
|
67
|
-
reqType: RoomPropertyEnum.set,
|
|
68
|
-
message
|
|
69
|
-
});
|
|
70
|
-
ty.device.sendMqttMessage(params);
|
|
71
|
-
const {
|
|
72
|
-
taskId
|
|
73
|
-
} = params.message;
|
|
74
|
-
return normalResolve(RoomPropertyEnum.query, taskId);
|
|
75
|
-
} catch (error) {
|
|
76
|
-
throw error instanceof Error ? error : new Error('Failed to set room property');
|
|
77
|
-
}
|
|
45
|
+
setRoomProperty: data => {
|
|
46
|
+
return new Promise((resolve, reject) => {
|
|
47
|
+
try {
|
|
48
|
+
var _data$num, _data$suctions, _data$cisterns, _data$cleanCounts, _data$yMops, _data$sweepMopModes, _data$names;
|
|
49
|
+
if (!useMqtt) {
|
|
50
|
+
reject(new Error('useMqtt is not used'));
|
|
51
|
+
return;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
// 构建发送数据,为可选字段设置默认值
|
|
55
|
+
const {
|
|
56
|
+
ids
|
|
57
|
+
} = data;
|
|
58
|
+
const len = ids.length;
|
|
59
|
+
const sendData = {
|
|
60
|
+
num: (_data$num = data.num) !== null && _data$num !== void 0 ? _data$num : len,
|
|
61
|
+
ids,
|
|
62
|
+
suctions: (_data$suctions = data.suctions) !== null && _data$suctions !== void 0 ? _data$suctions : new Array(len).fill('closed'),
|
|
63
|
+
cisterns: (_data$cisterns = data.cisterns) !== null && _data$cisterns !== void 0 ? _data$cisterns : new Array(len).fill('closed'),
|
|
64
|
+
cleanCounts: (_data$cleanCounts = data.cleanCounts) !== null && _data$cleanCounts !== void 0 ? _data$cleanCounts : new Array(len).fill(1),
|
|
65
|
+
yMops: (_data$yMops = data.yMops) !== null && _data$yMops !== void 0 ? _data$yMops : new Array(len).fill(-1),
|
|
66
|
+
sweepMopModes: (_data$sweepMopModes = data.sweepMopModes) !== null && _data$sweepMopModes !== void 0 ? _data$sweepMopModes : new Array(len).fill('only_sweep'),
|
|
67
|
+
names: (_data$names = data.names) !== null && _data$names !== void 0 ? _data$names : new Array(len).fill(''),
|
|
68
|
+
floorTypes: data.floorTypes,
|
|
69
|
+
orders: data.orders
|
|
70
|
+
};
|
|
71
|
+
|
|
72
|
+
// 使用 TypeBox Schema 进行参数验证(包含自定义验证逻辑)
|
|
73
|
+
const validatedData = validator.validate('set_room_property', sendData);
|
|
74
|
+
sendStructuredMessage(RoomPropertyEnum.set, validatedData, resolve, error => reject(handleMqttError(error, 'Failed to set room property')), RoomPropertyEnum.query // 响应类型是 query,不是 set
|
|
75
|
+
);
|
|
76
|
+
} catch (error) {
|
|
77
|
+
reject(handleMqttError(error, 'Failed to set room property'));
|
|
78
|
+
}
|
|
79
|
+
});
|
|
78
80
|
}
|
|
79
81
|
};
|
|
80
82
|
};
|
|
@@ -1,30 +1,10 @@
|
|
|
1
|
-
import {
|
|
2
|
-
type ScheduleItem = Pick<RoomPreference, 'suctions' | 'cisterns' | 'cleanCounts' | 'yMops' | 'sweepMopModes' | 'ids'> & {
|
|
3
|
-
active: number;
|
|
4
|
-
cycle: number[];
|
|
5
|
-
time: number[];
|
|
6
|
-
};
|
|
7
|
-
interface Schedule {
|
|
8
|
-
list: Array<ScheduleItem>;
|
|
9
|
-
num: number;
|
|
10
|
-
version?: string;
|
|
11
|
-
}
|
|
12
|
-
interface ScheduleResponse extends BaseResponse {
|
|
13
|
-
reqType: ScheduleEnum.query;
|
|
14
|
-
list: Array<ScheduleItem>;
|
|
15
|
-
num: number;
|
|
16
|
-
}
|
|
17
|
-
type TRequestSchedule = (message?: {
|
|
18
|
-
version?: string;
|
|
19
|
-
}) => Promise<ScheduleResponse>;
|
|
20
|
-
type TSetSchedule = (message: Schedule) => Promise<ScheduleResponse>;
|
|
1
|
+
import { type TRequestSchedule, type TSetSchedule } from './type/protocols';
|
|
21
2
|
/**
|
|
22
3
|
* 自定义 Hook,用于定时任务
|
|
23
|
-
* @param devId 设备ID
|
|
4
|
+
* @param devId 设备ID(可选,如果不提供则从 MqttProvider Context 获取)
|
|
24
5
|
* @returns 包含 requestSchedule 和 setSchedule 函数的对象
|
|
25
6
|
*/
|
|
26
|
-
export declare const useSchedule: (
|
|
7
|
+
export declare const useSchedule: () => {
|
|
27
8
|
requestSchedule: TRequestSchedule;
|
|
28
9
|
setSchedule: TSetSchedule;
|
|
29
10
|
};
|
|
30
|
-
export {};
|