@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
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import * as z from 'zod/mini';
|
|
2
|
+
import { BaseResponseSchema } from './base';
|
|
3
|
+
|
|
4
|
+
// 设置 WiFi 地图参数 Schema
|
|
5
|
+
export const setWifiMapSchema = z.object({
|
|
6
|
+
taskId: z.optional(z.string())
|
|
7
|
+
});
|
|
8
|
+
|
|
9
|
+
// WiFi 地图响应 Schema(BaseResponseSchema 已包含所有必需字段)
|
|
10
|
+
const wifiMapResponseSchema = BaseResponseSchema;
|
|
11
|
+
|
|
12
|
+
// 类型导出
|
|
13
|
+
|
|
14
|
+
// 函数类型定义
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import * as z from 'zod/mini';
|
|
2
|
+
export declare const setZoneCleanSchema: any;
|
|
3
|
+
declare const setZoneCleanResponseSchema: any;
|
|
4
|
+
export type SetZoneCleanData = z.infer<typeof setZoneCleanSchema>;
|
|
5
|
+
export type ZoneCleanResponse = z.infer<typeof setZoneCleanResponseSchema>;
|
|
6
|
+
export type TSetZoneClean = (data: SetZoneCleanData) => Promise<ZoneCleanResponse>;
|
|
7
|
+
export type TRequestZoneClean = () => Promise<ZoneCleanResponse>;
|
|
8
|
+
export {};
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import * as z from 'zod/mini';
|
|
2
|
+
import { BaseResponseSchema, Point } from './base';
|
|
3
|
+
const zoneSchema = z.object({
|
|
4
|
+
// 区域点集
|
|
5
|
+
points: z.array(Point),
|
|
6
|
+
// 区域名称
|
|
7
|
+
name: z.optional(z.string()),
|
|
8
|
+
// 区域高级设置
|
|
9
|
+
advanced: z.optional(z.object({
|
|
10
|
+
id: z.int(),
|
|
11
|
+
localSave: z.int(),
|
|
12
|
+
cleanMode: z.int(),
|
|
13
|
+
order: z.int(),
|
|
14
|
+
cleanTimes: z.int(),
|
|
15
|
+
suction: z.int(),
|
|
16
|
+
cistern: z.int()
|
|
17
|
+
}))
|
|
18
|
+
});
|
|
19
|
+
export const setZoneCleanSchema = z.object({
|
|
20
|
+
zones: z.array(zoneSchema),
|
|
21
|
+
origin: Point,
|
|
22
|
+
suctions: z.optional(z.array(z.string())),
|
|
23
|
+
cisterns: z.optional(z.array(z.string())),
|
|
24
|
+
cleanCounts: z.optional(z.array(z.int())),
|
|
25
|
+
yMops: z.optional(z.array(z.int())),
|
|
26
|
+
sweepMopModes: z.optional(z.array(z.string()))
|
|
27
|
+
});
|
|
28
|
+
|
|
29
|
+
// 划区清扫响应 Schema
|
|
30
|
+
const setZoneCleanResponseSchema = z.extend(BaseResponseSchema, {
|
|
31
|
+
// 区域坐标
|
|
32
|
+
polygons: z.array(z.string()),
|
|
33
|
+
// 区域名称
|
|
34
|
+
names: z.optional(z.array(z.string())),
|
|
35
|
+
// 吸力, closed - 关闭 gentle - 安静 normal - 正常 strong - 强劲 max - 超强 ,默认值为''
|
|
36
|
+
suctions: z.optional(z.array(z.string())),
|
|
37
|
+
// 拖地水量 "closed"- 关闭,"low"-低,"middle"-中,"high"-高,默认值为''
|
|
38
|
+
cisterns: z.optional(z.array(z.string())),
|
|
39
|
+
// 清扫次数 默认值1
|
|
40
|
+
cleanCounts: z.optional(z.array(z.int())),
|
|
41
|
+
// 拖地模式 1:开启Y型拖地 0:关闭Y型拖地 -1 未设置 默认值-1
|
|
42
|
+
yMops: z.optional(z.array(z.int())),
|
|
43
|
+
// 扫拖模式 "only_sweep":仅扫,"only_mop":仅拖,"both_work":扫拖同时,"clean_before_mop":先扫后拖,默认值为'only_sweep'
|
|
44
|
+
sweepMopModes: z.optional(z.array(z.string()))
|
|
45
|
+
});
|
|
46
|
+
|
|
47
|
+
// 类型导出
|
|
48
|
+
|
|
49
|
+
// 函数类型定义
|
package/lib/mqtt/useCarpet.d.ts
CHANGED
|
@@ -1,73 +1,13 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
}
|
|
9
|
-
type CarpetShape = 'rectangle' | 'round';
|
|
10
|
-
type CarpetShapeWithCustom = 'rectangle' | 'round' | 'custom';
|
|
11
|
-
interface AddCarpetInput extends CarpetCommonFields {
|
|
12
|
-
shape: CarpetShape[];
|
|
13
|
-
polygons: Array<Point[]>;
|
|
14
|
-
num: number;
|
|
15
|
-
type: number[];
|
|
16
|
-
cleanMode: number[];
|
|
17
|
-
}
|
|
18
|
-
interface AddCarpetResponse extends BaseResponse {
|
|
19
|
-
reqType: CarpetEnum.add;
|
|
20
|
-
id: number;
|
|
21
|
-
}
|
|
22
|
-
type TAddCarpet = (carpetInfo: AddCarpetInput) => Promise<AddCarpetResponse>;
|
|
23
|
-
interface UpdateCarpetInfo extends CarpetCommonFields {
|
|
24
|
-
ids: number[];
|
|
25
|
-
shape?: CarpetShape[];
|
|
26
|
-
type?: number[];
|
|
27
|
-
cleanMode?: number[];
|
|
28
|
-
polygons?: Array<Point[]>;
|
|
29
|
-
}
|
|
30
|
-
type TUpdateCarpet = (carpetInfo: UpdateCarpetInfo) => Promise<BaseResponse>;
|
|
31
|
-
type TDeleteCarpet = (carpetIds: number[]) => Promise<BaseResponse>;
|
|
32
|
-
interface CarpetQueryResponse extends BaseResponse {
|
|
33
|
-
reqType: CarpetEnum.query;
|
|
34
|
-
num: number;
|
|
35
|
-
polygons: string[];
|
|
36
|
-
cleanMode: number[];
|
|
37
|
-
autoBoost?: number[];
|
|
38
|
-
fineCleaning?: number[];
|
|
39
|
-
sideBrushRotating?: number[];
|
|
40
|
-
shape: string[];
|
|
41
|
-
type: number[];
|
|
42
|
-
ids: number[];
|
|
43
|
-
}
|
|
44
|
-
type TQueryCarpet = () => Promise<CarpetQueryResponse>;
|
|
45
|
-
export interface SetCarpetInput extends CarpetCommonFields {
|
|
46
|
-
num: number;
|
|
47
|
-
polygons: Array<Point[]>;
|
|
48
|
-
cleanMode: number[];
|
|
49
|
-
shape: CarpetShapeWithCustom[];
|
|
50
|
-
ids: number[];
|
|
51
|
-
type?: number[];
|
|
52
|
-
}
|
|
53
|
-
interface SetCarpetResponse extends BaseResponse {
|
|
54
|
-
reqType: CarpetEnum.set;
|
|
55
|
-
num: number;
|
|
56
|
-
polygons: string[];
|
|
57
|
-
cleanMode: number[];
|
|
58
|
-
autoBoost?: number[];
|
|
59
|
-
fineCleaning?: number[];
|
|
60
|
-
sideBrushRotating?: number[];
|
|
61
|
-
shape: string[];
|
|
62
|
-
ids: number[];
|
|
63
|
-
type?: number[];
|
|
64
|
-
}
|
|
65
|
-
type TSetCarpet = (carpetInfo: SetCarpetInput) => Promise<SetCarpetResponse>;
|
|
66
|
-
export declare const useCarpet: (devId: string) => {
|
|
1
|
+
import { type TAddCarpet, type TUpdateCarpet, type TDeleteCarpet, type TQueryCarpet, type TSetCarpet } from './type/protocols/carpetProtocol';
|
|
2
|
+
export type { SetCarpetInput, CarpetQueryResponse } from './type/protocols/carpetProtocol';
|
|
3
|
+
/**
|
|
4
|
+
* 自定义 Hook,用于地毯管理
|
|
5
|
+
* @returns 包含 addCarpet、updateCarpet、deleteCarpet、queryCarpet、setCarpet 函数的对象
|
|
6
|
+
*/
|
|
7
|
+
export declare const useCarpet: () => {
|
|
67
8
|
addCarpet: TAddCarpet;
|
|
68
9
|
updateCarpet: TUpdateCarpet;
|
|
69
10
|
deleteCarpet: TDeleteCarpet;
|
|
70
11
|
queryCarpet: TQueryCarpet;
|
|
71
12
|
setCarpet: TSetCarpet;
|
|
72
13
|
};
|
|
73
|
-
export {};
|
package/lib/mqtt/useCarpet.js
CHANGED
|
@@ -1,51 +1,21 @@
|
|
|
1
|
-
import "
|
|
2
|
-
import "core-js/modules/esnext.iterator.every.js";
|
|
1
|
+
import _objectSpread from "@babel/runtime/helpers/esm/objectSpread2";
|
|
3
2
|
import "core-js/modules/esnext.iterator.map.js";
|
|
4
3
|
import { pointsToString } from '../utils';
|
|
5
|
-
import {
|
|
6
|
-
import { normalResolve } from './promise';
|
|
4
|
+
import { pickBy } from 'lodash-es';
|
|
7
5
|
import { CarpetEnum } from './type/requestType';
|
|
6
|
+
import { useStructuredMessage, handleMqttError } from './hooks/useStructuredMessage';
|
|
7
|
+
import { validator } from './type/fun';
|
|
8
8
|
|
|
9
|
-
//
|
|
9
|
+
// 导出类型供外部使用
|
|
10
10
|
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
// 更新地毯的输入参数
|
|
18
|
-
|
|
19
|
-
// 更新地毯发送数据的类型(polygons 已转换为字符串)
|
|
20
|
-
|
|
21
|
-
// 查询地毯响应类型
|
|
22
|
-
|
|
23
|
-
// 设置地毯的输入参数
|
|
24
|
-
|
|
25
|
-
// 设置地毯响应类型
|
|
26
|
-
|
|
27
|
-
// 验证形状数组的辅助函数
|
|
28
|
-
const validateShape = function (shape, allowedShapes) {
|
|
29
|
-
let fieldName = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 'shape';
|
|
30
|
-
if (!shape.every(s => allowedShapes.includes(s))) {
|
|
31
|
-
throw new Error(`${fieldName} must contain only ${allowedShapes.map(s => `"${s}"`).join(', ')}`);
|
|
32
|
-
}
|
|
33
|
-
};
|
|
34
|
-
|
|
35
|
-
// 发送 MQTT 消息并返回 Promise 的辅助函数
|
|
36
|
-
const sendMqttMessage = (devId, reqType, message) => {
|
|
37
|
-
const params = createSetCommonParams({
|
|
38
|
-
deviceId: devId,
|
|
39
|
-
reqType,
|
|
40
|
-
message
|
|
41
|
-
});
|
|
42
|
-
ty.device.sendMqttMessage(params);
|
|
11
|
+
/**
|
|
12
|
+
* 自定义 Hook,用于地毯管理
|
|
13
|
+
* @returns 包含 addCarpet、updateCarpet、deleteCarpet、queryCarpet、setCarpet 函数的对象
|
|
14
|
+
*/
|
|
15
|
+
export const useCarpet = () => {
|
|
43
16
|
const {
|
|
44
|
-
|
|
45
|
-
} =
|
|
46
|
-
return normalResolve(reqType, taskId);
|
|
47
|
-
};
|
|
48
|
-
export const useCarpet = devId => {
|
|
17
|
+
sendStructuredMessage
|
|
18
|
+
} = useStructuredMessage();
|
|
49
19
|
/**
|
|
50
20
|
* 添加地毯(批量添加)
|
|
51
21
|
* @param carpetInfo 地毯信息,包含形状数组、轮廓点集合、数量、材质数组和清洁属性数组
|
|
@@ -54,172 +24,122 @@ export const useCarpet = devId => {
|
|
|
54
24
|
|
|
55
25
|
/**
|
|
56
26
|
* 更新地毯
|
|
57
|
-
* @param carpetInfo 地毯信息(
|
|
27
|
+
* @param carpetInfo 地毯信息(ids 必填,shape、type、cleanMode 可选)
|
|
58
28
|
* @returns Promise<BaseResponse> 响应结果
|
|
59
29
|
*/
|
|
60
30
|
|
|
61
31
|
/**
|
|
62
32
|
* 删除地毯
|
|
63
|
-
* @param
|
|
33
|
+
* @param data 包含地毯ID数组的对象
|
|
64
34
|
* @returns Promise<BaseResponse> 响应结果
|
|
65
35
|
*/
|
|
66
36
|
|
|
67
37
|
/**
|
|
68
38
|
* 查询地毯
|
|
39
|
+
* @param data 可选参数(目前为空对象)
|
|
69
40
|
* @returns Promise<CarpetQueryResponse> 响应结果,包含地毯数量、轮廓点集合、清洁属性和形状等信息
|
|
70
41
|
*/
|
|
71
42
|
|
|
72
43
|
/**
|
|
73
44
|
* 设置地毯(一次性设置所有地毯)
|
|
74
45
|
* @param carpetInfo 地毯信息,包含数量、轮廓点集合、清洁属性、形状和ID等
|
|
75
|
-
* @returns Promise<
|
|
46
|
+
* @returns Promise<CarpetQueryResponse> 响应结果,包含设置后的地毯信息
|
|
76
47
|
*/
|
|
77
48
|
|
|
78
49
|
return {
|
|
79
50
|
addCarpet: carpetInfo => {
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
const sendData = {
|
|
102
|
-
shape: carpetInfo.shape,
|
|
103
|
-
polygons: carpetInfo.polygons.map(i => pointsToString(i)),
|
|
104
|
-
num: carpetInfo.num,
|
|
105
|
-
type: carpetInfo.type,
|
|
106
|
-
cleanMode: carpetInfo.cleanMode,
|
|
107
|
-
autoBoost: carpetInfo.autoBoost,
|
|
108
|
-
fineCleaning: carpetInfo.fineCleaning,
|
|
109
|
-
sideBrushRotating: carpetInfo.sideBrushRotating
|
|
110
|
-
};
|
|
111
|
-
return sendMqttMessage(devId, CarpetEnum.add, {
|
|
112
|
-
carpetInfo: sendData
|
|
113
|
-
});
|
|
114
|
-
} catch (error) {
|
|
115
|
-
throw error instanceof Error ? error : new Error('Failed to add carpet');
|
|
116
|
-
}
|
|
51
|
+
return new Promise((resolve, reject) => {
|
|
52
|
+
try {
|
|
53
|
+
// 使用 TypeBox Schema 进行参数验证
|
|
54
|
+
const validatedData = validator.validate('add_carpet', carpetInfo);
|
|
55
|
+
const sendData = {
|
|
56
|
+
shape: validatedData.shape,
|
|
57
|
+
polygons: validatedData.polygons.map(i => pointsToString(i)),
|
|
58
|
+
num: validatedData.num,
|
|
59
|
+
type: validatedData.type,
|
|
60
|
+
cleanMode: validatedData.cleanMode,
|
|
61
|
+
autoBoost: validatedData.autoBoost,
|
|
62
|
+
fineCleaning: validatedData.fineCleaning,
|
|
63
|
+
sideBrushRotating: validatedData.sideBrushRotating
|
|
64
|
+
};
|
|
65
|
+
sendStructuredMessage(CarpetEnum.add, {
|
|
66
|
+
carpetInfo: sendData
|
|
67
|
+
}, resolve, error => reject(handleMqttError(error, 'Failed to add carpet')));
|
|
68
|
+
} catch (error) {
|
|
69
|
+
reject(handleMqttError(error, 'Failed to add carpet'));
|
|
70
|
+
}
|
|
71
|
+
});
|
|
117
72
|
},
|
|
118
73
|
updateCarpet: carpetInfo => {
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
}
|
|
138
|
-
if (carpetInfo.type !== undefined) {
|
|
139
|
-
sendData.type = carpetInfo.type;
|
|
140
|
-
}
|
|
141
|
-
if (carpetInfo.cleanMode !== undefined) {
|
|
142
|
-
sendData.cleanMode = carpetInfo.cleanMode;
|
|
143
|
-
}
|
|
144
|
-
if (carpetInfo.autoBoost !== undefined) {
|
|
145
|
-
sendData.autoBoost = carpetInfo.autoBoost;
|
|
146
|
-
}
|
|
147
|
-
if (carpetInfo.fineCleaning !== undefined) {
|
|
148
|
-
sendData.fineCleaning = carpetInfo.fineCleaning;
|
|
74
|
+
return new Promise((resolve, reject) => {
|
|
75
|
+
try {
|
|
76
|
+
// 使用 TypeBox Schema 进行参数验证
|
|
77
|
+
const validatedData = validator.validate('update_carpet', carpetInfo);
|
|
78
|
+
|
|
79
|
+
// 构建发送数据,只包含传入的字段
|
|
80
|
+
// 先处理需要特殊转换的字段
|
|
81
|
+
const processedData = _objectSpread(_objectSpread({}, validatedData), validatedData.polygons !== undefined && {
|
|
82
|
+
polygons: validatedData.polygons.map(i => pointsToString(i))
|
|
83
|
+
});
|
|
84
|
+
|
|
85
|
+
// 使用 lodash pickBy 过滤掉 undefined 值
|
|
86
|
+
const sendData = pickBy(processedData, value => value !== undefined);
|
|
87
|
+
sendStructuredMessage(CarpetEnum.update, {
|
|
88
|
+
carpetInfo: sendData
|
|
89
|
+
}, resolve, error => reject(handleMqttError(error, 'Failed to update carpet')), CarpetEnum.update);
|
|
90
|
+
} catch (error) {
|
|
91
|
+
reject(handleMqttError(error, 'Failed to update carpet'));
|
|
149
92
|
}
|
|
150
|
-
|
|
151
|
-
sendData.sideBrushRotating = carpetInfo.sideBrushRotating;
|
|
152
|
-
}
|
|
153
|
-
// 特殊处理 polygons(需要转换)
|
|
154
|
-
if (carpetInfo.polygons !== undefined) {
|
|
155
|
-
sendData.polygons = carpetInfo.polygons.map(i => pointsToString(i));
|
|
156
|
-
}
|
|
157
|
-
return sendMqttMessage(devId, CarpetEnum.update, {
|
|
158
|
-
carpetInfo: sendData
|
|
159
|
-
});
|
|
160
|
-
} catch (error) {
|
|
161
|
-
throw error instanceof Error ? error : new Error('Failed to update carpet');
|
|
162
|
-
}
|
|
93
|
+
});
|
|
163
94
|
},
|
|
164
|
-
deleteCarpet:
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
}
|
|
174
|
-
})
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
}
|
|
95
|
+
deleteCarpet: data => {
|
|
96
|
+
return new Promise((resolve, reject) => {
|
|
97
|
+
try {
|
|
98
|
+
// 使用 TypeBox Schema 进行参数验证
|
|
99
|
+
const validatedData = validator.validate('delete_carpet', data);
|
|
100
|
+
sendStructuredMessage(CarpetEnum.delete, {
|
|
101
|
+
carpetInfo: {
|
|
102
|
+
ids: validatedData.ids
|
|
103
|
+
}
|
|
104
|
+
}, resolve, error => reject(handleMqttError(error, 'Failed to delete carpet')), CarpetEnum.delete);
|
|
105
|
+
} catch (error) {
|
|
106
|
+
reject(handleMqttError(error, 'Failed to delete carpet'));
|
|
107
|
+
}
|
|
108
|
+
});
|
|
178
109
|
},
|
|
179
|
-
queryCarpet: ()
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
110
|
+
queryCarpet: function () {
|
|
111
|
+
let data = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
|
112
|
+
return new Promise((resolve, reject) => {
|
|
113
|
+
try {
|
|
114
|
+
// 使用 TypeBox Schema 进行参数验证
|
|
115
|
+
const validatedParams = validator.validate('query_carpet', data);
|
|
116
|
+
sendStructuredMessage(CarpetEnum.query, validatedParams, resolve, error => reject(handleMqttError(error, 'Failed to query carpet')), CarpetEnum.query);
|
|
117
|
+
} catch (error) {
|
|
118
|
+
reject(handleMqttError(error, 'Failed to query carpet'));
|
|
119
|
+
}
|
|
120
|
+
});
|
|
185
121
|
},
|
|
186
122
|
setCarpet: carpetInfo => {
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
}
|
|
207
|
-
try {
|
|
208
|
-
const sendData = {
|
|
209
|
-
num: carpetInfo.num,
|
|
210
|
-
polygons: carpetInfo.polygons.map(i => pointsToString(i)),
|
|
211
|
-
cleanMode: carpetInfo.cleanMode,
|
|
212
|
-
autoBoost: carpetInfo.autoBoost,
|
|
213
|
-
fineCleaning: carpetInfo.fineCleaning,
|
|
214
|
-
sideBrushRotating: carpetInfo.sideBrushRotating,
|
|
215
|
-
shape: carpetInfo.shape,
|
|
216
|
-
ids: carpetInfo.ids,
|
|
217
|
-
type: carpetInfo.type
|
|
218
|
-
};
|
|
219
|
-
return sendMqttMessage(devId, CarpetEnum.set, sendData);
|
|
220
|
-
} catch (error) {
|
|
221
|
-
throw error instanceof Error ? error : new Error('Failed to set carpet');
|
|
222
|
-
}
|
|
123
|
+
return new Promise((resolve, reject) => {
|
|
124
|
+
try {
|
|
125
|
+
// 使用 TypeBox Schema 进行参数验证
|
|
126
|
+
const validatedData = validator.validate('set_carpet', carpetInfo);
|
|
127
|
+
const sendData = {
|
|
128
|
+
num: validatedData.num,
|
|
129
|
+
polygons: validatedData.polygons.map(i => pointsToString(i)),
|
|
130
|
+
cleanMode: validatedData.cleanMode,
|
|
131
|
+
autoBoost: validatedData.autoBoost,
|
|
132
|
+
fineCleaning: validatedData.fineCleaning,
|
|
133
|
+
sideBrushRotating: validatedData.sideBrushRotating,
|
|
134
|
+
shape: validatedData.shape,
|
|
135
|
+
ids: validatedData.ids,
|
|
136
|
+
type: validatedData.type
|
|
137
|
+
};
|
|
138
|
+
sendStructuredMessage(CarpetEnum.set, sendData, resolve, error => reject(handleMqttError(error, 'Failed to set carpet')), CarpetEnum.query);
|
|
139
|
+
} catch (error) {
|
|
140
|
+
reject(handleMqttError(error, 'Failed to set carpet'));
|
|
141
|
+
}
|
|
142
|
+
});
|
|
223
143
|
}
|
|
224
144
|
};
|
|
225
145
|
};
|
|
@@ -1,18 +1,9 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { CarpetCleanEnum } from './type/requestType';
|
|
3
|
-
interface CarpetCleanResponse extends BaseResponse {
|
|
4
|
-
reqType: CarpetCleanEnum;
|
|
5
|
-
ids: number[];
|
|
6
|
-
}
|
|
7
|
-
type TSetCarpetClean = (carpetIds: number[]) => Promise<CarpetCleanResponse>;
|
|
8
|
-
type TRequestCarpetClean = () => Promise<CarpetCleanResponse>;
|
|
1
|
+
import { type TRequestCarpetClean, type TSetCarpetClean } from './type/protocols';
|
|
9
2
|
/**
|
|
10
3
|
* 自定义 Hook,用于地毯清扫
|
|
11
|
-
* @param devId 设备ID
|
|
12
4
|
* @returns 包含 requestCarpetClean 和 setCarpetClean 函数的对象
|
|
13
5
|
*/
|
|
14
|
-
export declare const useCarpetClean: (
|
|
6
|
+
export declare const useCarpetClean: () => {
|
|
15
7
|
requestCarpetClean: TRequestCarpetClean;
|
|
16
8
|
setCarpetClean: TSetCarpetClean;
|
|
17
9
|
};
|
|
18
|
-
export {};
|
|
@@ -1,75 +1,48 @@
|
|
|
1
|
-
import "core-js/modules/esnext.iterator.constructor.js";
|
|
2
|
-
import "core-js/modules/esnext.iterator.for-each.js";
|
|
3
1
|
// 地毯清扫
|
|
4
|
-
import { createSetCommonParams } from './createCommonOptions';
|
|
5
2
|
import { CarpetCleanEnum } from './type/requestType';
|
|
6
|
-
import {
|
|
7
|
-
|
|
8
|
-
// 地毯清扫响应类型
|
|
9
|
-
|
|
10
|
-
// 设置地毯清扫函数类型定义
|
|
11
|
-
|
|
12
|
-
// 请求地毯清扫函数类型定义
|
|
13
|
-
|
|
3
|
+
import { useStructuredMessage, handleMqttError } from './hooks/useStructuredMessage';
|
|
4
|
+
import { validator } from './type/fun';
|
|
14
5
|
/**
|
|
15
6
|
* 自定义 Hook,用于地毯清扫
|
|
16
|
-
* @param devId 设备ID
|
|
17
7
|
* @returns 包含 requestCarpetClean 和 setCarpetClean 函数的对象
|
|
18
8
|
*/
|
|
19
|
-
export const useCarpetClean =
|
|
9
|
+
export const useCarpetClean = () => {
|
|
10
|
+
const {
|
|
11
|
+
sendStructuredMessage
|
|
12
|
+
} = useStructuredMessage();
|
|
13
|
+
|
|
20
14
|
/**
|
|
21
15
|
* 请求地毯清扫信息
|
|
16
|
+
* @param data 可选参数(目前为空对象)
|
|
22
17
|
* @returns Promise<CarpetCleanResponse> 响应结果
|
|
23
18
|
*/
|
|
24
19
|
|
|
25
20
|
/**
|
|
26
21
|
* 设置地毯清扫
|
|
27
|
-
* @param
|
|
22
|
+
* @param data 包含地毯ID数组的对象
|
|
28
23
|
* @returns Promise<CarpetCleanResponse> 响应结果
|
|
29
24
|
*/
|
|
30
25
|
|
|
31
26
|
return {
|
|
32
27
|
requestCarpetClean: () => {
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
taskId
|
|
41
|
-
} = params.message;
|
|
42
|
-
return normalResolve(CarpetCleanEnum.query, taskId);
|
|
43
|
-
} catch (error) {
|
|
44
|
-
return Promise.reject(error instanceof Error ? error : new Error('Failed to request carpet clean'));
|
|
45
|
-
}
|
|
28
|
+
return new Promise((resolve, reject) => {
|
|
29
|
+
try {
|
|
30
|
+
sendStructuredMessage(CarpetCleanEnum.query, {}, resolve, error => reject(handleMqttError(error, 'Failed to request carpet clean')), CarpetCleanEnum.query);
|
|
31
|
+
} catch (error) {
|
|
32
|
+
reject(handleMqttError(error, 'Failed to request carpet clean'));
|
|
33
|
+
}
|
|
34
|
+
});
|
|
46
35
|
},
|
|
47
|
-
setCarpetClean:
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
36
|
+
setCarpetClean: data => {
|
|
37
|
+
return new Promise((resolve, reject) => {
|
|
38
|
+
try {
|
|
39
|
+
// 使用 TypeBox Schema 进行参数验证
|
|
40
|
+
const validatedData = validator.validate('set_carpet_clean', data);
|
|
41
|
+
sendStructuredMessage(CarpetCleanEnum.set, validatedData, resolve, error => reject(handleMqttError(error, 'Failed to set carpet clean')), CarpetCleanEnum.set);
|
|
42
|
+
} catch (error) {
|
|
43
|
+
reject(handleMqttError(error, 'Failed to set carpet clean'));
|
|
55
44
|
}
|
|
56
45
|
});
|
|
57
|
-
try {
|
|
58
|
-
const params = createSetCommonParams({
|
|
59
|
-
deviceId: devId,
|
|
60
|
-
reqType: CarpetCleanEnum.set,
|
|
61
|
-
message: {
|
|
62
|
-
ids: carpetIds
|
|
63
|
-
}
|
|
64
|
-
});
|
|
65
|
-
ty.device.sendMqttMessage(params);
|
|
66
|
-
const {
|
|
67
|
-
taskId
|
|
68
|
-
} = params.message;
|
|
69
|
-
return normalResolve(CarpetCleanEnum.set, taskId);
|
|
70
|
-
} catch (error) {
|
|
71
|
-
throw error instanceof Error ? error : new Error('Failed to set carpet clean');
|
|
72
|
-
}
|
|
73
46
|
}
|
|
74
47
|
};
|
|
75
48
|
};
|
package/lib/mqtt/useDevInfo.d.ts
CHANGED
|
@@ -1,7 +1,9 @@
|
|
|
1
|
-
import {
|
|
2
|
-
export
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
1
|
+
import { type TRequestDevInfo } from './type/protocols/devInfoProtocol';
|
|
2
|
+
export type { DevInfoResponse } from './type/protocols/devInfoProtocol';
|
|
3
|
+
/**
|
|
4
|
+
* 自定义 Hook,用于设备信息管理
|
|
5
|
+
* @returns 包含 requestDevInfo 函数的对象
|
|
6
|
+
*/
|
|
7
|
+
export declare const useDevInfo: () => {
|
|
8
|
+
requestDevInfo: TRequestDevInfo;
|
|
7
9
|
};
|