@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.
Files changed (156) hide show
  1. package/lib/mqtt/createCommonOptions.d.ts +4 -2
  2. package/lib/mqtt/createCommonOptions.js +10 -5
  3. package/lib/mqtt/hooks/useStructuredMessage.d.ts +14 -0
  4. package/lib/mqtt/hooks/useStructuredMessage.js +131 -0
  5. package/lib/mqtt/mqttProvider.d.ts +19 -1
  6. package/lib/mqtt/mqttProvider.js +69 -8
  7. package/lib/mqtt/promise.d.ts +57 -4
  8. package/lib/mqtt/promise.js +115 -36
  9. package/lib/mqtt/type/fun.d.ts +49 -0
  10. package/lib/mqtt/type/fun.js +145 -0
  11. package/lib/mqtt/type/index.d.ts +0 -7
  12. package/lib/mqtt/type/index.js +0 -1
  13. package/lib/mqtt/type/protocols/base.d.ts +5 -0
  14. package/lib/mqtt/type/protocols/base.js +32 -0
  15. package/lib/mqtt/type/protocols/carpetCleanProtocol.d.ts +8 -0
  16. package/lib/mqtt/type/protocols/carpetCleanProtocol.js +16 -0
  17. package/lib/mqtt/type/protocols/carpetProtocol.d.ts +41 -0
  18. package/lib/mqtt/type/protocols/carpetProtocol.js +202 -0
  19. package/lib/mqtt/type/protocols/devInfoProtocol.d.ts +5 -0
  20. package/lib/mqtt/type/protocols/devInfoProtocol.js +12 -0
  21. package/lib/mqtt/type/protocols/deviceModelProtocol.d.ts +8 -0
  22. package/lib/mqtt/type/protocols/deviceModelProtocol.js +34 -0
  23. package/lib/mqtt/type/protocols/furnitureModelProtocol.d.ts +10 -0
  24. package/lib/mqtt/type/protocols/furnitureModelProtocol.js +35 -0
  25. package/lib/mqtt/type/protocols/historyMapProtocol.d.ts +17 -0
  26. package/lib/mqtt/type/protocols/historyMapProtocol.js +37 -0
  27. package/lib/mqtt/type/protocols/index.d.ts +20 -0
  28. package/lib/mqtt/type/protocols/index.js +20 -0
  29. package/lib/mqtt/type/protocols/partDivisionProtocol.d.ts +8 -0
  30. package/lib/mqtt/type/protocols/partDivisionProtocol.js +12 -0
  31. package/lib/mqtt/type/protocols/partMergeProtocol.d.ts +7 -0
  32. package/lib/mqtt/type/protocols/partMergeProtocol.js +12 -0
  33. package/lib/mqtt/type/protocols/passwordProtocol.d.ts +11 -0
  34. package/lib/mqtt/type/protocols/passwordProtocol.js +25 -0
  35. package/lib/mqtt/type/protocols/quietHoursProtocol.d.ts +8 -0
  36. package/lib/mqtt/type/protocols/quietHoursProtocol.js +35 -0
  37. package/lib/mqtt/type/protocols/resetMapProtocol.d.ts +4 -0
  38. package/lib/mqtt/type/protocols/resetMapProtocol.js +1 -0
  39. package/lib/mqtt/type/protocols/roomPropertyProtocol.d.ts +14 -0
  40. package/lib/mqtt/type/protocols/roomPropertyProtocol.js +113 -0
  41. package/lib/mqtt/type/protocols/scheduleProtocol.d.ts +18 -0
  42. package/lib/mqtt/type/protocols/scheduleProtocol.js +100 -0
  43. package/lib/mqtt/type/protocols/selectRoomCleanProtocol.d.ts +8 -0
  44. package/lib/mqtt/type/protocols/selectRoomCleanProtocol.js +40 -0
  45. package/lib/mqtt/type/protocols/spotCleanProtocol.d.ts +9 -0
  46. package/lib/mqtt/type/protocols/spotCleanProtocol.js +72 -0
  47. package/lib/mqtt/type/protocols/virtualAreaProtocol.d.ts +8 -0
  48. package/lib/mqtt/type/protocols/virtualAreaProtocol.js +36 -0
  49. package/lib/mqtt/type/protocols/virtualWallProtocol.d.ts +8 -0
  50. package/lib/mqtt/type/protocols/virtualWallProtocol.js +25 -0
  51. package/lib/mqtt/type/protocols/voiceProtocol.d.ts +8 -0
  52. package/lib/mqtt/type/protocols/voiceProtocol.js +23 -0
  53. package/lib/mqtt/type/protocols/wifiMapProtocol.d.ts +8 -0
  54. package/lib/mqtt/type/protocols/wifiMapProtocol.js +14 -0
  55. package/lib/mqtt/type/protocols/zoneCleanProtocol.d.ts +8 -0
  56. package/lib/mqtt/type/protocols/zoneCleanProtocol.js +49 -0
  57. package/lib/mqtt/useCarpet.d.ts +7 -67
  58. package/lib/mqtt/useCarpet.js +101 -181
  59. package/lib/mqtt/useCarpetClean.d.ts +2 -11
  60. package/lib/mqtt/useCarpetClean.js +24 -51
  61. package/lib/mqtt/useDevInfo.d.ts +8 -6
  62. package/lib/mqtt/useDevInfo.js +44 -36
  63. package/lib/mqtt/useDeviceModel.d.ts +6 -19
  64. package/lib/mqtt/useDeviceModel.js +29 -42
  65. package/lib/mqtt/useFurnitureModel.d.ts +6 -18
  66. package/lib/mqtt/useFurnitureModel.js +29 -43
  67. package/lib/mqtt/useHistoryMap.d.ts +2 -18
  68. package/lib/mqtt/useHistoryMap.js +102 -119
  69. package/lib/mqtt/usePartDivision.d.ts +2 -9
  70. package/lib/mqtt/usePartDivision.js +48 -57
  71. package/lib/mqtt/usePartMerge.d.ts +2 -8
  72. package/lib/mqtt/usePartMerge.js +34 -49
  73. package/lib/mqtt/usePassword.d.ts +6 -13
  74. package/lib/mqtt/usePassword.js +84 -74
  75. package/lib/mqtt/useQuiteHours.d.ts +4 -37
  76. package/lib/mqtt/useQuiteHours.js +66 -100
  77. package/lib/mqtt/useResetMap.d.ts +2 -8
  78. package/lib/mqtt/useResetMap.js +27 -34
  79. package/lib/mqtt/useRoomProperty.d.ts +8 -9
  80. package/lib/mqtt/useRoomProperty.js +67 -65
  81. package/lib/mqtt/useSchedule.d.ts +3 -23
  82. package/lib/mqtt/useSchedule.js +72 -101
  83. package/lib/mqtt/useSelectRoomClean.d.ts +3 -24
  84. package/lib/mqtt/useSelectRoomClean.js +107 -133
  85. package/lib/mqtt/useSpotClean.d.ts +5 -15
  86. package/lib/mqtt/useSpotClean.js +68 -121
  87. package/lib/mqtt/useVirtualArea.d.ts +6 -17
  88. package/lib/mqtt/useVirtualArea.js +109 -119
  89. package/lib/mqtt/useVirtualWall.d.ts +2 -18
  90. package/lib/mqtt/useVirtualWall.js +69 -90
  91. package/lib/mqtt/useVoice.d.ts +2 -16
  92. package/lib/mqtt/useVoice.js +48 -68
  93. package/lib/mqtt/useWifiMap.d.ts +6 -5
  94. package/lib/mqtt/useWifiMap.js +43 -42
  95. package/lib/mqtt/useZoneClean.d.ts +2 -21
  96. package/lib/mqtt/useZoneClean.js +125 -137
  97. package/lib/myLib/zod/mini/index.d.cts +1 -0
  98. package/lib/myLib/zod/mini/index.d.ts +1 -0
  99. package/lib/myLib/zod/mini/index.js +1 -0
  100. package/lib/myLib/zod/mini/package.json +6 -0
  101. package/lib/myLib/zod/src/mini/index.d.ts +1 -0
  102. package/lib/myLib/zod/src/mini/index.js +1 -0
  103. package/lib/myLib/zod/src/v4/core/api.d.ts +306 -0
  104. package/lib/myLib/zod/src/v4/core/api.js +1256 -0
  105. package/lib/myLib/zod/src/v4/core/checks.d.ts +278 -0
  106. package/lib/myLib/zod/src/v4/core/checks.js +816 -0
  107. package/lib/myLib/zod/src/v4/core/config.d.ts +9 -0
  108. package/lib/myLib/zod/src/v4/core/config.js +5 -0
  109. package/lib/myLib/zod/src/v4/core/core.d.ts +70 -0
  110. package/lib/myLib/zod/src/v4/core/core.js +95 -0
  111. package/lib/myLib/zod/src/v4/core/doc.d.ts +14 -0
  112. package/lib/myLib/zod/src/v4/core/doc.js +42 -0
  113. package/lib/myLib/zod/src/v4/core/errors.d.ts +220 -0
  114. package/lib/myLib/zod/src/v4/core/errors.js +232 -0
  115. package/lib/myLib/zod/src/v4/core/index.d.ts +15 -0
  116. package/lib/myLib/zod/src/v4/core/index.js +15 -0
  117. package/lib/myLib/zod/src/v4/core/json-schema-generator.d.ts +65 -0
  118. package/lib/myLib/zod/src/v4/core/json-schema-generator.js +120 -0
  119. package/lib/myLib/zod/src/v4/core/json-schema-processors.d.ts +49 -0
  120. package/lib/myLib/zod/src/v4/core/json-schema-processors.js +593 -0
  121. package/lib/myLib/zod/src/v4/core/json-schema.d.ts +88 -0
  122. package/lib/myLib/zod/src/v4/core/json-schema.js +1 -0
  123. package/lib/myLib/zod/src/v4/core/parse.d.ts +49 -0
  124. package/lib/myLib/zod/src/v4/core/parse.js +147 -0
  125. package/lib/myLib/zod/src/v4/core/regexes.d.ts +78 -0
  126. package/lib/myLib/zod/src/v4/core/regexes.js +146 -0
  127. package/lib/myLib/zod/src/v4/core/registries.d.ts +35 -0
  128. package/lib/myLib/zod/src/v4/core/registries.js +51 -0
  129. package/lib/myLib/zod/src/v4/core/schemas.d.ts +1136 -0
  130. package/lib/myLib/zod/src/v4/core/schemas.js +2745 -0
  131. package/lib/myLib/zod/src/v4/core/standard-schema.d.ts +126 -0
  132. package/lib/myLib/zod/src/v4/core/standard-schema.js +1 -0
  133. package/lib/myLib/zod/src/v4/core/to-json-schema.d.ts +114 -0
  134. package/lib/myLib/zod/src/v4/core/to-json-schema.js +488 -0
  135. package/lib/myLib/zod/src/v4/core/util.d.ts +199 -0
  136. package/lib/myLib/zod/src/v4/core/util.js +656 -0
  137. package/lib/myLib/zod/src/v4/core/versions.d.ts +5 -0
  138. package/lib/myLib/zod/src/v4/core/versions.js +5 -0
  139. package/lib/myLib/zod/src/v4/core/zsf.d.ts +91 -0
  140. package/lib/myLib/zod/src/v4/core/zsf.js +1 -0
  141. package/lib/myLib/zod/src/v4/mini/checks.d.ts +1 -0
  142. package/lib/myLib/zod/src/v4/mini/checks.js +1 -0
  143. package/lib/myLib/zod/src/v4/mini/coerce.d.ts +7 -0
  144. package/lib/myLib/zod/src/v4/mini/coerce.js +27 -0
  145. package/lib/myLib/zod/src/v4/mini/external.d.ts +11 -0
  146. package/lib/myLib/zod/src/v4/mini/external.js +16 -0
  147. package/lib/myLib/zod/src/v4/mini/index.d.ts +3 -0
  148. package/lib/myLib/zod/src/v4/mini/index.js +3 -0
  149. package/lib/myLib/zod/src/v4/mini/iso.d.ts +22 -0
  150. package/lib/myLib/zod/src/v4/mini/iso.js +46 -0
  151. package/lib/myLib/zod/src/v4/mini/parse.d.ts +1 -0
  152. package/lib/myLib/zod/src/v4/mini/parse.js +1 -0
  153. package/lib/myLib/zod/src/v4/mini/schemas.js +1244 -0
  154. package/lib/utils/index.d.ts +1 -0
  155. package/lib/utils/index.js +2 -1
  156. 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 = devId => {
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
- try {
47
- if (useMqtt) {
48
- const params = createSetCommonParams({
49
- deviceId: devId,
50
- reqType: VirtualWallEnum.query
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
- // 非 MQTT 模式:使用命令传输
60
- devices.common.model.actions.command_trans.set(requestVirtualWall0x13({
61
- version: commandVersion
62
- }));
47
+ // 非 MQTT 模式:使用命令传输
48
+ devices.common.model.actions.command_trans.set(requestVirtualWall0x13({
49
+ version: commandVersion
50
+ }));
63
51
 
64
- // 非 MQTT 模式下无法立即获取响应数据,返回默认响应
65
- return Promise.resolve({
66
- success: true,
67
- errCode: 0,
68
- reqType: VirtualWallEnum.query,
69
- version: commandVersion,
70
- taskId: `${Date.now()}`,
71
- num: 0,
72
- modes: [],
73
- points: [],
74
- mapId: 0
75
- });
76
- } catch (error) {
77
- return Promise.reject(error instanceof Error ? error : new Error('Failed to request virtual wall'));
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: _ref => {
81
- let {
82
- data,
83
- origin
84
- } = _ref;
85
- // 参数验证
86
- if (!Array.isArray(data)) {
87
- throw new Error('data is required and must be a non-empty array');
88
- }
89
- if (!origin || typeof origin.x !== 'number' || typeof origin.y !== 'number') {
90
- throw new Error('origin is required and must be a valid Point object with x and y properties');
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
- ty.device.sendMqttMessage(params);
104
- const {
105
- taskId
106
- } = params.message;
107
- return normalResolve(VirtualWallEnum.query, taskId);
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
  };
@@ -1,24 +1,10 @@
1
- import { BaseResponse, VoiceLanguageEnum } from './type';
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: (devId: string) => {
6
+ export declare const useVoice: () => {
20
7
  requestAllVoices: () => Promise<ty.GetVoiceListResponse>;
21
8
  requestVoiceInUse: TRequestVoiceInUse;
22
9
  setVoice: TSetVoice;
23
10
  };
24
- export {};
@@ -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 = devId => {
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
- if (!useMqtt) {
58
- return Promise.reject(new Error('useMqtt is not used'));
59
- }
60
- try {
61
- const params = createSetCommonParams({
62
- deviceId: devId,
63
- reqType: VoiceLanguageEnum.query
64
- });
65
- const {
66
- taskId
67
- } = params.message;
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
- if (!message || typeof message.id !== 'number') {
77
- throw new Error('message.id is required and must be a number');
78
- }
79
- if (!message.url || typeof message.url !== 'string') {
80
- throw new Error('message.url is required and must be a string');
81
- }
82
- if (!message.md5 || typeof message.md5 !== 'string') {
83
- throw new Error('message.md5 is required and must be a string');
84
- }
85
- try {
86
- if (useMqtt) {
87
- const sendData = _objectSpread(_objectSpread({}, message), {}, {
88
- urlLen: message.url.length
89
- });
90
- const params = createSetCommonParams({
91
- deviceId: devId,
92
- reqType: VoiceLanguageEnum.set,
93
- message: sendData
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
- ty.device.sendMqttMessage(params);
96
- const {
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
  };
@@ -1,8 +1,9 @@
1
- import { PromiseWithRejection } from './promise';
2
- type TRequestWifiMap = () => PromiseWithRejection | Promise<void>;
3
- type TSetWifiMap = () => PromiseWithRejection;
4
- export declare const useWifiMap: (devId: string) => {
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 {};
@@ -1,53 +1,54 @@
1
- import { createSetCommonParams } from './createCommonOptions';
2
- import { normalResolve } from './promise';
3
1
  import { WifiMapEnum } from './type';
4
- import { useContext } from 'react';
5
- import { SingletonContext } from './mqttProvider';
6
- export const useWifiMap = devId => {
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
- useMqtt
9
- } = useContext(SingletonContext);
10
+ sendStructuredMessage
11
+ } = useStructuredMessage();
10
12
 
11
- // 请求 WiFi 地图状态
13
+ /**
14
+ * 请求 WiFi 地图状态
15
+ * @param data 可选参数(目前为空对象)
16
+ * @returns Promise<WifiMapResponse> 响应结果
17
+ */
12
18
 
13
- // 设置 WiFi 地图
19
+ /**
20
+ * 设置 WiFi 地图
21
+ * @param data 包含 taskId 的参数对象(taskId 可选,不提供时自动生成)
22
+ * @returns Promise<WifiMapResponse> 响应结果
23
+ */
14
24
 
15
25
  return {
16
26
  requestWifiMap: () => {
17
- if (!useMqtt) {
18
- return Promise.reject(new Error('useMqtt is not used'));
19
- }
20
- try {
21
- const params = createSetCommonParams({
22
- deviceId: devId,
23
- reqType: WifiMapEnum.query
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
- try {
36
- const params = createSetCommonParams({
37
- deviceId: devId,
38
- reqType: WifiMapEnum.set,
39
- message: {
40
- taskId: String(Date.now())
41
- }
42
- });
43
- ty.device.sendMqttMessage(params);
44
- const {
45
- taskId
46
- } = params.message;
47
- return normalResolve(WifiMapEnum.rst, taskId);
48
- } catch (error) {
49
- throw error instanceof Error ? error : new Error('Failed to set WiFi map');
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 { BaseResponse, ZoneCleanEnum, RoomPreference } from './type';
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: (devId: string) => {
6
+ export declare const useZoneClean: () => {
25
7
  requestZoneClean: TRequestZoneClean;
26
8
  setZoneClean: TSetZoneClean;
27
9
  };
28
- export {};