@ray-js/robot-data-stream 0.1.0 → 0.1.3

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.
@@ -2,6 +2,7 @@ import { MqttProvider } from './mqttProvider';
2
2
  import { useDevInfo } from './useDevInfo';
3
3
  import { usePartDivision } from './usePartDivision';
4
4
  import { usePartMerge } from './usePartMerge';
5
+ import { useResetPartDivision } from './useResetPartDivision';
5
6
  import { usePassword } from './usePassword';
6
7
  import { useWifiMap } from './useWifiMap';
7
8
  import { useQuiteHours } from './useQuiteHours';
@@ -26,7 +27,7 @@ import { useMcsRoomInfo } from './useMcsRoomInfo';
26
27
  import { useThreshold } from './useThreshold';
27
28
  import { useCustomCommand } from './useCustomCommand';
28
29
  import { defineRobotCommand } from './defineRobotCommand';
29
- export { useCarpet, useCarpetClean, useVoice, MqttProvider, useDeviceModel, useFurnitureModel, useDevInfo, usePartMerge, usePartDivision, usePassword, useWifiMap, useQuiteHours, useVirtualArea, useSpotClean, useZoneClean, useSelectRoomClean, useVirtualWall, useSchedule, useHistoryMap, useRoomProperty, useResetMap, usePurifierSchedule, useCruise, useSpotPolygons, useMcsRoomInfo, useThreshold, useCustomCommand, defineRobotCommand, };
30
+ export { useCarpet, useCarpetClean, useVoice, MqttProvider, useDeviceModel, useFurnitureModel, useDevInfo, usePartMerge, usePartDivision, useResetPartDivision, usePassword, useWifiMap, useQuiteHours, useVirtualArea, useSpotClean, useZoneClean, useSelectRoomClean, useVirtualWall, useSchedule, useHistoryMap, useRoomProperty, useResetMap, usePurifierSchedule, useCruise, useSpotPolygons, useMcsRoomInfo, useThreshold, useCustomCommand, defineRobotCommand, };
30
31
  export type { CustomCommandOptions, TSendCustomCommand } from './useCustomCommand';
31
32
  export type { RobotCommandConfig, DefinedRobotCommand } from './defineRobotCommand';
32
33
  export * from './type/protocols';
package/lib/mqtt/index.js CHANGED
@@ -2,6 +2,7 @@ import { MqttProvider } from './mqttProvider';
2
2
  import { useDevInfo } from './useDevInfo';
3
3
  import { usePartDivision } from './usePartDivision';
4
4
  import { usePartMerge } from './usePartMerge';
5
+ import { useResetPartDivision } from './useResetPartDivision';
5
6
  import { usePassword } from './usePassword';
6
7
  import { useWifiMap } from './useWifiMap';
7
8
  import { useQuiteHours } from './useQuiteHours';
@@ -26,7 +27,7 @@ import { useMcsRoomInfo } from './useMcsRoomInfo';
26
27
  import { useThreshold } from './useThreshold';
27
28
  import { useCustomCommand } from './useCustomCommand';
28
29
  import { defineRobotCommand } from './defineRobotCommand';
29
- export { useCarpet, useCarpetClean, useVoice, MqttProvider, useDeviceModel, useFurnitureModel, useDevInfo, usePartMerge, usePartDivision, usePassword, useWifiMap, useQuiteHours, useVirtualArea, useSpotClean, useZoneClean, useSelectRoomClean, useVirtualWall, useSchedule, useHistoryMap, useRoomProperty, useResetMap, usePurifierSchedule, useCruise, useSpotPolygons, useMcsRoomInfo, useThreshold, useCustomCommand, defineRobotCommand };
30
+ export { useCarpet, useCarpetClean, useVoice, MqttProvider, useDeviceModel, useFurnitureModel, useDevInfo, usePartMerge, usePartDivision, useResetPartDivision, usePassword, useWifiMap, useQuiteHours, useVirtualArea, useSpotClean, useZoneClean, useSelectRoomClean, useVirtualWall, useSchedule, useHistoryMap, useRoomProperty, useResetMap, usePurifierSchedule, useCruise, useSpotPolygons, useMcsRoomInfo, useThreshold, useCustomCommand, defineRobotCommand };
30
31
 
31
32
  // 自定义指令相关类型
32
33
 
@@ -13,6 +13,7 @@ export * from './quietHoursProtocol';
13
13
  export * from './passwordProtocol';
14
14
  export * from './partMergeProtocol';
15
15
  export * from './partDivisionProtocol';
16
+ export * from './resetPartDivisionProtocol';
16
17
  export * from './historyMapProtocol';
17
18
  export * from './furnitureModelProtocol';
18
19
  export * from './deviceModelProtocol';
@@ -13,6 +13,7 @@ export * from './quietHoursProtocol';
13
13
  export * from './passwordProtocol';
14
14
  export * from './partMergeProtocol';
15
15
  export * from './partDivisionProtocol';
16
+ export * from './resetPartDivisionProtocol';
16
17
  export * from './historyMapProtocol';
17
18
  export * from './furnitureModelProtocol';
18
19
  export * from './deviceModelProtocol';
