@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
package/lib/mqtt/useDevInfo.js
CHANGED
|
@@ -1,52 +1,60 @@
|
|
|
1
1
|
import { hexToUriDecodedString } from '@ray-js/robot-protocol';
|
|
2
2
|
import { useContext } from 'react';
|
|
3
|
-
import {
|
|
3
|
+
import { handleMqttError, useStructuredMessage } from './hooks/useStructuredMessage';
|
|
4
4
|
import { SingletonContext } from './mqttProvider';
|
|
5
|
-
import { normalResolve } from './promise';
|
|
6
5
|
import { DevInfoEnum } from './type';
|
|
7
6
|
|
|
8
|
-
//
|
|
7
|
+
// 导出类型供外部使用
|
|
9
8
|
|
|
10
|
-
|
|
11
|
-
|
|
9
|
+
/**
|
|
10
|
+
* 自定义 Hook,用于设备信息管理
|
|
11
|
+
* @returns 包含 requestDevInfo 函数的对象
|
|
12
|
+
*/
|
|
13
|
+
export const useDevInfo = () => {
|
|
12
14
|
const {
|
|
13
15
|
useMqtt,
|
|
14
|
-
devices
|
|
16
|
+
devices,
|
|
17
|
+
commandVersion
|
|
15
18
|
} = useContext(SingletonContext);
|
|
19
|
+
const {
|
|
20
|
+
sendStructuredMessage
|
|
21
|
+
} = useStructuredMessage();
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* 请求设备信息
|
|
25
|
+
* @returns Promise<DevInfoResponse> 响应结果,包含设备信息
|
|
26
|
+
*/
|
|
27
|
+
|
|
16
28
|
return {
|
|
17
29
|
requestDevInfo: () => {
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
taskId
|
|
27
|
-
} = params.message;
|
|
28
|
-
return normalResolve(DevInfoEnum.query, taskId);
|
|
29
|
-
}
|
|
30
|
+
return new Promise((resolve, reject) => {
|
|
31
|
+
try {
|
|
32
|
+
var _devices$common$model;
|
|
33
|
+
if (useMqtt) {
|
|
34
|
+
// request_dev_info 不需要参数,直接发送空对象
|
|
35
|
+
sendStructuredMessage(DevInfoEnum.query, {}, resolve, error => reject(handleMqttError(error, 'Failed to request device info')));
|
|
36
|
+
return;
|
|
37
|
+
}
|
|
30
38
|
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
39
|
+
// 非 MQTT 模式:从设备属性中获取设备信息
|
|
40
|
+
const dpDevInfo = (_devices$common$model = devices.common.model.props) === null || _devices$common$model === void 0 ? void 0 : _devices$common$model.device_info;
|
|
41
|
+
if (!dpDevInfo) {
|
|
42
|
+
reject(new Error('Device info is not available in device properties'));
|
|
43
|
+
return;
|
|
44
|
+
}
|
|
45
|
+
const info = hexToUriDecodedString(dpDevInfo);
|
|
46
|
+
resolve({
|
|
47
|
+
info,
|
|
48
|
+
success: true,
|
|
49
|
+
errCode: 0,
|
|
50
|
+
reqType: DevInfoEnum.query,
|
|
51
|
+
version: commandVersion || '1.0.0',
|
|
52
|
+
taskId: `${Date.now()}`
|
|
53
|
+
});
|
|
54
|
+
} catch (error) {
|
|
55
|
+
reject(handleMqttError(error, 'Failed to request device info'));
|
|
37
56
|
}
|
|
38
|
-
|
|
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
|
-
}
|
|
57
|
+
});
|
|
50
58
|
}
|
|
51
59
|
};
|
|
52
60
|
};
|
|
@@ -1,22 +1,9 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
size: [number, number, number];
|
|
8
|
-
rotation: [number, number, number];
|
|
9
|
-
position: [number, number, number];
|
|
10
|
-
subDevId: string;
|
|
11
|
-
}
|
|
12
|
-
interface DeviceModelResponse extends BaseResponse {
|
|
13
|
-
reqType: DeviceModelEnum.query;
|
|
14
|
-
modelInfo: DeviceModelInfo[];
|
|
15
|
-
}
|
|
16
|
-
type TRequestDeviceList = () => Promise<DeviceModelResponse>;
|
|
17
|
-
type TSetDeviceModel = (modelInfos: DeviceModelInfo[]) => Promise<DeviceModelResponse>;
|
|
18
|
-
export declare const useDeviceModel: (devId: string) => {
|
|
1
|
+
import { type TRequestDeviceList, type TSetDeviceModel } from './type/protocols';
|
|
2
|
+
/**
|
|
3
|
+
* 自定义 Hook,用于设备模型管理
|
|
4
|
+
* @returns 包含 requestDeviceList 和 setDeviceModel 函数的对象
|
|
5
|
+
*/
|
|
6
|
+
export declare const useDeviceModel: () => {
|
|
19
7
|
requestDeviceList: TRequestDeviceList;
|
|
20
8
|
setDeviceModel: TSetDeviceModel;
|
|
21
9
|
};
|
|
22
|
-
export {};
|
|
@@ -1,60 +1,47 @@
|
|
|
1
|
-
import { createSetCommonParams } from './createCommonOptions';
|
|
2
|
-
import { normalResolve } from './promise';
|
|
3
1
|
import { DeviceModelEnum } from './type/requestType';
|
|
2
|
+
import { useStructuredMessage, handleMqttError } from './hooks/useStructuredMessage';
|
|
3
|
+
import { validator } from './type/fun';
|
|
4
|
+
/**
|
|
5
|
+
* 自定义 Hook,用于设备模型管理
|
|
6
|
+
* @returns 包含 requestDeviceList 和 setDeviceModel 函数的对象
|
|
7
|
+
*/
|
|
8
|
+
export const useDeviceModel = () => {
|
|
9
|
+
const {
|
|
10
|
+
sendStructuredMessage
|
|
11
|
+
} = useStructuredMessage();
|
|
4
12
|
|
|
5
|
-
// 请求设备列表函数定义
|
|
6
|
-
|
|
7
|
-
// 设置设备模型函数定义
|
|
8
|
-
|
|
9
|
-
export const useDeviceModel = devId => {
|
|
10
13
|
/**
|
|
11
14
|
* 请求设备列表
|
|
15
|
+
* @param data 可选参数(目前为空对象)
|
|
12
16
|
* @returns Promise<DeviceModelResponse> 响应结果
|
|
13
17
|
*/
|
|
14
18
|
|
|
15
19
|
/**
|
|
16
20
|
* 设置设备模型
|
|
17
|
-
* @param
|
|
21
|
+
* @param data 包含设备模型信息数组的对象
|
|
18
22
|
* @returns Promise<DeviceModelResponse> 响应结果
|
|
19
23
|
*/
|
|
20
24
|
|
|
21
25
|
return {
|
|
22
26
|
requestDeviceList: () => {
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
} = params.message;
|
|
31
|
-
ty.device.sendMqttMessage(params);
|
|
32
|
-
return normalResolve(DeviceModelEnum.query, taskId);
|
|
33
|
-
} catch (error) {
|
|
34
|
-
return Promise.reject(error instanceof Error ? error : new Error('Failed to request device list'));
|
|
35
|
-
}
|
|
27
|
+
return new Promise((resolve, reject) => {
|
|
28
|
+
try {
|
|
29
|
+
sendStructuredMessage(DeviceModelEnum.query, {}, resolve, error => reject(handleMqttError(error, 'Failed to request device list')));
|
|
30
|
+
} catch (error) {
|
|
31
|
+
reject(handleMqttError(error, 'Failed to request device list'));
|
|
32
|
+
}
|
|
33
|
+
});
|
|
36
34
|
},
|
|
37
|
-
setDeviceModel:
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
modelInfos
|
|
48
|
-
}
|
|
49
|
-
});
|
|
50
|
-
ty.device.sendMqttMessage(params);
|
|
51
|
-
const {
|
|
52
|
-
taskId
|
|
53
|
-
} = params.message;
|
|
54
|
-
return normalResolve(DeviceModelEnum.query, taskId);
|
|
55
|
-
} catch (error) {
|
|
56
|
-
throw error instanceof Error ? error : new Error('Failed to set device model');
|
|
57
|
-
}
|
|
35
|
+
setDeviceModel: data => {
|
|
36
|
+
return new Promise((resolve, reject) => {
|
|
37
|
+
try {
|
|
38
|
+
// 使用 TypeBox Schema 进行参数验证
|
|
39
|
+
const validatedData = validator.validate('set_device_model', data);
|
|
40
|
+
sendStructuredMessage(DeviceModelEnum.set, validatedData, resolve, error => reject(handleMqttError(error, 'Failed to set device model')), DeviceModelEnum.query);
|
|
41
|
+
} catch (error) {
|
|
42
|
+
reject(handleMqttError(error, 'Failed to set device model'));
|
|
43
|
+
}
|
|
44
|
+
});
|
|
58
45
|
}
|
|
59
46
|
};
|
|
60
47
|
};
|
|
@@ -1,21 +1,9 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
size: [number, number, number];
|
|
8
|
-
rotation: [number, number, number];
|
|
9
|
-
position: [number, number, number];
|
|
10
|
-
}
|
|
11
|
-
interface FurnitureModelResponse extends BaseResponse {
|
|
12
|
-
reqType: FurnitureModelEnum.query;
|
|
13
|
-
modelInfo: FurnitureModelInfo[];
|
|
14
|
-
}
|
|
15
|
-
type TRequestFurnitureList = () => Promise<FurnitureModelResponse>;
|
|
16
|
-
type TSetFurnitureModel = (modelInfos: FurnitureModelInfo[]) => Promise<FurnitureModelResponse>;
|
|
17
|
-
export declare const useFurnitureModel: (devId: string) => {
|
|
1
|
+
import { type TRequestFurnitureList, type TSetFurnitureModel } from './type/protocols';
|
|
2
|
+
/**
|
|
3
|
+
* 自定义 Hook,用于家具模型管理
|
|
4
|
+
* @returns 包含 requestFurnitureList 和 setFurnitureModel 函数的对象
|
|
5
|
+
*/
|
|
6
|
+
export declare const useFurnitureModel: () => {
|
|
18
7
|
requestFurnitureList: TRequestFurnitureList;
|
|
19
8
|
setFurnitureModel: TSetFurnitureModel;
|
|
20
9
|
};
|
|
21
|
-
export {};
|
|
@@ -1,61 +1,47 @@
|
|
|
1
|
-
import { createSetCommonParams } from './createCommonOptions';
|
|
2
|
-
import { normalResolve } from './promise';
|
|
3
1
|
import { FurnitureModelEnum } from './type/requestType';
|
|
2
|
+
import { useStructuredMessage, handleMqttError } from './hooks/useStructuredMessage';
|
|
3
|
+
import { validator } from './type/fun';
|
|
4
|
+
/**
|
|
5
|
+
* 自定义 Hook,用于家具模型管理
|
|
6
|
+
* @returns 包含 requestFurnitureList 和 setFurnitureModel 函数的对象
|
|
7
|
+
*/
|
|
8
|
+
export const useFurnitureModel = () => {
|
|
9
|
+
const {
|
|
10
|
+
sendStructuredMessage
|
|
11
|
+
} = useStructuredMessage();
|
|
4
12
|
|
|
5
|
-
// 请求家具列表函数定义
|
|
6
|
-
|
|
7
|
-
// 设置家具模型函数定义
|
|
8
|
-
|
|
9
|
-
export const useFurnitureModel = devId => {
|
|
10
13
|
/**
|
|
11
14
|
* 请求家具列表
|
|
15
|
+
* @param data 可选参数(目前为空对象)
|
|
12
16
|
* @returns Promise<FurnitureModelResponse> 响应结果
|
|
13
17
|
*/
|
|
14
18
|
|
|
15
19
|
/**
|
|
16
20
|
* 设置家具模型
|
|
17
|
-
* @param
|
|
21
|
+
* @param data 包含家具模型信息数组的对象
|
|
18
22
|
* @returns Promise<FurnitureModelResponse> 响应结果
|
|
19
23
|
*/
|
|
20
24
|
|
|
21
25
|
return {
|
|
22
26
|
requestFurnitureList: () => {
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
} = params.message;
|
|
31
|
-
ty.device.sendMqttMessage(params);
|
|
32
|
-
return normalResolve(FurnitureModelEnum.query, taskId);
|
|
33
|
-
} catch (error) {
|
|
34
|
-
return Promise.reject(error instanceof Error ? error : new Error('Failed to request furniture list'));
|
|
35
|
-
}
|
|
27
|
+
return new Promise((resolve, reject) => {
|
|
28
|
+
try {
|
|
29
|
+
sendStructuredMessage(FurnitureModelEnum.query, {}, resolve, error => reject(handleMqttError(error, 'Failed to request furniture list')));
|
|
30
|
+
} catch (error) {
|
|
31
|
+
reject(handleMqttError(error, 'Failed to request furniture list'));
|
|
32
|
+
}
|
|
33
|
+
});
|
|
36
34
|
},
|
|
37
|
-
setFurnitureModel:
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
modelInfos
|
|
48
|
-
}
|
|
49
|
-
});
|
|
50
|
-
console.log('========================params', params);
|
|
51
|
-
ty.device.sendMqttMessage(params);
|
|
52
|
-
const {
|
|
53
|
-
taskId
|
|
54
|
-
} = params.message;
|
|
55
|
-
return normalResolve(FurnitureModelEnum.query, taskId);
|
|
56
|
-
} catch (error) {
|
|
57
|
-
throw error instanceof Error ? error : new Error('Failed to set furniture model');
|
|
58
|
-
}
|
|
35
|
+
setFurnitureModel: data => {
|
|
36
|
+
return new Promise((resolve, reject) => {
|
|
37
|
+
try {
|
|
38
|
+
// 使用 TypeBox Schema 进行参数验证
|
|
39
|
+
const validatedData = validator.validate('set_furniture_model', data);
|
|
40
|
+
sendStructuredMessage(FurnitureModelEnum.set, validatedData, resolve, error => reject(handleMqttError(error, 'Failed to set furniture model')), FurnitureModelEnum.query);
|
|
41
|
+
} catch (error) {
|
|
42
|
+
reject(handleMqttError(error, 'Failed to set furniture model'));
|
|
43
|
+
}
|
|
44
|
+
});
|
|
59
45
|
}
|
|
60
46
|
};
|
|
61
47
|
};
|
|
@@ -1,26 +1,10 @@
|
|
|
1
|
-
import {
|
|
2
|
-
interface DeleteMapResponse extends BaseResponse {
|
|
3
|
-
reqType: DeleteMapEnum.rst;
|
|
4
|
-
}
|
|
5
|
-
interface SaveMapResponse extends BaseResponse {
|
|
6
|
-
reqType: SaveCurrentMapEnum.query;
|
|
7
|
-
mapId: number;
|
|
8
|
-
}
|
|
9
|
-
interface UseMapResponse extends BaseResponse {
|
|
10
|
-
reqType: UseMapEnum.query;
|
|
11
|
-
mapId: number;
|
|
12
|
-
}
|
|
13
|
-
type TDeleteHistoryMap = (mapId: number) => Promise<DeleteMapResponse>;
|
|
14
|
-
type TSaveMap = () => Promise<SaveMapResponse>;
|
|
15
|
-
type TChangeCurrentMap = (mapId: number, url: string) => Promise<UseMapResponse>;
|
|
1
|
+
import { type TDeleteHistoryMap, type TSaveMap, type TChangeCurrentMap } from './type/protocols/historyMapProtocol';
|
|
16
2
|
/**
|
|
17
3
|
* 自定义 Hook,用于管理历史地图
|
|
18
|
-
* @param devId 设备ID
|
|
19
4
|
* @returns 包含删除历史地图、更改当前地图和保存地图的函数
|
|
20
5
|
*/
|
|
21
|
-
export declare const useHistoryMap: (
|
|
6
|
+
export declare const useHistoryMap: () => {
|
|
22
7
|
deleteHistoryMap: TDeleteHistoryMap;
|
|
23
8
|
changeCurrentMap: TChangeCurrentMap;
|
|
24
9
|
saveMap: TSaveMap;
|
|
25
10
|
};
|
|
26
|
-
export {};
|
|
@@ -1,35 +1,26 @@
|
|
|
1
1
|
import { useContext } from 'react';
|
|
2
2
|
import { deleteMultipleMapFile } from '../api/deleteMultipleMapFile';
|
|
3
|
-
import { createSetCommonParams } from './createCommonOptions';
|
|
4
|
-
import { normalResolve } from './promise';
|
|
5
3
|
import { DeleteMapEnum, SaveCurrentMapEnum, UseMapEnum } from './type';
|
|
6
4
|
import { SingletonContext } from './mqttProvider';
|
|
7
5
|
import { encodeDeleteMap0x2c, encodeSaveMap0x2a, encodeUseMap0x2e } from '@ray-js/robot-protocol';
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
// 保存地图响应类型
|
|
12
|
-
|
|
13
|
-
// 更改当前地图响应类型
|
|
14
|
-
|
|
15
|
-
// 删除历史地图函数类型定义
|
|
16
|
-
|
|
17
|
-
// 保存当前地图函数类型定义
|
|
18
|
-
|
|
19
|
-
// 更改当前使用的地图函数类型定义
|
|
20
|
-
|
|
6
|
+
import { useStructuredMessage, handleMqttError } from './hooks/useStructuredMessage';
|
|
7
|
+
import { validator } from './type/fun';
|
|
21
8
|
/**
|
|
22
9
|
* 自定义 Hook,用于管理历史地图
|
|
23
|
-
* @param devId 设备ID
|
|
24
10
|
* @returns 包含删除历史地图、更改当前地图和保存地图的函数
|
|
25
11
|
*/
|
|
26
|
-
export const useHistoryMap =
|
|
12
|
+
export const useHistoryMap = () => {
|
|
27
13
|
const {
|
|
28
14
|
useMqtt,
|
|
29
15
|
devices,
|
|
30
16
|
commandVersion
|
|
31
17
|
} = useContext(SingletonContext);
|
|
32
|
-
|
|
18
|
+
const {
|
|
19
|
+
sendStructuredMessage
|
|
20
|
+
} = useStructuredMessage();
|
|
21
|
+
const {
|
|
22
|
+
devId
|
|
23
|
+
} = devices.common.getDevInfo();
|
|
33
24
|
/**
|
|
34
25
|
* 删除历史地图
|
|
35
26
|
* @param mapId 地图ID
|
|
@@ -38,6 +29,7 @@ export const useHistoryMap = devId => {
|
|
|
38
29
|
|
|
39
30
|
/**
|
|
40
31
|
* 保存当前地图
|
|
32
|
+
* @param data 包含操作类型的参数对象(可选,默认为 oper: 0)
|
|
41
33
|
* @returns Promise<SaveMapResponse> 响应结果
|
|
42
34
|
*/
|
|
43
35
|
|
|
@@ -50,119 +42,110 @@ export const useHistoryMap = devId => {
|
|
|
50
42
|
|
|
51
43
|
return {
|
|
52
44
|
deleteHistoryMap: async mapId => {
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
// 先删除地图文件
|
|
59
|
-
await deleteMultipleMapFile(mapId, devId);
|
|
60
|
-
if (useMqtt) {
|
|
61
|
-
const params = createSetCommonParams({
|
|
62
|
-
deviceId: devId,
|
|
63
|
-
reqType: DeleteMapEnum.set,
|
|
64
|
-
message: {
|
|
45
|
+
return new Promise((resolve, reject) => {
|
|
46
|
+
(async () => {
|
|
47
|
+
try {
|
|
48
|
+
// 使用 TypeBox Schema 进行参数验证
|
|
49
|
+
const validatedData = validator.validate('delete_history_map', {
|
|
65
50
|
mapId
|
|
51
|
+
});
|
|
52
|
+
|
|
53
|
+
// 先删除地图文件
|
|
54
|
+
await deleteMultipleMapFile(validatedData.mapId, devId);
|
|
55
|
+
if (useMqtt) {
|
|
56
|
+
sendStructuredMessage(DeleteMapEnum.set, {
|
|
57
|
+
mapId: validatedData.mapId
|
|
58
|
+
}, resolve, error => reject(handleMqttError(error, 'Failed to delete history map')), DeleteMapEnum.rst // 响应类型是 rst,不是 set
|
|
59
|
+
);
|
|
60
|
+
return;
|
|
66
61
|
}
|
|
67
|
-
});
|
|
68
|
-
ty.device.sendMqttMessage(params);
|
|
69
|
-
const {
|
|
70
|
-
taskId
|
|
71
|
-
} = params.message;
|
|
72
|
-
return normalResolve(DeleteMapEnum.rst, taskId);
|
|
73
|
-
}
|
|
74
62
|
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
63
|
+
// 非 MQTT 模式:使用命令传输
|
|
64
|
+
const command = encodeDeleteMap0x2c({
|
|
65
|
+
id: validatedData.mapId
|
|
66
|
+
});
|
|
67
|
+
devices.common.model.actions.command_trans.set(command);
|
|
68
|
+
resolve({
|
|
69
|
+
success: true,
|
|
70
|
+
errCode: 0,
|
|
71
|
+
reqType: DeleteMapEnum.rst,
|
|
72
|
+
version: commandVersion,
|
|
73
|
+
taskId: `${Date.now()}`
|
|
74
|
+
});
|
|
75
|
+
} catch (error) {
|
|
76
|
+
reject(handleMqttError(error, 'Failed to delete history map'));
|
|
77
|
+
}
|
|
78
|
+
})();
|
|
79
|
+
});
|
|
90
80
|
},
|
|
91
81
|
changeCurrentMap: async (mapId, url) => {
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
throw new Error('url is required and must be a string');
|
|
98
|
-
}
|
|
99
|
-
try {
|
|
100
|
-
if (useMqtt) {
|
|
101
|
-
const params = createSetCommonParams({
|
|
102
|
-
deviceId: devId,
|
|
103
|
-
reqType: UseMapEnum.set,
|
|
104
|
-
message: {
|
|
82
|
+
return new Promise((resolve, reject) => {
|
|
83
|
+
(async () => {
|
|
84
|
+
try {
|
|
85
|
+
// 构建符合 Schema 的数据
|
|
86
|
+
const mapData = {
|
|
105
87
|
mapId,
|
|
106
88
|
url,
|
|
107
|
-
urlLen: url.length
|
|
89
|
+
urlLen: url.length
|
|
90
|
+
};
|
|
91
|
+
|
|
92
|
+
// 使用 TypeBox Schema 进行参数验证
|
|
93
|
+
const validatedData = validator.validate('change_current_map', mapData);
|
|
94
|
+
if (useMqtt) {
|
|
95
|
+
sendStructuredMessage(UseMapEnum.set, validatedData, resolve, error => reject(handleMqttError(error, 'Failed to change current map')), UseMapEnum.query // 响应类型是 query,不是 set
|
|
96
|
+
);
|
|
97
|
+
return;
|
|
108
98
|
}
|
|
109
|
-
});
|
|
110
|
-
ty.device.sendMqttMessage(params);
|
|
111
|
-
const {
|
|
112
|
-
taskId
|
|
113
|
-
} = params.message;
|
|
114
|
-
return normalResolve(UseMapEnum.query, taskId);
|
|
115
|
-
}
|
|
116
99
|
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
100
|
+
// 非 MQTT 模式:使用命令传输
|
|
101
|
+
const command = encodeUseMap0x2e({
|
|
102
|
+
mapId: validatedData.mapId,
|
|
103
|
+
url: validatedData.url
|
|
104
|
+
});
|
|
105
|
+
devices.common.model.actions.command_trans.set(command);
|
|
106
|
+
resolve({
|
|
107
|
+
success: true,
|
|
108
|
+
errCode: 0,
|
|
109
|
+
reqType: UseMapEnum.query,
|
|
110
|
+
version: commandVersion,
|
|
111
|
+
taskId: `${Date.now()}`,
|
|
112
|
+
mapId: validatedData.mapId
|
|
113
|
+
});
|
|
114
|
+
} catch (error) {
|
|
115
|
+
reject(handleMqttError(error, 'Failed to change current map'));
|
|
116
|
+
}
|
|
117
|
+
})();
|
|
118
|
+
});
|
|
134
119
|
},
|
|
135
|
-
saveMap: ()
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
120
|
+
saveMap: function () {
|
|
121
|
+
let data = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {
|
|
122
|
+
oper: 0
|
|
123
|
+
};
|
|
124
|
+
return new Promise((resolve, reject) => {
|
|
125
|
+
try {
|
|
126
|
+
// 使用 TypeBox Schema 进行参数验证
|
|
127
|
+
const validatedData = validator.validate('save_map', data);
|
|
128
|
+
if (useMqtt) {
|
|
129
|
+
sendStructuredMessage(SaveCurrentMapEnum.set, validatedData, resolve, error => reject(handleMqttError(error, 'Failed to save current map')), SaveCurrentMapEnum.query // 响应类型是 query,不是 set
|
|
130
|
+
);
|
|
131
|
+
return;
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
// 非 MQTT 模式:使用命令传输
|
|
135
|
+
const command = encodeSaveMap0x2a(1);
|
|
136
|
+
devices.common.model.actions.command_trans.set(command);
|
|
137
|
+
resolve({
|
|
138
|
+
success: true,
|
|
139
|
+
errCode: 0,
|
|
140
|
+
reqType: SaveCurrentMapEnum.query,
|
|
141
|
+
version: commandVersion,
|
|
142
|
+
taskId: `${Date.now()}`,
|
|
143
|
+
mapId: 0 // 非 MQTT 模式下无法获取 mapId
|
|
144
144
|
});
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
taskId
|
|
148
|
-
} = params.message;
|
|
149
|
-
return normalResolve(SaveCurrentMapEnum.query, taskId);
|
|
145
|
+
} catch (error) {
|
|
146
|
+
reject(handleMqttError(error, 'Failed to save current map'));
|
|
150
147
|
}
|
|
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
|
|
162
|
-
});
|
|
163
|
-
} catch (error) {
|
|
164
|
-
throw error instanceof Error ? error : new Error('Failed to save current map');
|
|
165
|
-
}
|
|
148
|
+
});
|
|
166
149
|
}
|
|
167
150
|
};
|
|
168
151
|
};
|
|
@@ -1,15 +1,8 @@
|
|
|
1
|
-
import {
|
|
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>;
|
|
1
|
+
import { type TSetPartDivision } from './type/protocols';
|
|
7
2
|
/**
|
|
8
3
|
* 自定义 Hook,用于房间分隔
|
|
9
|
-
* @param devId 设备ID
|
|
10
4
|
* @returns 包含 setPartDivision 函数的对象
|
|
11
5
|
*/
|
|
12
|
-
export declare const usePartDivision: (
|
|
6
|
+
export declare const usePartDivision: () => {
|
|
13
7
|
setPartDivision: TSetPartDivision;
|
|
14
8
|
};
|
|
15
|
-
export {};
|