@ray-js/lamp-schedule-core 1.0.4-beta-15 → 1.0.5-beta.2

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 (47) hide show
  1. package/lib/config/dpCodes.d.ts +5 -1
  2. package/lib/config/dpCodes.js +5 -1
  3. package/lib/dpParser/__test__/rhythms.test.js +7 -2
  4. package/lib/dpParser/__test__/rhythmsSigmesh.test.d.ts +1 -0
  5. package/lib/dpParser/__test__/rhythmsSigmesh.test.js +263 -0
  6. package/lib/dpParser/__test__/sleepSigmesh.test.d.ts +1 -0
  7. package/lib/dpParser/__test__/sleepSigmesh.test.js +183 -0
  8. package/lib/dpParser/brightAdjustData.d.ts +10 -0
  9. package/lib/dpParser/brightAdjustData.js +43 -0
  10. package/lib/dpParser/colourDataRaw.d.ts +14 -0
  11. package/lib/dpParser/colourDataRaw.js +56 -0
  12. package/lib/dpParser/index.d.ts +4 -1
  13. package/lib/dpParser/index.js +14 -1
  14. package/lib/dpParser/rhythms/index.d.ts +9 -0
  15. package/lib/dpParser/rhythms/index.js +27 -0
  16. package/lib/dpParser/{rhythms.d.ts → rhythms/rhythmsCommon.d.ts} +2 -3
  17. package/lib/dpParser/{rhythms.js → rhythms/rhythmsCommon.js} +6 -9
  18. package/lib/dpParser/rhythms/rhythmsSigmesh.d.ts +17 -0
  19. package/lib/dpParser/rhythms/rhythmsSigmesh.js +143 -0
  20. package/lib/dpParser/sleep/index.d.ts +1 -2
  21. package/lib/dpParser/sleep/index.js +13 -12
  22. package/lib/dpParser/sleep/sleepSigmesh.d.ts +20 -0
  23. package/lib/dpParser/sleep/sleepSigmesh.js +86 -98
  24. package/lib/dpParser/stripLocalTimer.d.ts +10 -0
  25. package/lib/dpParser/stripLocalTimer.js +107 -0
  26. package/lib/dpParser/wakeup/index.d.ts +0 -2
  27. package/lib/dpParser/wakeup/index.js +12 -16
  28. package/lib/dpParser/wakeup/wakeupSigmesh.js +9 -1
  29. package/lib/hooks/useBaseLightDp.d.ts +1 -1
  30. package/lib/hooks/useBaseLightDp.js +1 -0
  31. package/lib/hooks/useCommonSupport.js +19 -0
  32. package/lib/hooks/useCycleDp.js +2 -0
  33. package/lib/hooks/useDPByProtocol.d.ts +2 -0
  34. package/lib/hooks/useRandomDp.js +2 -0
  35. package/lib/hooks/useRhythmsDp.d.ts +3 -3
  36. package/lib/hooks/useRhythmsDp.js +2 -0
  37. package/lib/hooks/useSleepDp.js +2 -0
  38. package/lib/hooks/useWakeUpDp.js +2 -0
  39. package/lib/hooks/useWakeupDp.js +2 -0
  40. package/lib/types/rhythms.d.ts +16 -0
  41. package/lib/types/rhythms.js +3 -1
  42. package/lib/types/timer.d.ts +42 -0
  43. package/lib/utils/ScheduleSupport.d.ts +4 -0
  44. package/lib/utils/ScheduleSupport.js +9 -0
  45. package/lib/utils/getDPByProtocol.d.ts +4 -0
  46. package/lib/utils/matterDeviceUtils.d.ts +4 -0
  47. package/package.json +1 -1
@@ -7,13 +7,19 @@ import { getSleepParser } from './sleep';
7
7
  import { rtcTimerParser } from './rtcTimer';
8
8
  import { timerReportParser } from './timerReport';
9
9
  import { getWakeUpParser } from './wakeup';
10
+ import { stripLocalTimerParser } from './stripLocalTimer';
11
+ import { brightAdjustDataParser } from './brightAdjustData';
12
+ import { colourDataRawParser } from './colourDataRaw';
10
13
  export { randomParser, getRandomParser } from './random';
11
14
  export { rhythmParser, getRhythmParser } from './rhythms';
12
- export { sleepParserCommon as sleepParser, getSleepParser, SleepParser } from './sleep';
15
+ export { sleepParserCommon as sleepParser, getSleepParser, SleepParser, sleepParserSigmesh } from './sleep';
13
16
  export { rtcTimerParser, getRtcParser } from './rtcTimer';
