@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,35 +1,29 @@
|
|
|
1
1
|
import "core-js/modules/esnext.iterator.map.js";
|
|
2
2
|
// 虚拟墙数据
|
|
3
3
|
import { useContext } from 'react';
|
|
4
|
-
import { createSetCommonParams } from './createCommonOptions';
|
|
5
|
-
import { normalResolve } from './promise';
|
|
6
4
|
import { VirtualWallEnum } from './type';
|
|
7
5
|
import { SingletonContext } from './mqttProvider';
|
|
8
6
|
import { encodeVirtualWall0x12, requestVirtualWall0x13 } from '@ray-js/robot-protocol';
|
|
9
7
|
import { pointsToString } from '../utils';
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
// 设置虚拟墙参数类型
|
|
14
|
-
|
|
15
|
-
// 请求虚拟墙函数类型定义
|
|
16
|
-
|
|
17
|
-
// 设置虚拟墙函数类型定义
|
|
18
|
-
|
|
8
|
+
import { useStructuredMessage, handleMqttError } from './hooks/useStructuredMessage';
|
|
9
|
+
import { validator } from './type/fun';
|
|
19
10
|
/**
|
|
20
11
|
* 自定义 Hook,用于虚拟墙管理
|
|
21
|
-
* @param devId 设备ID
|
|
22
12
|
* @returns 包含 requestVirtualWall 和 setVirtualWall 函数的对象
|
|
23
13
|
*/
|
|
24
|
-
export const useVirtualWall =
|
|
14
|
+
export const useVirtualWall = () => {
|
|
25
15
|
const {
|
|
26
16
|
useMqtt,
|
|
27
17
|
commandVersion,
|
|
28
18
|
devices
|
|
29
19
|
} = useContext(SingletonContext);
|
|
20
|
+
const {
|
|
21
|
+
sendStructuredMessage
|
|
22
|
+
} = useStructuredMessage();
|
|
30
23
|
|
|
31
24
|
/**
|
|
32
25
|
* 请求虚拟墙数据
|
|
26
|
+
* @param data 可选参数(目前为空对象)
|
|
33
27
|
* @returns Promise<VirtualWallResponse> 响应结果
|
|
34
28
|
*/
|
|
35
29
|
|
|
@@ -43,91 +37,76 @@ export const useVirtualWall = devId => {
|
|
|
43
37
|
|
|
44
38
|
return {
|
|
45
39
|
requestVirtualWall: () => {
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
}
|
|
52
|
-
ty.device.sendMqttMessage(params);
|
|
53
|
-
const {
|
|
54
|
-
taskId
|
|
55
|
-
} = params.message;
|
|
56
|
-
return normalResolve(VirtualWallEnum.query, taskId);
|
|
57
|
-
}
|
|
40
|
+
return new Promise((resolve, reject) => {
|
|
41
|
+
try {
|
|
42
|
+
if (useMqtt) {
|
|
43
|
+
sendStructuredMessage(VirtualWallEnum.query, {}, resolve, error => reject(handleMqttError(error, 'Failed to request virtual wall')));
|
|
44
|
+
return;
|
|
45
|
+
}
|
|
58
46
|
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
47
|
+
// 非 MQTT 模式:使用命令传输
|
|
48
|
+
devices.common.model.actions.command_trans.set(requestVirtualWall0x13({
|
|
49
|
+
version: commandVersion
|
|
50
|
+
}));
|
|
63
51
|
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
52
|
+
// 非 MQTT 模式下无法立即获取响应数据,返回默认响应
|
|
53
|
+
resolve({
|
|
54
|
+
success: true,
|
|
55
|
+
errCode: 0,
|
|
56
|
+
reqType: VirtualWallEnum.query,
|
|
57
|
+
version: commandVersion,
|
|
58
|
+
taskId: `${Date.now()}`,
|
|
59
|
+
num: 0,
|
|
60
|
+
modes: [],
|
|
61
|
+
points: [],
|
|
62
|
+
mapId: 0
|
|
63
|
+
});
|
|
64
|
+
} catch (error) {
|
|
65
|
+
reject(handleMqttError(error, 'Failed to request virtual wall'));
|
|
66
|
+
}
|
|
67
|
+
});
|
|
79
68
|
},
|
|
80
|
-
setVirtualWall:
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
}
|
|
92
|
-
try {
|
|
93
|
-
if (useMqtt) {
|
|
94
|
-
const params = createSetCommonParams({
|
|
95
|
-
deviceId: devId,
|
|
96
|
-
reqType: VirtualWallEnum.set,
|
|
97
|
-
message: {
|
|
69
|
+
setVirtualWall: params => {
|
|
70
|
+
return new Promise((resolve, reject) => {
|
|
71
|
+
try {
|
|
72
|
+
// 使用 TypeBox Schema 进行参数验证
|
|
73
|
+
const validatedData = validator.validate('set_virtual_wall', params);
|
|
74
|
+
const {
|
|
75
|
+
data,
|
|
76
|
+
origin
|
|
77
|
+
} = validatedData;
|
|
78
|
+
if (useMqtt) {
|
|
79
|
+
sendStructuredMessage(VirtualWallEnum.set, {
|
|
98
80
|
points: data.map(points => pointsToString(points, origin)),
|
|
99
81
|
num: data.length,
|
|
100
82
|
mode: new Array(data.length).fill('0')
|
|
101
|
-
}
|
|
83
|
+
}, resolve, error => reject(handleMqttError(error, 'Failed to set virtual wall')), VirtualWallEnum.query // 响应类型是 query,不是 set
|
|
84
|
+
);
|
|
85
|
+
return;
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
// 非 MQTT 模式:使用命令传输
|
|
89
|
+
const command = encodeVirtualWall0x12({
|
|
90
|
+
version: commandVersion,
|
|
91
|
+
origin,
|
|
92
|
+
walls: data
|
|
102
93
|
});
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
94
|
+
devices.common.model.actions.command_trans.set(command);
|
|
95
|
+
resolve({
|
|
96
|
+
success: true,
|
|
97
|
+
errCode: 0,
|
|
98
|
+
reqType: VirtualWallEnum.query,
|
|
99
|
+
version: commandVersion,
|
|
100
|
+
taskId: `${Date.now()}`,
|
|
101
|
+
num: data.length,
|
|
102
|
+
modes: new Array(data.length).fill(0),
|
|
103
|
+
points: data.map(points => pointsToString(points, origin)),
|
|
104
|
+
mapId: 0
|
|
105
|
+
});
|
|
106
|
+
} catch (error) {
|
|
107
|
+
reject(handleMqttError(error, 'Failed to set virtual wall'));
|
|
108
108
|
}
|
|
109
|
-
|
|
110
|
-
// 非 MQTT 模式:使用命令传输
|
|
111
|
-
const command = encodeVirtualWall0x12({
|
|
112
|
-
version: commandVersion,
|
|
113
|
-
origin,
|
|
114
|
-
walls: data
|
|
115
|
-
});
|
|
116
|
-
devices.common.model.actions.command_trans.set(command);
|
|
117
|
-
return Promise.resolve({
|
|
118
|
-
success: true,
|
|
119
|
-
errCode: 0,
|
|
120
|
-
reqType: VirtualWallEnum.query,
|
|
121
|
-
version: commandVersion,
|
|
122
|
-
taskId: `${Date.now()}`,
|
|
123
|
-
num: data.length,
|
|
124
|
-
modes: new Array(data.length).fill(0),
|
|
125
|
-
points: data.map(points => pointsToString(points, origin)),
|
|
126
|
-
mapId: 0
|
|
127
|
-
});
|
|
128
|
-
} catch (error) {
|
|
129
|
-
throw error instanceof Error ? error : new Error('Failed to set virtual wall');
|
|
130
|
-
}
|
|
109
|
+
});
|
|
131
110
|
}
|
|
132
111
|
};
|
|
133
112
|
};
|
package/lib/mqtt/useVoice.d.ts
CHANGED
|
@@ -1,24 +1,10 @@
|
|
|
1
|
-
import {
|
|
2
|
-
interface VoiceLanguageResponse extends BaseResponse {
|
|
3
|
-
reqType: VoiceLanguageEnum.query;
|
|
4
|
-
id: number;
|
|
5
|
-
schedule: number;
|
|
6
|
-
status: number;
|
|
7
|
-
}
|
|
8
|
-
type TSetVoice = (message: {
|
|
9
|
-
id: number;
|
|
10
|
-
url: string;
|
|
11
|
-
md5: string;
|
|
12
|
-
}) => Promise<VoiceLanguageResponse>;
|
|
13
|
-
type TRequestVoiceInUse = () => Promise<VoiceLanguageResponse>;
|
|
1
|
+
import { type TSetVoice, type TRequestVoiceInUse } from './type/protocols';
|
|
14
2
|
/**
|
|
15
3
|
* 自定义 Hook,用于语音语言设置
|
|
16
|
-
* @param devId 设备ID
|
|
17
4
|
* @returns 包含 requestAllVoices, requestVoiceInUse 和 setVoice 函数的对象
|
|
18
5
|
*/
|
|
19
|
-
export declare const useVoice: (
|
|
6
|
+
export declare const useVoice: () => {
|
|
20
7
|
requestAllVoices: () => Promise<ty.GetVoiceListResponse>;
|
|
21
8
|
requestVoiceInUse: TRequestVoiceInUse;
|
|
22
9
|
setVoice: TSetVoice;
|
|
23
10
|
};
|
|
24
|
-
export {};
|
package/lib/mqtt/useVoice.js
CHANGED
|
@@ -1,29 +1,27 @@
|
|
|
1
1
|
import _objectSpread from "@babel/runtime/helpers/esm/objectSpread2";
|
|
2
2
|
import { getVoiceList } from '@ray-js/ray';
|
|
3
|
-
import { createSetCommonParams } from './createCommonOptions';
|
|
4
|
-
import { normalResolve } from './promise';
|
|
5
3
|
import { VoiceLanguageEnum } from './type';
|
|
6
4
|
import { useContext } from 'react';
|
|
7
5
|
import { SingletonContext } from './mqttProvider';
|
|
8
6
|
import { encodeVoice0x34 } from '@ray-js/robot-protocol';
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
// 设置语音语言函数类型定义
|
|
13
|
-
|
|
14
|
-
// 请求当前使用的机器语音
|
|
15
|
-
|
|
7
|
+
import { useStructuredMessage, handleMqttError } from './hooks/useStructuredMessage';
|
|
8
|
+
import { validator } from './type/fun';
|
|
16
9
|
/**
|
|
17
10
|
* 自定义 Hook,用于语音语言设置
|
|
18
|
-
* @param devId 设备ID
|
|
19
11
|
* @returns 包含 requestAllVoices, requestVoiceInUse 和 setVoice 函数的对象
|
|
20
12
|
*/
|
|
21
|
-
export const useVoice =
|
|
13
|
+
export const useVoice = () => {
|
|
22
14
|
const {
|
|
23
15
|
useMqtt,
|
|
24
16
|
devices,
|
|
25
17
|
commandVersion
|
|
26
18
|
} = useContext(SingletonContext);
|
|
19
|
+
const {
|
|
20
|
+
sendStructuredMessage
|
|
21
|
+
} = useStructuredMessage();
|
|
22
|
+
const {
|
|
23
|
+
devId
|
|
24
|
+
} = devices.common.getDevInfo();
|
|
27
25
|
/**
|
|
28
26
|
* 请求所有语音语言
|
|
29
27
|
* @returns Promise<ty.GetVoiceListResponse> 响应结果
|
|
@@ -31,6 +29,7 @@ export const useVoice = devId => {
|
|
|
31
29
|
|
|
32
30
|
/**
|
|
33
31
|
* 请求当前使用的语音语言
|
|
32
|
+
* @param data 可选参数(目前为空对象)
|
|
34
33
|
* @returns Promise<VoiceLanguageResponse> 响应结果
|
|
35
34
|
*/
|
|
36
35
|
|
|
@@ -54,67 +53,48 @@ export const useVoice = devId => {
|
|
|
54
53
|
}
|
|
55
54
|
},
|
|
56
55
|
requestVoiceInUse: () => {
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
})
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
ty.device.sendMqttMessage(params);
|
|
69
|
-
return normalResolve(VoiceLanguageEnum.query, taskId);
|
|
70
|
-
} catch (error) {
|
|
71
|
-
return Promise.reject(error instanceof Error ? error : new Error('Failed to request voice in use'));
|
|
72
|
-
}
|
|
56
|
+
return new Promise((resolve, reject) => {
|
|
57
|
+
try {
|
|
58
|
+
if (!useMqtt) {
|
|
59
|
+
reject(new Error('useMqtt is not used'));
|
|
60
|
+
return;
|
|
61
|
+
}
|
|
62
|
+
sendStructuredMessage(VoiceLanguageEnum.query, {}, resolve, error => reject(handleMqttError(error, 'Failed to request voice in use')));
|
|
63
|
+
} catch (error) {
|
|
64
|
+
reject(handleMqttError(error, 'Failed to request voice in use'));
|
|
65
|
+
}
|
|
66
|
+
});
|
|
73
67
|
},
|
|
74
68
|
setVoice: message => {
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
69
|
+
return new Promise((resolve, reject) => {
|
|
70
|
+
try {
|
|
71
|
+
// 使用 TypeBox Schema 进行参数验证
|
|
72
|
+
const validatedData = validator.validate('set_voice', message);
|
|
73
|
+
if (useMqtt) {
|
|
74
|
+
const sendData = _objectSpread(_objectSpread({}, validatedData), {}, {
|
|
75
|
+
urlLen: validatedData.url.length
|
|
76
|
+
});
|
|
77
|
+
sendStructuredMessage(VoiceLanguageEnum.set, sendData, resolve, error => reject(handleMqttError(error, 'Failed to set voice')), VoiceLanguageEnum.query);
|
|
78
|
+
return;
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
// 非 MQTT 模式:使用命令传输
|
|
82
|
+
const command = encodeVoice0x34(validatedData);
|
|
83
|
+
devices.common.model.actions.voice_data.set(command);
|
|
84
|
+
resolve({
|
|
85
|
+
success: true,
|
|
86
|
+
errCode: 0,
|
|
87
|
+
reqType: VoiceLanguageEnum.query,
|
|
88
|
+
version: commandVersion,
|
|
89
|
+
taskId: `${Date.now()}`,
|
|
90
|
+
id: validatedData.id,
|
|
91
|
+
schedule: 0,
|
|
92
|
+
status: 0
|
|
94
93
|
});
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
taskId
|
|
98
|
-
} = params.message;
|
|
99
|
-
return normalResolve(VoiceLanguageEnum.query, taskId);
|
|
94
|
+
} catch (error) {
|
|
95
|
+
reject(handleMqttError(error, 'Failed to set voice'));
|
|
100
96
|
}
|
|
101
|
-
|
|
102
|
-
// 非 MQTT 模式:使用命令传输
|
|
103
|
-
const command = encodeVoice0x34(message);
|
|
104
|
-
devices.common.model.actions.voice_data.set(command);
|
|
105
|
-
return Promise.resolve({
|
|
106
|
-
success: true,
|
|
107
|
-
errCode: 0,
|
|
108
|
-
reqType: VoiceLanguageEnum.query,
|
|
109
|
-
version: commandVersion,
|
|
110
|
-
taskId: `${Date.now()}`,
|
|
111
|
-
id: message.id,
|
|
112
|
-
schedule: 0,
|
|
113
|
-
status: 0
|
|
114
|
-
});
|
|
115
|
-
} catch (error) {
|
|
116
|
-
throw error instanceof Error ? error : new Error('Failed to set voice');
|
|
117
|
-
}
|
|
97
|
+
});
|
|
118
98
|
}
|
|
119
99
|
};
|
|
120
100
|
};
|
package/lib/mqtt/useWifiMap.d.ts
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
1
|
+
import { type TRequestWifiMap, type TSetWifiMap } from './type/protocols';
|
|
2
|
+
/**
|
|
3
|
+
* 自定义 Hook,用于 WiFi 地图管理
|
|
4
|
+
* @returns 包含 requestWifiMap 和 setWifiMap 函数的对象
|
|
5
|
+
*/
|
|
6
|
+
export declare const useWifiMap: () => {
|
|
5
7
|
requestWifiMap: TRequestWifiMap;
|
|
6
8
|
setWifiMap: TSetWifiMap;
|
|
7
9
|
};
|
|
8
|
-
export {};
|
package/lib/mqtt/useWifiMap.js
CHANGED
|
@@ -1,53 +1,54 @@
|
|
|
1
|
-
import { createSetCommonParams } from './createCommonOptions';
|
|
2
|
-
import { normalResolve } from './promise';
|
|
3
1
|
import { WifiMapEnum } from './type';
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
6
|
-
|
|
2
|
+
import { useStructuredMessage, handleMqttError } from './hooks/useStructuredMessage';
|
|
3
|
+
import { validator } from './type/fun';
|
|
4
|
+
/**
|
|
5
|
+
* 自定义 Hook,用于 WiFi 地图管理
|
|
6
|
+
* @returns 包含 requestWifiMap 和 setWifiMap 函数的对象
|
|
7
|
+
*/
|
|
8
|
+
export const useWifiMap = () => {
|
|
7
9
|
const {
|
|
8
|
-
|
|
9
|
-
} =
|
|
10
|
+
sendStructuredMessage
|
|
11
|
+
} = useStructuredMessage();
|
|
10
12
|
|
|
11
|
-
|
|
13
|
+
/**
|
|
14
|
+
* 请求 WiFi 地图状态
|
|
15
|
+
* @param data 可选参数(目前为空对象)
|
|
16
|
+
* @returns Promise<WifiMapResponse> 响应结果
|
|
17
|
+
*/
|
|
12
18
|
|
|
13
|
-
|
|
19
|
+
/**
|
|
20
|
+
* 设置 WiFi 地图
|
|
21
|
+
* @param data 包含 taskId 的参数对象(taskId 可选,不提供时自动生成)
|
|
22
|
+
* @returns Promise<WifiMapResponse> 响应结果
|
|
23
|
+
*/
|
|
14
24
|
|
|
15
25
|
return {
|
|
16
26
|
requestWifiMap: () => {
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
});
|
|
25
|
-
ty.device.sendMqttMessage(params);
|
|
26
|
-
const {
|
|
27
|
-
taskId
|
|
28
|
-
} = params.message;
|
|
29
|
-
return normalResolve(WifiMapEnum.query, taskId);
|
|
30
|
-
} catch (error) {
|
|
31
|
-
return Promise.reject(error instanceof Error ? error : new Error('Failed to request WiFi map'));
|
|
32
|
-
}
|
|
27
|
+
return new Promise((resolve, reject) => {
|
|
28
|
+
try {
|
|
29
|
+
sendStructuredMessage(WifiMapEnum.query, {}, resolve, error => reject(handleMqttError(error, 'Failed to request WiFi map')));
|
|
30
|
+
} catch (error) {
|
|
31
|
+
reject(handleMqttError(error, 'Failed to request WiFi map'));
|
|
32
|
+
}
|
|
33
|
+
});
|
|
33
34
|
},
|
|
34
|
-
setWifiMap: ()
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
taskId: String(Date.now())
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
}
|
|
35
|
+
setWifiMap: function () {
|
|
36
|
+
let data = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
|
37
|
+
return new Promise((resolve, reject) => {
|
|
38
|
+
try {
|
|
39
|
+
// 如果没有提供 taskId,自动生成
|
|
40
|
+
const wifiMapData = {
|
|
41
|
+
taskId: data.taskId || String(Date.now())
|
|
42
|
+
};
|
|
43
|
+
|
|
44
|
+
// 使用 TypeBox Schema 进行参数验证
|
|
45
|
+
const validatedData = validator.validate('set_wifi_map', wifiMapData);
|
|
46
|
+
sendStructuredMessage(WifiMapEnum.set, validatedData, resolve, error => reject(handleMqttError(error, 'Failed to set WiFi map')), WifiMapEnum.rst // 响应类型是 rst,不是 set
|
|
47
|
+
);
|
|
48
|
+
} catch (error) {
|
|
49
|
+
reject(handleMqttError(error, 'Failed to set WiFi map'));
|
|
50
|
+
}
|
|
51
|
+
});
|
|
51
52
|
}
|
|
52
53
|
};
|
|
53
54
|
};
|
|
@@ -1,28 +1,9 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { Point, Zone } from '@ray-js/robot-protocol';
|
|
3
|
-
interface ZoneCleanResponse extends BaseResponse {
|
|
4
|
-
reqType: ZoneCleanEnum.query;
|
|
5
|
-
polygons: string[];
|
|
6
|
-
names?: string[];
|
|
7
|
-
suctions?: string[];
|
|
8
|
-
cisterns?: string[];
|
|
9
|
-
cleanCounts?: number[];
|
|
10
|
-
yMops?: number[];
|
|
11
|
-
sweepMopModes?: string[];
|
|
12
|
-
}
|
|
13
|
-
interface SetZoneCleanParams extends Partial<Pick<RoomPreference, 'suctions' | 'cisterns' | 'cleanCounts' | 'yMops' | 'sweepMopModes'>> {
|
|
14
|
-
zones: Zone[];
|
|
15
|
-
origin: Point;
|
|
16
|
-
}
|
|
17
|
-
type TRequestZoneClean = () => Promise<ZoneCleanResponse>;
|
|
18
|
-
type TSetZoneClean = (params: SetZoneCleanParams) => Promise<ZoneCleanResponse>;
|
|
1
|
+
import { type TRequestZoneClean, type TSetZoneClean } from './type/protocols';
|
|
19
2
|
/**
|
|
20
3
|
* 自定义 Hook,用于划区清扫
|
|
21
|
-
* @param devId 设备ID
|
|
22
4
|
* @returns 包含 requestZoneClean 和 setZoneClean 函数的对象
|
|
23
5
|
*/
|
|
24
|
-
export declare const useZoneClean: (
|
|
6
|
+
export declare const useZoneClean: () => {
|
|
25
7
|
requestZoneClean: TRequestZoneClean;
|
|
26
8
|
setZoneClean: TSetZoneClean;
|
|
27
9
|
};
|
|
28
|
-
export {};
|