@ray-js/robot-data-stream 0.0.16 → 0.0.17-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/index.d.ts +3 -1
- package/lib/mqtt/index.js +3 -1
- package/lib/mqtt/type/protocols/cruiseProtocol.d.ts +34 -0
- package/lib/mqtt/type/protocols/cruiseProtocol.js +1 -0
- package/lib/mqtt/type/protocols/index.d.ts +2 -0
- package/lib/mqtt/type/protocols/index.js +3 -1
- package/lib/mqtt/type/protocols/purifierScheduleProtocol.d.ts +42 -0
- package/lib/mqtt/type/protocols/purifierScheduleProtocol.js +1 -0
- package/lib/mqtt/type/protocols/roomPropertyProtocol.d.ts +4 -0
- package/lib/mqtt/type/requestType.d.ts +8 -0
- package/lib/mqtt/type/requestType.js +14 -0
- package/lib/mqtt/useCruise.d.ts +9 -0
- package/lib/mqtt/useCruise.js +66 -0
- package/lib/mqtt/usePurifierSchedule.d.ts +9 -0
- package/lib/mqtt/usePurifierSchedule.js +66 -0
- package/lib/mqtt/useRoomProperty.js +3 -1
- package/package.json +1 -1
package/lib/mqtt/index.d.ts
CHANGED
|
@@ -19,4 +19,6 @@ import { useCarpet } from './useCarpet';
|
|
|
19
19
|
import { useCarpetClean } from './useCarpetClean';
|
|
20
20
|
import { useDeviceModel } from './useDeviceModel';
|
|
21
21
|
import { useFurnitureModel } from './useFurnitureModel';
|
|
22
|
-
|
|
22
|
+
import { usePurifierSchedule } from './usePurifierSchedule';
|
|
23
|
+
import { useCruise } from './useCruise';
|
|
24
|
+
export { useCarpet, useCarpetClean, useVoice, MqttProvider, useDeviceModel, useFurnitureModel, useDevInfo, usePartMerge, usePartDivision, usePassword, useWifiMap, useQuiteHours, useVirtualArea, useSpotClean, useZoneClean, useSelectRoomClean, useVirtualWall, useSchedule, useHistoryMap, useRoomProperty, useResetMap, usePurifierSchedule, useCruise, };
|
package/lib/mqtt/index.js
CHANGED
|
@@ -19,4 +19,6 @@ import { useCarpet } from './useCarpet';
|
|
|
19
19
|
import { useCarpetClean } from './useCarpetClean';
|
|
20
20
|
import { useDeviceModel } from './useDeviceModel';
|
|
21
21
|
import { useFurnitureModel } from './useFurnitureModel';
|
|
22
|
-
|
|
22
|
+
import { usePurifierSchedule } from './usePurifierSchedule';
|
|
23
|
+
import { useCruise } from './useCruise';
|
|
24
|
+
export { useCarpet, useCarpetClean, useVoice, MqttProvider, useDeviceModel, useFurnitureModel, useDevInfo, usePartMerge, usePartDivision, usePassword, useWifiMap, useQuiteHours, useVirtualArea, useSpotClean, useZoneClean, useSelectRoomClean, useVirtualWall, useSchedule, useHistoryMap, useRoomProperty, useResetMap, usePurifierSchedule, useCruise };
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import type { BaseResponse } from './base';
|
|
2
|
+
/** 巡航控制指令 */
|
|
3
|
+
export type CruiseCmd = 'start' | 'pause' | 'resume' | 'stop';
|
|
4
|
+
/** 巡航状态:idle 未巡航 / cruising 巡航中 / paused 已暂停 */
|
|
5
|
+
export type CruiseStatus = 'idle' | 'cruising' | 'paused';
|
|
6
|
+
/** 巡航类型:whole_house 全屋巡航 / select_room 定点巡航(按房间工作点) */
|
|
7
|
+
export type CruiseType = 'whole_house' | 'select_room';
|
|
8
|
+
export interface SetCruiseData {
|
|
9
|
+
/** start 开始 / pause 暂停 / resume 继续 / stop 结束 */
|
|
10
|
+
cmd: CruiseCmd;
|
|
11
|
+
/** 巡航类型,cmd 为 start 时必填 */
|
|
12
|
+
cruiseType?: CruiseType;
|
|
13
|
+
/** select_room 时的房间 ID 列表;不传表示全部工作点 */
|
|
14
|
+
ids?: number[];
|
|
15
|
+
version?: string;
|
|
16
|
+
}
|
|
17
|
+
export interface RequestCruiseData {
|
|
18
|
+
version?: string;
|
|
19
|
+
}
|
|
20
|
+
export interface CruiseResponse extends BaseResponse {
|
|
21
|
+
/** 巡航状态 */
|
|
22
|
+
status: CruiseStatus;
|
|
23
|
+
mapId: number;
|
|
24
|
+
/** 巡航类型;idle 时可不携带 */
|
|
25
|
+
cruiseType?: CruiseType;
|
|
26
|
+
/** select_room 时本次巡航的房间 ID 列表 */
|
|
27
|
+
ids?: number[];
|
|
28
|
+
/** 当前正在工作的房间 ID */
|
|
29
|
+
currentId?: number;
|
|
30
|
+
/** 当前工作点坐标 "x, y" */
|
|
31
|
+
polygon?: string;
|
|
32
|
+
}
|
|
33
|
+
export type TRequestCruise = (message?: RequestCruiseData) => Promise<CruiseResponse>;
|
|
34
|
+
export type TSetCruise = (message: SetCruiseData) => Promise<CruiseResponse>;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -17,4 +17,6 @@ export * from './furnitureModelProtocol';
|
|
|
17
17
|
export * from './deviceModelProtocol';
|
|
18
18
|
export * from './carpetCleanProtocol';
|
|
19
19
|
export * from './devInfoProtocol';
|
|
20
|
-
export * from './roomPropertyProtocol';
|
|
20
|
+
export * from './roomPropertyProtocol';
|
|
21
|
+
export * from './purifierScheduleProtocol';
|
|
22
|
+
export * from './cruiseProtocol';
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import type { BaseResponse } from './base';
|
|
2
|
+
/** 工作类型:select_room 选房净化 / whole_house 整屋净化 */
|
|
3
|
+
export type PurifierWorkType = 'select_room' | 'whole_house';
|
|
4
|
+
/** 风速 */
|
|
5
|
+
export type PurifierFanMode = 'auto' | 'low' | 'mid' | 'high';
|
|
6
|
+
export interface PurifierScheduleItem {
|
|
7
|
+
/** 是否启用:1 启用 / 0 禁用 */
|
|
8
|
+
active: number;
|
|
9
|
+
/** 周重复,长度 7(周一~周日),1 生效;全 0 表示仅执行一次 */
|
|
10
|
+
cycle: number[];
|
|
11
|
+
/** 执行时间 [时, 分],24 小时制 */
|
|
12
|
+
time: number[];
|
|
13
|
+
/** 房间 ID 列表;workTypes 为 whole_house 时为空数组 */
|
|
14
|
+
ids: number[];
|
|
15
|
+
/** 工作类型,与 ids 对齐;整屋时单元素 whole_house */
|
|
16
|
+
workTypes: PurifierWorkType[];
|
|
17
|
+
/** 风速,与 ids 对齐(整屋时单元素) */
|
|
18
|
+
fanModes: PurifierFanMode[];
|
|
19
|
+
/** 净化顺序,与 ids 对齐 */
|
|
20
|
+
orders?: number[];
|
|
21
|
+
/** 房间名称,与 ids 对齐 */
|
|
22
|
+
names?: string[];
|
|
23
|
+
/** 净化点坐标 "x, y",与 ids 对齐 */
|
|
24
|
+
polygons?: string[];
|
|
25
|
+
}
|
|
26
|
+
export interface SetPurifierScheduleData {
|
|
27
|
+
/** 定时任务数量,= list.length */
|
|
28
|
+
num: number;
|
|
29
|
+
/** 定时任务列表(覆盖式全量下发) */
|
|
30
|
+
list: PurifierScheduleItem[];
|
|
31
|
+
version?: string;
|
|
32
|
+
}
|
|
33
|
+
export interface RequestPurifierScheduleData {
|
|
34
|
+
version?: string;
|
|
35
|
+
}
|
|
36
|
+
export interface PurifierScheduleResponse extends BaseResponse {
|
|
37
|
+
mapId: number;
|
|
38
|
+
num: number;
|
|
39
|
+
list: PurifierScheduleItem[];
|
|
40
|
+
}
|
|
41
|
+
export type TRequestPurifierSchedule = (message?: RequestPurifierScheduleData) => Promise<PurifierScheduleResponse>;
|
|
42
|
+
export type TSetPurifierSchedule = (message: SetPurifierScheduleData) => Promise<PurifierScheduleResponse>;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -13,6 +13,8 @@ export interface SetRoomPropertyData {
|
|
|
13
13
|
orders?: number[];
|
|
14
14
|
routePreferences?: string[];
|
|
15
15
|
waterValues?: number[];
|
|
16
|
+
/** 净化点坐标 "x, y",与 ids 一一对应;空字符串表示该房间未设置净化点 */
|
|
17
|
+
polygons?: string[];
|
|
16
18
|
}
|
|
17
19
|
export interface RoomPropertyResponse extends BaseResponse {
|
|
18
20
|
suctions?: string[];
|
|
@@ -29,6 +31,8 @@ export interface RoomPropertyResponse extends BaseResponse {
|
|
|
29
31
|
orders?: number[];
|
|
30
32
|
routePreferences?: string[];
|
|
31
33
|
waterValues?: number[];
|
|
34
|
+
/** 净化点坐标 "x, y",与 ids 一一对应;空字符串表示该房间未设置净化点 */
|
|
35
|
+
polygons?: string[];
|
|
32
36
|
}
|
|
33
37
|
export type TRequestRoomProperty = () => Promise<RoomPropertyResponse>;
|
|
34
38
|
export type TSetRoomProperty = (data: SetRoomPropertyData) => Promise<RoomPropertyResponse>;
|
|
@@ -92,3 +92,11 @@ export declare enum CarpetCleanEnum {
|
|
|
92
92
|
query = "carpetCleanQry",
|
|
93
93
|
set = "carpetCleanSet"
|
|
94
94
|
}
|
|
95
|
+
export declare enum PurifierScheduleEnum {
|
|
96
|
+
query = "purifierScheduleQry",
|
|
97
|
+
set = "purifierScheduleSet"
|
|
98
|
+
}
|
|
99
|
+
export declare enum CruiseEnum {
|
|
100
|
+
query = "cruiseQry",
|
|
101
|
+
set = "cruiseSet"
|
|
102
|
+
}
|
|
@@ -137,4 +137,18 @@ export let CarpetCleanEnum = /*#__PURE__*/function (CarpetCleanEnum) {
|
|
|
137
137
|
CarpetCleanEnum["query"] = "carpetCleanQry";
|
|
138
138
|
CarpetCleanEnum["set"] = "carpetCleanSet";
|
|
139
139
|
return CarpetCleanEnum;
|
|
140
|
+
}({});
|
|
141
|
+
|
|
142
|
+
// 净化定时(移动空气净化器)
|
|
143
|
+
export let PurifierScheduleEnum = /*#__PURE__*/function (PurifierScheduleEnum) {
|
|
144
|
+
PurifierScheduleEnum["query"] = "purifierScheduleQry";
|
|
145
|
+
PurifierScheduleEnum["set"] = "purifierScheduleSet";
|
|
146
|
+
return PurifierScheduleEnum;
|
|
147
|
+
}({});
|
|
148
|
+
|
|
149
|
+
// 巡航(通用:移动空气净化器、移动垃圾桶等移动设备)
|
|
150
|
+
export let CruiseEnum = /*#__PURE__*/function (CruiseEnum) {
|
|
151
|
+
CruiseEnum["query"] = "cruiseQry";
|
|
152
|
+
CruiseEnum["set"] = "cruiseSet";
|
|
153
|
+
return CruiseEnum;
|
|
140
154
|
}({});
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { type TRequestCruise, type TSetCruise } from './type/protocols/cruiseProtocol';
|
|
2
|
+
/**
|
|
3
|
+
* 自定义 Hook,用于移动设备巡航状态查询与控制(如移动空气净化器、移动垃圾桶)
|
|
4
|
+
* @returns 包含 requestCruise 和 setCruise 函数的对象
|
|
5
|
+
*/
|
|
6
|
+
export declare const useCruise: () => {
|
|
7
|
+
requestCruise: TRequestCruise;
|
|
8
|
+
setCruise: TSetCruise;
|
|
9
|
+
};
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
// 巡航(通用:移动空气净化器、移动垃圾桶等移动设备)
|
|
2
|
+
import { useContext } from 'react';
|
|
3
|
+
import { handleMqttError, useStructuredMessage } from './hooks/useStructuredMessage';
|
|
4
|
+
import { SingletonContext } from './mqttProvider';
|
|
5
|
+
import { CruiseEnum } from './type';
|
|
6
|
+
/**
|
|
7
|
+
* 自定义 Hook,用于移动设备巡航状态查询与控制(如移动空气净化器、移动垃圾桶)
|
|
8
|
+
* @returns 包含 requestCruise 和 setCruise 函数的对象
|
|
9
|
+
*/
|
|
10
|
+
export const useCruise = () => {
|
|
11
|
+
const {
|
|
12
|
+
useMqtt
|
|
13
|
+
} = useContext(SingletonContext);
|
|
14
|
+
const {
|
|
15
|
+
sendStructuredMessage
|
|
16
|
+
} = useStructuredMessage();
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* 查询巡航状态(status)与巡航类型(cruiseType)
|
|
20
|
+
* @param message 可选参数,包含版本号
|
|
21
|
+
* @returns Promise<CruiseResponse> 响应结果
|
|
22
|
+
*/
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* 巡航控制:cmd 为 start / pause / resume / stop;start 时需携带 cruiseType
|
|
26
|
+
* @param message 巡航控制数据
|
|
27
|
+
* @returns Promise<CruiseResponse> 响应结果
|
|
28
|
+
*/
|
|
29
|
+
|
|
30
|
+
return {
|
|
31
|
+
requestCruise: function () {
|
|
32
|
+
let message = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {
|
|
33
|
+
version: '1.0.0'
|
|
34
|
+
};
|
|
35
|
+
return new Promise((resolve, reject) => {
|
|
36
|
+
try {
|
|
37
|
+
if (!useMqtt) {
|
|
38
|
+
reject(new Error('useMqtt is not used'));
|
|
39
|
+
return;
|
|
40
|
+
}
|
|
41
|
+
sendStructuredMessage(CruiseEnum.query, message, resolve, error => reject(handleMqttError(error, 'Failed to request cruise')));
|
|
42
|
+
} catch (error) {
|
|
43
|
+
reject(handleMqttError(error, 'Failed to request cruise'));
|
|
44
|
+
}
|
|
45
|
+
});
|
|
46
|
+
},
|
|
47
|
+
setCruise: message => {
|
|
48
|
+
return new Promise((resolve, reject) => {
|
|
49
|
+
try {
|
|
50
|
+
if (!useMqtt) {
|
|
51
|
+
reject(new Error('useMqtt is not used'));
|
|
52
|
+
return;
|
|
53
|
+
}
|
|
54
|
+
if (message.cmd === 'start' && !message.cruiseType) {
|
|
55
|
+
reject(new Error('cruiseType is required when cmd is "start"'));
|
|
56
|
+
return;
|
|
57
|
+
}
|
|
58
|
+
sendStructuredMessage(CruiseEnum.set, message, resolve, error => reject(handleMqttError(error, 'Failed to set cruise')), CruiseEnum.query // 响应类型是 query,不是 set
|
|
59
|
+
);
|
|
60
|
+
} catch (error) {
|
|
61
|
+
reject(handleMqttError(error, 'Failed to set cruise'));
|
|
62
|
+
}
|
|
63
|
+
});
|
|
64
|
+
}
|
|
65
|
+
};
|
|
66
|
+
};
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { type TRequestPurifierSchedule, type TSetPurifierSchedule } from './type/protocols/purifierScheduleProtocol';
|
|
2
|
+
/**
|
|
3
|
+
* 自定义 Hook,用于净化定时任务管理(移动空气净化器)
|
|
4
|
+
* @returns 包含 requestPurifierSchedule 和 setPurifierSchedule 函数的对象
|
|
5
|
+
*/
|
|
6
|
+
export declare const usePurifierSchedule: () => {
|
|
7
|
+
requestPurifierSchedule: TRequestPurifierSchedule;
|
|
8
|
+
setPurifierSchedule: TSetPurifierSchedule;
|
|
9
|
+
};
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
import _objectSpread from "@babel/runtime/helpers/esm/objectSpread2";
|
|
2
|
+
// 净化定时(移动空气净化器)
|
|
3
|
+
import { useContext } from 'react';
|
|
4
|
+
import { handleMqttError, useStructuredMessage } from './hooks/useStructuredMessage';
|
|
5
|
+
import { SingletonContext } from './mqttProvider';
|
|
6
|
+
import { PurifierScheduleEnum } from './type';
|
|
7
|
+
/**
|
|
8
|
+
* 自定义 Hook,用于净化定时任务管理(移动空气净化器)
|
|
9
|
+
* @returns 包含 requestPurifierSchedule 和 setPurifierSchedule 函数的对象
|
|
10
|
+
*/
|
|
11
|
+
export const usePurifierSchedule = () => {
|
|
12
|
+
const {
|
|
13
|
+
useMqtt
|
|
14
|
+
} = useContext(SingletonContext);
|
|
15
|
+
const {
|
|
16
|
+
sendStructuredMessage
|
|
17
|
+
} = useStructuredMessage();
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* 请求净化定时数据
|
|
21
|
+
* @param message 可选参数,包含版本号
|
|
22
|
+
* @returns Promise<PurifierScheduleResponse> 响应结果
|
|
23
|
+
*/
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* 设置净化定时数据(覆盖式全量下发)
|
|
27
|
+
* @param message 定时任务数据
|
|
28
|
+
* @returns Promise<PurifierScheduleResponse> 响应结果
|
|
29
|
+
*/
|
|
30
|
+
|
|
31
|
+
return {
|
|
32
|
+
requestPurifierSchedule: function () {
|
|
33
|
+
let message = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {
|
|
34
|
+
version: '1.0.0'
|
|
35
|
+
};
|
|
36
|
+
return new Promise((resolve, reject) => {
|
|
37
|
+
try {
|
|
38
|
+
if (!useMqtt) {
|
|
39
|
+
reject(new Error('useMqtt is not used'));
|
|
40
|
+
return;
|
|
41
|
+
}
|
|
42
|
+
sendStructuredMessage(PurifierScheduleEnum.query, message, resolve, error => reject(handleMqttError(error, 'Failed to request purifier schedule')));
|
|
43
|
+
} catch (error) {
|
|
44
|
+
reject(handleMqttError(error, 'Failed to request purifier schedule'));
|
|
45
|
+
}
|
|
46
|
+
});
|
|
47
|
+
},
|
|
48
|
+
setPurifierSchedule: message => {
|
|
49
|
+
return new Promise((resolve, reject) => {
|
|
50
|
+
try {
|
|
51
|
+
var _message$num;
|
|
52
|
+
if (!useMqtt) {
|
|
53
|
+
reject(new Error('useMqtt is not used'));
|
|
54
|
+
return;
|
|
55
|
+
}
|
|
56
|
+
sendStructuredMessage(PurifierScheduleEnum.set, _objectSpread(_objectSpread({}, message), {}, {
|
|
57
|
+
num: (_message$num = message.num) !== null && _message$num !== void 0 ? _message$num : message.list.length
|
|
58
|
+
}), resolve, error => reject(handleMqttError(error, 'Failed to set purifier schedule')), PurifierScheduleEnum.query // 响应类型是 query,不是 set
|
|
59
|
+
);
|
|
60
|
+
} catch (error) {
|
|
61
|
+
reject(handleMqttError(error, 'Failed to set purifier schedule'));
|
|
62
|
+
}
|
|
63
|
+
});
|
|
64
|
+
}
|
|
65
|
+
};
|
|
66
|
+
};
|
|
@@ -57,7 +57,7 @@ export const useRoomProperty = () => {
|
|
|
57
57
|
ids
|
|
58
58
|
} = data;
|
|
59
59
|
const len = ids.length;
|
|
60
|
-
const sendData = _objectSpread(_objectSpread({
|
|
60
|
+
const sendData = _objectSpread(_objectSpread(_objectSpread({
|
|
61
61
|
num: (_data$num = data.num) !== null && _data$num !== void 0 ? _data$num : len,
|
|
62
62
|
ids,
|
|
63
63
|
suctions: (_data$suctions = data.suctions) !== null && _data$suctions !== void 0 ? _data$suctions : new Array(len).fill('closed'),
|
|
@@ -70,6 +70,8 @@ export const useRoomProperty = () => {
|
|
|
70
70
|
orders: data.orders
|
|
71
71
|
}, data.routePreferences && {
|
|
72
72
|
routePreferences: data.routePreferences
|
|
73
|
+
}), data.polygons && {
|
|
74
|
+
polygons: data.polygons
|
|
73
75
|
}), pickWaterFields(len, data.cisterns, data.waterValues));
|
|
74
76
|
sendStructuredMessage(RoomPropertyEnum.set, sendData, resolve, error => reject(handleMqttError(error, 'Failed to set room property')), RoomPropertyEnum.query // 响应类型是 query,不是 set
|
|
75
77
|
);
|