14
17
  export { cycleParser, getCycleParser } from './cycle';
15
18
  export { wakeupParserCommon as wakeupParser, getWakeUpParser, WakeUpParser } from './wakeup';
16
19
  export { timerReportParser } from './timerReport';
20
+ export { stripLocalTimerParser, getStripLocalTimerParser } from './stripLocalTimer';
21
+ export { brightAdjustDataParser, getBrightAdjustDataParser } from './brightAdjustData';
22
+ export { colourDataRawParser, getColourDataRawParser } from './colourDataRaw';
17
23
  /**
18
24
  * 自动匹配 dp 解析函数
19
25
  *
@@ -37,6 +43,13 @@ export const autoDispatchTransDpFun = dpCode => {
37
43
  return timerReportParser;
38
44
  case scheduleDpCodes.WAKE_UP_MODE:
39
45
  return getWakeUpParser();
46
+ // Beacon 设备专属 dp
47
+ case scheduleDpCodes.STRIP_LOCAL_TIMER:
48
+ return stripLocalTimerParser;
49
+ case scheduleDpCodes.BRIGHT_ADJUST_DATA:
50
+ return brightAdjustDataParser;
51
+ case scheduleDpCodes.COLOUR_DATA_RAW:
52
+ return colourDataRawParser;
40
53
  default:
41
54
  return null;
42
55
  }
@@ -0,0 +1,9 @@
1
+ import { TRhythmData, TRhythmDataSigmesh } from '../../types/rhythms';
2
+ export { default as RhythmFormatter, rhythmParserCommon } from './rhythmsCommon';
3
+ export { RhythmSigmesh, rhythmParserSigmesh } from './rhythmsSigmesh';
4
+ declare class RhythmParserDispatcher {
5
+ parser(dpValue: string): TRhythmData | TRhythmDataSigmesh;
6
+ formatter(data: TRhythmData | TRhythmDataSigmesh): string;
7
+ }
8
+ export declare const rhythmParser: RhythmParserDispatcher;
9
+ export declare const getRhythmParser: () => RhythmParserDispatcher;
@@ -0,0 +1,27 @@
1
+ import { getSupportIns } from '../../hooks/useCommonSupport';
2
+ export { default as RhythmFormatter, rhythmParserCommon } from './rhythmsCommon';
3
+ export { RhythmSigmesh, rhythmParserSigmesh } from './rhythmsSigmesh';
4
+ import { rhythmParserCommon } from './rhythmsCommon';
5
+ import { rhythmParserSigmesh } from './rhythmsSigmesh';
6
+ class RhythmParserDispatcher {
7
+ parser(dpValue) {
8
+ const support = getSupportIns();
9
+ const isSigmesh = support === null || support === void 0 ? void 0 : support.isSigMeshDevice();
10
+ if (isSigmesh) {
11
+ return rhythmParserSigmesh.parser(dpValue);
12
+ }
13
+ return rhythmParserCommon.parser(dpValue);
14
+ }
15
+ formatter(data) {
16
+ const support = getSupportIns();
17
+ const isSigmesh = support === null || support === void 0 ? void 0 : support.isSigMeshDevice();
18
+ if (isSigmesh) {
19
+ return rhythmParserSigmesh.formatter(data);
20
+ }
21
+ return rhythmParserCommon.formatter(data);
22
+ }
23
+ }
24
+ export const rhythmParser = new RhythmParserDispatcher();
25
+ export const getRhythmParser = () => {
26
+ return rhythmParser;
27
+ };
@@ -1,4 +1,4 @@
1
- import { TRhythmData } from '../types/rhythms';
1
+ import { TRhythmData } from '../../types/rhythms';
2
2
  export default class RhythmFormatter {
3
3
  uuid: string;
4
4
  defaultValue: any;
@@ -6,5 +6,4 @@ export default class RhythmFormatter {
6
6
  parser(dpValue?: string): any;
7
7
  formatter(data: TRhythmData): string;
8
8
  }
9
- export declare const rhythmParser: RhythmFormatter;
10
- export declare const getRhythmParser: () => RhythmFormatter;
9
+ export declare const rhythmParserCommon: RhythmFormatter;
@@ -2,11 +2,11 @@ import "core-js/modules/esnext.iterator.constructor.js";
2
2
  import "core-js/modules/esnext.iterator.map.js";
3
3
  import { generateDpStrStep, numToHexString } from '@ray-js/panel-sdk/lib/utils';
4
4
  import { padStart } from 'lodash-es';
5
- import { defaultValue } from '../config/rhythms/defaultValue';
6
- import { scheduleDpCodes } from '../config/dpCodes';
7
- import { scheduleLogger as ScheduleLogger } from '../utils/ScheduleLogger';
8
- import { getSupportIns } from '../hooks/useCommonSupport';
9
- import { getDPByProtocol } from '../utils/getDPByProtocol';
5
+ import { defaultValue } from '../../config/rhythms/defaultValue';
6
+ import { scheduleDpCodes } from '../../config/dpCodes';
7
+ import { scheduleLogger as ScheduleLogger } from '../../utils/ScheduleLogger';
8
+ import { getSupportIns } from '../../hooks/useCommonSupport';
9
+ import { getDPByProtocol } from '../../utils/getDPByProtocol';
10
10
  const {
11
11
  RHYTHM_MODE
12
12
  } = scheduleDpCodes;
@@ -120,7 +120,4 @@ export default class RhythmFormatter {
120
120
  }).join('')}`;
121
121
  }
122
122
  }
123
- export const rhythmParser = new RhythmFormatter();
124
- export const getRhythmParser = () => {
125
- return rhythmParser;
126
- };
123
+ export const rhythmParserCommon = new RhythmFormatter();
@@ -0,0 +1,17 @@
1
+ import { TRhythmDataSigmesh } from '../../types/rhythms';
2
+ export declare class RhythmSigmesh {
3
+ defaultValue: TRhythmDataSigmesh;
4
+ /**
5
+ * 解析 sigmesh 生物节律 DP 字符串
6
+ * 格式: version(2) + power(2) + mode(2) + weeks(2) + paramMode(2) + number(2) + nodes[valid(2) + hour(2) + minute(2) + brightness(2) + temperature(2)]
7
+ */
8
+ parser(dpValue: string): TRhythmDataSigmesh;
9
+ /**
10
+ * 将 sigmesh 生物节律数据编码为 DP 字符串
11
+ */
12
+ formatter(data: TRhythmDataSigmesh): string;
13
+ }
14
+ export declare const rhythmParserSigmesh: {
15
+ parser: (dpValue: string) => TRhythmDataSigmesh;
16
+ formatter: (dpData: TRhythmDataSigmesh) => string;
17
+ };
@@ -0,0 +1,143 @@
1
+ import "core-js/modules/esnext.iterator.constructor.js";
2
+ import "core-js/modules/esnext.iterator.map.js";
3
+ /* eslint-disable no-console */
4
+ import { generateDpStrStep, numToHexString } from '@ray-js/panel-sdk/lib/utils';
5
+ import { padStart } from 'lodash-es';
6
+ import { scheduleLogger, scheduleLogger as ScheduleLogger } from '../../utils/ScheduleLogger';
7
+ import { getSupportIns } from '../../hooks/useCommonSupport';
8
+ import { getDPByProtocol } from '../../utils/getDPByProtocol';
9
+ const to16 = num => {
10
+ return numToHexString(num);
11
+ };
12
+ const defaultSigmeshRhythmsValue = {
13
+ version: 1,
14
+ power: false,
15
+ mode: 0,
16
+ weeks: [1, 1, 1, 1, 1, 1, 1, 0],
17
+ paramMode: 1,
18
+ number: 4,
19
+ rhythms: [{
20
+ power: true,
21
+ hour: 6,
22
+ minute: 30,
23
+ brightness: 100,
24
+ temperature: 50
25
+ }, {
26
+ power: true,
27
+ hour: 11,
28
+ minute: 30,
29
+ brightness: 100,
30
+ temperature: 100
31
+ }, {
32
+ power: true,
33
+ hour: 17,
34
+ minute: 0,
35
+ brightness: 70,
36
+ temperature: 50
37
+ }, {
38
+ power: true,
39
+ hour: 20,
40
+ minute: 30,
41
+ brightness: 70,
42
+ temperature: 50
43
+ }]
44
+ };
45
+ export class RhythmSigmesh {
46
+ defaultValue = (() => defaultSigmeshRhythmsValue)();
47
+
48
+ /**
49
+ * 解析 sigmesh 生物节律 DP 字符串
50
+ * 格式: version(2) + power(2) + mode(2) + weeks(2) + paramMode(2) + number(2) + nodes[valid(2) + hour(2) + minute(2) + brightness(2) + temperature(2)]
51
+ */
52
+ parser(dpValue) {
53
+ scheduleLogger.debug('Sigmesh dpParser ===> RhythmSigmesh parser: dpValue', dpValue);
54
+ if (!dpValue) {
55
+ ScheduleLogger.warn('dpParser ===> RhythmSigmesh parser: dpValue is empty');
56
+ return this.defaultValue;
57
+ }
58
+
59
+ // 头部 12 hex chars (6 字段 x 2), 每个节点 10 hex chars (5 字段 x 2)
60
+ if (dpValue.length < 12 || (dpValue.length - 12) % 10 !== 0) {
61
+ ScheduleLogger.warn('dpParser ===> RhythmSigmesh parser: dpValue length invalid', dpValue.length);
62
+ return this.defaultValue;
63
+ }
64
+ try {
65
+ const step = generateDpStrStep(dpValue);
66
+ const version = step(2).value;
67
+ const power = !!step(2).value;
68
+ const mode = step(2).value;
69
+ const weekNum = step(2).value;
70
+ const weeks = padStart(Number(weekNum).toString(2), 8, '0').split('').reverse().map(v => parseInt(v, 10));
71
+ const paramMode = step(2).value;
72
+ const number = step(2).value;
73
+ const rhythms = [];
74
+ for (let i = 0; i < number; i++) {
75
+ const valid = !!step(2).value;
76
+ const hour = step(2).value;
77
+ const minute = step(2).value;
78
+ const brightness = step(2).value;
79
+ const temperature = step(2).value;
80
+ rhythms.push({
81
+ power: valid,
82
+ hour,
83
+ minute,
84
+ brightness,
85
+ temperature
86
+ });
87
+ }
88
+ return {
89
+ version,
90
+ power,
91
+ mode,
92
+ weeks,
93
+ paramMode,
94
+ number,
95
+ rhythms
96
+ };
97
+ } catch (err) {
98
+ ScheduleLogger.error('dpParser ===> RhythmSigmesh parser error', err);
99
+ return this.defaultValue;
100
+ }
101
+ }
102
+
103
+ /**
104
+ * 将 sigmesh 生物节律数据编码为 DP 字符串
105
+ */
106
+ formatter(data) {
107
+ scheduleLogger.debug('Sigmesh dpParser ===> RhythmSigmesh formatter: data', data);
108
+ const support = getSupportIns();
109
+ if (!data || !support) {
110
+ ScheduleLogger.error('dpParser ===> RhythmSigmesh formatter: data or support is empty');
111
+ return '';
112
+ }
113
+ try {
114
+ const {
115
+ power,
116
+ mode,
117
+ weeks,
118
+ rhythms
119
+ } = data;
120
+ const weekStr = [...weeks].reverse().join('').padStart(8, '0');
121
+ const number = rhythms.length;
122
+ const weeksValue = parseInt(weekStr, 2);
123
+
124
+ // 兼容 matter 设备,需要获取 dpCodes 来判断是否支持色温
125
+ const dpCodes = getDPByProtocol();
126
+ const isSupportWhiteTemp = support.isSupportDp(dpCodes.TEMPERATURE);
127
+ return `${to16(1)}${to16(Number(power))}${to16(mode)}${to16(weeksValue)}${to16(1)}${to16(number)}${rhythms.map(_ref => {
128
+ let {
129
+ power: valid,
130
+ hour,
131
+ minute,
132
+ brightness,
133
+ temperature
134
+ } = _ref;
135
+ return `${to16(Number(valid))}${to16(hour)}${to16(minute)}${to16(brightness)}${to16(isSupportWhiteTemp ? temperature : 100)}`;
136
+ }).join('')}`;
137
+ } catch (err) {
138
+ ScheduleLogger.error('dpParser ===> RhythmSigmesh formatter error', err);
139
+ return '';
140
+ }
141
+ }
142
+ }
143
+ export const rhythmParserSigmesh = new RhythmSigmesh();
@@ -1,8 +1,7 @@
1
- import { Support } from '../../utils/ScheduleSupport';
2
1
  export { sleepParser as sleepParserCommon, Sleep as SleepCommon } from './sleepCommon';