@@ -0,0 +1,3 @@
1
+ import type { BaseResponse } from './base';
2
+ export type ResetPartDivisionResponse = BaseResponse;
3
+ export type TSetResetPartDivision = () => Promise<ResetPartDivisionResponse>;
@@ -14,6 +14,10 @@ export declare enum PartDivisionEnum {
14
14
  set = "partDivisionSet",
15
15
  query = "partDivisionRst"
16
16
  }
17
+ export declare enum ResetPartDivisionEnum {
18
+ set = "resetPartDivisionSet",
19
+ rst = "resetPartDivisionRst"
20
+ }
17
21
  export declare enum PasswordEnum {
18
22
  query = "passwordQry",
19
23
  set = "passwordSet",
@@ -24,6 +24,13 @@ export let PartDivisionEnum = /*#__PURE__*/function (PartDivisionEnum) {
24
24
  PartDivisionEnum["query"] = "partDivisionRst";
25
25
  return PartDivisionEnum;
26
26
  }({});
27
+
28
+ // 恢复当前地图的默认分区
29
+ export let ResetPartDivisionEnum = /*#__PURE__*/function (ResetPartDivisionEnum) {
30
+ ResetPartDivisionEnum["set"] = "resetPartDivisionSet";
31
+ ResetPartDivisionEnum["rst"] = "resetPartDivisionRst";
32
+ return ResetPartDivisionEnum;
33
+ }({});
27
34
  export let PasswordEnum = /*#__PURE__*/function (PasswordEnum) {
28
35
  PasswordEnum["query"] = "passwordQry";
29
36
  PasswordEnum["set"] = "passwordSet";
@@ -0,0 +1,4 @@
1
+ import type { TSetResetPartDivision } from './type/protocols';
2
+ export declare const useResetPartDivision: () => {
3
+ setResetPartDivision: TSetResetPartDivision;
4
+ };
@@ -0,0 +1,14 @@
1
+ import { handleMqttError, useStructuredMessage } from './hooks/useStructuredMessage';
2
+ import { ResetPartDivisionEnum } from './type';
3
+ export const useResetPartDivision = () => {
4
+ const {
5
+ sendStructuredMessage
6
+ } = useStructuredMessage();
7
+ return {
8
+ setResetPartDivision: () => new Promise((resolve, reject) => {
9
+ sendStructuredMessage(ResetPartDivisionEnum.set, {}, resolve, error => reject(handleMqttError(error, 'Failed to restore default partitions')), {
10
+ responseType: ResetPartDivisionEnum.rst
11
+ });
12
+ })
13
+ };
14
+ };
@@ -5,6 +5,7 @@ import { VirtualWallEnum } from './type';
5
5
  import { SingletonContext } from './mqttProvider';
6
6
  import { encodeVirtualWall0x12, requestVirtualWall0x13 } from '@ray-js/robot-protocol';
7
7
  import { pointsToString } from '../utils';
8
+ import { createVirtualWallPayload } from './virtualWall';
8
9
  import { useStructuredMessage, handleMqttError } from './hooks/useStructuredMessage';
9
10
  /**
10
11
  * 自定义 Hook,用于虚拟墙管理
@@ -73,11 +74,10 @@ export const useVirtualWall = () => {
73
74
  origin
74
75
  } = params;
75
76
  if (useMqtt) {
76
- sendStructuredMessage(VirtualWallEnum.set, {
77
- points: data.map(points => pointsToString(points, origin)),
78
- num: data.length,
79
- mode: new Array(data.length).fill('0')
80
- }, resolve, error => reject(handleMqttError(error, 'Failed to set virtual wall')), {
77
+ sendStructuredMessage(VirtualWallEnum.set, createVirtualWallPayload({
78
+ data,
79
+ origin
80
+ }), resolve, error => reject(handleMqttError(error, 'Failed to set virtual wall')), {
81
81
  responseType: VirtualWallEnum.query
82
82
  } // 响应类型是 query,不是 set
83
83
  );
@@ -0,0 +1,7 @@
1
+ import type { SetVirtualWallData } from './type/protocols/virtualWallProtocol';
2
+ export declare const createVirtualWallPayload: ({ data, origin }: SetVirtualWallData) => {
3
+ points: string[];
4
+ num: number;
5
+ modes: number[];
6
+ mode: string[];
7
+ };
@@ -0,0 +1,15 @@
1
+ import "core-js/modules/esnext.iterator.map.js";
2
+ import { pointsToString } from '../utils';
3
+ export const createVirtualWallPayload = _ref => {
4
+ let {
5
+ data,
6
+ origin
7
+ } = _ref;
8
+ return {
9
+ points: data.map(points => pointsToString(points, origin)),
10
+ num: data.length,
11
+ modes: new Array(data.length).fill(0),
12
+ // 历史兼容字段,避免存量非标固件依赖旧键名 mode;标准协议字段为 modes
13
+ mode: new Array(data.length).fill('0')
14
+ };
15
+ };
package/package.json CHANGED
@@ -1,10 +1,12 @@
1
1
  {
2
2
  "name": "@ray-js/robot-data-stream",
3
- "version": "0.1.0",
3
+ "version": "0.1.3",
4
4
  "description": "扫地机P2P数据流标准化组件",
5
5
  "main": "lib/index",
6
6
  "files": [
7
- "lib"
7
+ "lib",
8
+ "docs/reference/mqtt-hooks.md",
9
+ "docs/reference/message-format.md"
8
10
  ],
9
11
  "license": "MIT",
10
12
  "types": "lib/index.d.ts",