2
+ export { sleepParserSigmesh, SleepSigmesh } from './sleepSigmesh';
3
3
  import { TSleepDataSigmesh, TSleepData } from '../../types';
4
4
  export declare class SleepParser {
5
- support: Support;
6
5
  parser(dpStr: string): TSleepData | TSleepDataSigmesh;
7
6
  formatter(dpData: TSleepDataSigmesh | TSleepData): string;
8
7
  }
@@ -1,22 +1,23 @@
1
+ import { getSupportIns } from '../../hooks/useCommonSupport';
1
2
  export { sleepParser as sleepParserCommon, Sleep as SleepCommon } from './sleepCommon';
3
+ export { sleepParserSigmesh, SleepSigmesh } from './sleepSigmesh';
2
4
  import { sleepParser as sleepParserCommon } from './sleepCommon';
5
+ import { sleepParserSigmesh } from './sleepSigmesh';
3
6
  export class SleepParser {
4
7
  parser(dpStr) {
5
- // FIXME: 暂时不支持 Sigmesh 设备
6
- // const support = getSupportIns();
7
- // const isSigmesh = support.isSigMeshDevice();
8
- // if (isSigmesh) {
9
- // return sleepParserSigmesh.parser(dpStr) as TSleepDataSigmesh;
10
- // }
8
+ const support = getSupportIns();
9
+ const isSigmesh = support === null || support === void 0 ? void 0 : support.isSigMeshDevice();
10
+ if (isSigmesh) {
11
+ return sleepParserSigmesh.parser(dpStr);
12
+ }
11
13
  return sleepParserCommon.parser(dpStr);
12
14
  }
13
15
  formatter(dpData) {
14
- // FIXME: 暂时不支持 Sigmesh 设备
15
- // const support = getSupportIns();
16
- // const isSigmesh = support.isSigMeshDevice();
17
- // if (isSigmesh) {
18
- // return sleepParserSigmesh.formatter(dpData as TSleepDataSigmesh);
19
- // }
16
+ const support = getSupportIns();
17
+ const isSigmesh = support === null || support === void 0 ? void 0 : support.isSigMeshDevice();
18
+ if (isSigmesh) {
19
+ return sleepParserSigmesh.formatter(dpData);
20
+ }
20
21
  return sleepParserCommon.formatter(dpData);
21
22
  }
22
23
  }
@@ -0,0 +1,20 @@
1
+ import { TSleepDataSigmesh, TSleepNodeSigmesh } from '../../types';
2
+ export declare class SleepSigmesh {
3
+ defaultValue: TSleepDataSigmesh;
4
+ /**
5
+ * 解析 sigmesh 助眠 DP 字符串
6
+ * 格式: version(2) + dataMode(2) + length(2) + nodes[onOff(2) + loops(2) + step(2) + hour(2) + minute(2) + brightness(2) + temperature(2)]
7
+ * 每个节点 7 字段 x 2 hex = 14 hex chars
8
+ */
9
+ parser(dpStr: string): {
10
+ version: any;
11
+ dataMode: any;
12
+ length: any;
13
+ nodes: TSleepNodeSigmesh[];
14
+ };
15
+ formatter(data: TSleepDataSigmesh): string;
16
+ }
17
+ export declare const sleepParserSigmesh: {
18
+ parser: (dpValue: string) => TSleepDataSigmesh;
19
+ formatter: (dpData: TSleepDataSigmesh) => string;
20
+ };
@@ -1,101 +1,89 @@
1
- // /* eslint-disable no-console */
2
- // import { generateDpStrStep, numToHexString } from '@ray-js/panel-sdk/lib/utils';
3
- // import { padEnd } from 'lodash-es';
1
+ import "core-js/modules/esnext.iterator.constructor.js";
2
+ import "core-js/modules/esnext.iterator.for-each.js";
3
+ /* eslint-disable no-console */
4
+ import { generateDpStrStep, numToHexString } from '@ray-js/panel-sdk/lib/utils';
5
+ import { padEnd } from 'lodash-es';
6
+ import { scheduleLogger } from '../../utils/ScheduleLogger';
7
+ export class SleepSigmesh {
8
+ defaultValue = {
9
+ version: 0,
10
+ dataMode: '01',
11
+ length: 0,
12
+ nodes: []
13
+ };
4
14
 
5
- // import { TSleepDataSigmesh, TSleepNodeSigmesh } from '../../types';
6
- // import { isInIDEFun } from '../../utils/isInIDE';
15
+ /**
16
+ * 解析 sigmesh 助眠 DP 字符串
17
+ * 格式: version(2) + dataMode(2) + length(2) + nodes[onOff(2) + loops(2) + step(2) + hour(2) + minute(2) + brightness(2) + temperature(2)]
18
+ * 每个节点 7 字段 x 2 hex = 14 hex chars
19
+ */
20
+ parser(dpStr) {
21
+ scheduleLogger.debug('Sigmesh dpParser ===> SleepSigmesh parser: dpStr', dpStr);
22
+ if (!dpStr) {
23
+ return this.defaultValue;
24
+ }
25
+ // 头部 6 hex chars (3 字段 x 2), 每个节点 14 hex chars (7 字段 x 2)
26
+ if (dpStr.slice(6).length % 14 !== 0) {
27
+ return this.defaultValue;
28
+ }
29
+ const step = generateDpStrStep(dpStr);
30
+ const version = step(2).value; // 版本号
31
+ const dataMode = step(2).value; // 参数模式 0x01:仅含BT 0x02:仅含HSV 0x03:含HSVBT
32
+ const length = step(2).value; // 任务节点数 0x01:1 个节点 0x02:2 个节点 0x03:3 个节点 0x04:4 个节点
33
+ const nodes = [];
7
34
 
8
- // export class SleepSigmesh {
9
- // defaultValue: TSleepDataSigmesh = {
10
- // version: 0,
11
- // dataMode: '01',
12
- // length: 0,
13
- // nodes: [],
14
- // };
35
+ // 解析循环节点数据
36
+ for (let i = 0; i < length; i++) {
37
+ var _loopNum$toString;
38
+ const onOff = !!step(2).value;
39
+ const loopNum = step(2).value;
40
+ const loops = padEnd(loopNum === null || loopNum === void 0 || (_loopNum$toString = loopNum.toString(2)) === null || _loopNum$toString === void 0 ? void 0 : _loopNum$toString.split('').reverse().join(''), 7, '0');
41
+ const stepGrad = step(2).value;
42
+ const hour = step(2).value;
43
+ const minute = step(2).value;
44
+ const brightness = step(2).value;
45
+ const temperature = step(2).value;
46
+ // 注意: sleep 模式不含 duration 字段(与 wakeup 的区别)
15
47
 
16
- // parser(dpStr: string) {
17
- // if (!dpStr) {
18
- // return this.defaultValue;
19
- // }
20
- // if (dpStr.slice(6).length % 8 !== 0) {
21
- // return this.defaultValue;
22
- // }
23
- // const step = generateDpStrStep(dpStr);
24
-
25
- // const version = step(2).value; // 版本号
26
- // const dataMode = step(2).value; // 参数模式 0x01:仅含BT 0x02:仅含HSV 0x03:含HSVBT
27
- // const length = step(2).value; // 任务节点数 0x01:1 个节点 0x02:2 个节点 0x03:3 个节点 0x04:4 个节点
28
- // const nodes: TSleepNodeSigmesh[] = [];
29
-
30
- // // 解析循环节点数据
31
- // for (let i = 0; i < length; i++) {
32
- // const onOff = !!step(2).value;
33
- // const loopNum = step(2).value;
34
- // const loops = padEnd(loopNum?.toString(2)?.split('').reverse().join(''), 7, '0');
35
- // const stepGrad = step(2).value;
36
- // const hour = step(2).value;
37
- // const minute = step(2).value;
38
- // const brightness = step(2).value;
39
- // const temperature = step(2).value;
40
- // const duration = step(2).value;
41
-
42
- // const node = {
43
- // onOff, // 任务开关
44
- // loops, // 日期设定
45
- // step: stepGrad, // 渐变步进值
46
- // hour, // 起始小时
47
- // minute, // 起始分钟
48
- // brightness, // 亮度百分比
49
- // temperature, // 色温百分比
50
- // duration, // 持续时间 0 - 24, 对应 0-120 => 5分钟一个步进
51
- // index: i,
52
- // };
53
- // nodes.push(node);
54
- // }
55
-
56
- // return {
57
- // version,
58
- // dataMode,
59
- // length,
60
- // nodes,
61
- // };
62
- // }
63
-
64
- // formatter(data: TSleepDataSigmesh) {
65
- // const result = [
66
- // numToHexString(data.version),
67
- // numToHexString(data.dataMode === '01' ? 1 : data.dataMode === '02' ? 2 : 3),
68
- // numToHexString(data.length),
69
- // ];
70
-
71
- // data.nodes.forEach(node => {
72
- // result.push(
73
- // numToHexString(node.onOff ? 1 : 0),
74
- // numToHexString(parseInt(node?.loops?.split('')?.reverse()?.join(''), 2)),
75
- // numToHexString(node.step),
76
- // numToHexString(node.hour),
77
- // numToHexString(node.minute),
78
- // numToHexString(node.brightness),
79
- // numToHexString(node.temperature)
80
- // );
81
- // });
82
-
83
- // return result.join('');
84
- // }
85
- // }
86
-
87
- // export const sleepParserSigmesh: {
88
- // parser: (dpValue: string) => TSleepDataSigmesh;
89
- // formatter: (dpData: TSleepDataSigmesh) => string;
90
- // } = new SleepSigmesh();
91
-
92
- // // 使用示例
93
- // // if (isInIDEFun()) {
94
- // // const dpStr = '01020301020304050607080102030405060708';
95
- // // const result = sleepParserSigmesh.parser(dpStr);
96
- // // const formatted = sleepParserSigmesh.formatter(result);
97
- // // console.warn(formatted, 'formattedformatted1');
98
- // // if (dpStr !== formatted) {
99
- // // throw new Error('sleepParserSigmesh dp 转换失败, 请检查');
100
- // // }
101
- // // }
48
+ const node = {
49
+ onOff,
50
+ // 任务开关
51
+ loops,
52
+ // 日期设定
53
+ step: stepGrad,
54
+ // 渐变步进值
55
+ hour,
56
+ // 起始小时
57
+ minute,
58
+ // 起始分钟
59
+ brightness,
60
+ // 亮度百分比
61
+ temperature,
62
+ // 色温百分比
63
+ index: i
64
+ };
65
+ nodes.push(node);
66
+ }
67
+ return {
68
+ version,
69
+ dataMode,
70
+ length,
71
+ nodes
72
+ };
73
+ }
74
+ formatter(data) {
75
+ var _data$nodes$length, _data$nodes;
76
+ scheduleLogger.debug('Sigmesh dpParser ===> SleepSigmesh formatter: data', data);
77
+ // dataMode 可能是字符串 ('01'/'02'/'03') 或数字 (1/2/3)
78
+ const dataModeNum = typeof data.dataMode === 'string' ? parseInt(data.dataMode, 10) : data.dataMode;
79
+ // 使用 nodes.length 而非 data.length,因为调用方可能未更新 length 字段
80
+ const nodeCount = (_data$nodes$length = (_data$nodes = data.nodes) === null || _data$nodes === void 0 ? void 0 : _data$nodes.length) !== null && _data$nodes$length !== void 0 ? _data$nodes$length : data.length;
81
+ const result = [numToHexString(data.version), numToHexString(dataModeNum), numToHexString(nodeCount)];
82
+ data.nodes.forEach(node => {
83
+ var _node$loops;
84
+ result.push(numToHexString(node.onOff ? 1 : 0), numToHexString(parseInt(node === null || node === void 0 || (_node$loops = node.loops) === null || _node$loops === void 0 || (_node$loops = _node$loops.split('')) === null || _node$loops === void 0 || (_node$loops = _node$loops.reverse()) === null || _node$loops === void 0 ? void 0 : _node$loops.join(''), 2)), numToHexString(node.step), numToHexString(node.hour), numToHexString(node.minute), numToHexString(node.brightness), numToHexString(node.temperature));
85
+ });
86
+ return result.join('');
87
+ }
88
+ }
89
+ export const sleepParserSigmesh = new SleepSigmesh();
@@ -0,0 +1,10 @@
1
+ import { TStripLocalTimerData } from '../types';
2
+ export declare class StripLocalTimerFormatter {
3
+ parser(dpValue: string): Partial<TStripLocalTimerData>;
4
+ formatter(data: TStripLocalTimerData): string;
5
+ }
6
+ export declare const stripLocalTimerParser: {
7
+ parser: (dpValue: string) => Partial<TStripLocalTimerData>;
8
+ formatter: (data: TStripLocalTimerData) => string;
9
+ };
10
+ export declare const getStripLocalTimerParser: () => StripLocalTimerFormatter;
@@ -0,0 +1,107 @@
1
+ import "core-js/modules/esnext.iterator.constructor.js";
2
+ import "core-js/modules/esnext.iterator.map.js";
3
+ /* eslint-disable no-console */
4
+ import padStart from 'lodash/padStart';
5
+ import { generateDpStrStep, numToHexString } from '@ray-js/panel-sdk/lib/utils';
6
+ import { scheduleLogger as ScheduleLogger } from '../utils/ScheduleLogger';
7
+ const toHex = function (value) {
8
+ let len = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 2;
9
+ return numToHexString(value).padStart(len, '0');
10
+ };
11
+ export class StripLocalTimerFormatter {
12
+ parser(dpValue) {
13
+ try {
14
+ ScheduleLogger.debug('dpParser ===> StripLocalTimerFormatter parser dpValue:', dpValue);
15
+ if (!dpValue) {
16
+ return {};
17
+ }
18
+ const step = generateDpStrStep(dpValue);
19
+ const step2 = () => step(2).value;
20
+ const step4 = () => step(4).value;
21
+ step2();
22
+ step2();
23
+ step4();
24
+ step2();
25
+ const opt = Array.from(step2().toString(2).padStart(8, '0')).map(i => Number(i));
26
+ const timerId = parseInt(opt.slice(0, 4).join(''), 2);
27
+ const time1 = opt.slice(4).join('');
28
+ const opt1 = Array.from(step2().toString(2).padStart(8, '0')).map(i => Number(i));
29
+ const time2 = parseInt(opt1.slice(0, 4).join('').padStart(8, '0'), 2);
30
+ const time = parseInt(time1 + time2, 2);
31
+ const opt2 = Array.from(step2().toString(2).padStart(8, '0')).map(i => Number(i));
32
+ const status = !!opt2[0];
33
+ const repeat = opt2.slice(1, 8).join('');
34
+ const mode = step2();
35
+ const result = {
36
+ timerId,
37
+ status,
38
+ time,
39
+ repeat,
40
+ mode
41
+ };
42
+ if (mode === 1) {
43
+ const lampPower = step2() === 1;
44
+ result.power = lampPower;
45
+ } else if (mode === 2) {
46
+ const brightness = step2();
47
+ const temperature = step2();
48
+ result.brightness = brightness;
49
+ result.temperature = temperature;
50
+ } else if (mode === 3) {
51
+ const sceneId = step2();
52
+ result.sceneId = sceneId;
53
+ } else if (mode === 4) {
54
+ const hue = step4();
55
+ const saturation = step2();
56
+ const value = step2();
57
+ result.hue = hue;
58
+ result.saturation = saturation;
59
+ result.value = value;
60
+ }
61
+ return result;
62
+ } catch (error) {
63
+ ScheduleLogger.error('dpParser ===> StripLocalTimerFormatter parser error:', error);
64
+ return {};
65
+ }
66
+ }
67
+ formatter(data) {
68
+ try {
69
+ ScheduleLogger.debug('dpParser ===> StripLocalTimerFormatter formatter data:', data);
70
+ const now = new Date();
71
+ const dayStr = toHex(now.getDay(), 2);
72
+ const minuteStr = toHex(now.getMinutes() + now.getHours() * 60, 4);
73
+ const secondStr = toHex(now.getSeconds(), 2);
74
+ const statusStr = data.status ? '1' : '0';
75
+ const timerIdStr = padStart(data.timerId.toString(2), 7, '0');
76
+ const idStr = toHex(parseInt(`${statusStr}${timerIdStr}`, 2), 2);
77
+ const repeatStr = toHex(parseInt(data.repeat.split('').reverse().join(''), 2), 2);
78
+ const startTimeStr = toHex(data.time, 4);
79
+ let dpDataStr = '';
80
+ if (data.power !== undefined) {
81
+ const powerStr = data.power ? '01' : '00';
82
+ dpDataStr = `01${powerStr}`;
83
+ } else if (data.hue !== undefined) {
84
+ const hueStr = toHex(data.hue, 4);
85
+ const saturationStr = toHex(data.saturation || 0);
86
+ const valueStr = toHex(data.value || 0);
87
+ dpDataStr = `04${hueStr}${saturationStr}${valueStr}`;
88
+ } else if (data.sceneId !== undefined) {
89
+ const sceneStr = toHex(data.sceneId);
90
+ dpDataStr = `03${sceneStr}`;
91
+ } else if (data.brightness !== undefined) {
92
+ const brightStr = toHex(data.brightness);
93
+ const temperatureStr = toHex(data.temperature || 0);
94
+ dpDataStr = `02${brightStr}${temperatureStr}`;
95
+ }
96
+ const modeStr = dpDataStr.substring(0, 2);
97
+ return `${'00'}${dayStr}${minuteStr}${secondStr}${idStr}${repeatStr}${startTimeStr}${modeStr}${dpDataStr}`;
98
+ } catch (error) {
99
+ ScheduleLogger.error('dpParser ===> StripLocalTimerFormatter formatter error:', error);
100
+ return '';
101
+ }
102
+ }
103
+ }
104
+ export const stripLocalTimerParser = new StripLocalTimerFormatter();
105
+ export const getStripLocalTimerParser = () => {
106
+ return stripLocalTimerParser;
107
+ };
@@ -1,9 +1,7 @@
1
- import { Support } from '../../utils/ScheduleSupport';
2
1
  export { wakeupParser as wakeupParserCommon, WakeUp as WakeUpCommon } from './wakeupCommon';
3
2
  export { wakeupParserSigmesh, WakeUpSigmesh } from './wakeupSigmesh';
4
3
  import { TWakeUpDataSigmesh, TWakeUpData } from '../../types';
5
4
  export declare class WakeUpParser {
6
- support: Support;
7
5
  parser(dpStr: string): TWakeUpData | TWakeUpDataSigmesh;
8
6
  formatter(dpData: TWakeUpDataSigmesh | TWakeUpData): string;
9
7
  }