@ray-js/lamp-schedule-core 1.0.0-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.
Files changed (246) hide show
  1. package/README.md +565 -0
  2. package/lib/config/dpCodes.d.ts +27 -0
  3. package/lib/config/dpCodes.js +30 -0
  4. package/lib/config/index.d.ts +2 -0
  5. package/lib/config/index.js +2 -0
  6. package/lib/config/rhythms/defaultValue.d.ts +18 -0
  7. package/lib/config/rhythms/defaultValue.js +72 -0
  8. package/lib/config/rhythms/index.d.ts +10 -0
  9. package/lib/config/rhythms/index.js +35 -0
  10. package/lib/conflict/ConflictResolver.d.ts +2 -0
  11. package/lib/conflict/ConflictResolver.js +284 -0
  12. package/lib/conflict/__test__/ConflictResolver.test.d.ts +1 -0
  13. package/lib/conflict/__test__/ConflictResolver.test.js +183 -0
  14. package/lib/conflict/__test__/index.test.d.ts +1 -0
  15. package/lib/conflict/__test__/index.test.js +385 -0
  16. package/lib/conflict/__test__/scheduleDataManager.test.d.ts +1 -0
  17. package/lib/conflict/__test__/scheduleDataManager.test.js +170 -0
  18. package/lib/conflict/__test__/transform.test.d.ts +1 -0
  19. package/lib/conflict/__test__/transform.test.js +454 -0
  20. package/lib/conflict/__test__/updateDeviceDp.d.ts +1 -0
  21. package/lib/conflict/__test__/updateDeviceDp.js +114 -0
  22. package/lib/conflict/index.d.ts +42 -0
  23. package/lib/conflict/index.js +103 -0
  24. package/lib/conflict/scheduleDataManager.d.ts +12 -0
  25. package/lib/conflict/scheduleDataManager.js +79 -0
  26. package/lib/conflict/transform.d.ts +71 -0
  27. package/lib/conflict/transform.js +251 -0
  28. package/lib/conflict/type.d.ts +55 -0
  29. package/lib/conflict/type.js +17 -0
  30. package/lib/conflict/updateDeviceDp.d.ts +1 -0
  31. package/lib/conflict/updateDeviceDp.js +41 -0
  32. package/lib/constant/index.d.ts +5 -0
  33. package/lib/constant/index.js +5 -0
  34. package/lib/context/index.d.ts +3 -0
  35. package/lib/context/index.js +3 -0
  36. package/lib/context/rhythms/actions.d.ts +20 -0
  37. package/lib/context/rhythms/actions.js +52 -0
  38. package/lib/context/rhythms/index.d.ts +5 -0
  39. package/lib/context/rhythms/index.js +51 -0
  40. package/lib/context/rhythms/reducer.d.ts +24 -0
  41. package/lib/context/rhythms/reducer.js +38 -0
  42. package/lib/context/schedule/actions.d.ts +7 -0
  43. package/lib/context/schedule/actions.js +51 -0
  44. package/lib/context/schedule/context.d.ts +6 -0
  45. package/lib/context/schedule/context.js +52 -0
  46. package/lib/context/schedule/index.d.ts +1 -0
  47. package/lib/context/schedule/index.js +1 -0
  48. package/lib/context/schedule/reducer.d.ts +16 -0
  49. package/lib/context/schedule/reducer.js +104 -0
  50. package/lib/context/schedule/type.d.ts +41 -0
  51. package/lib/context/schedule/type.js +11 -0
  52. package/lib/context/timer/actions.d.ts +8 -0
  53. package/lib/context/timer/actions.js +52 -0
  54. package/lib/context/timer/context.d.ts +10 -0
  55. package/lib/context/timer/context.js +53 -0
  56. package/lib/context/timer/index.d.ts +1 -0
  57. package/lib/context/timer/index.js +1 -0
  58. package/lib/context/timer/reducer.d.ts +15 -0
  59. package/lib/context/timer/reducer.js +70 -0
  60. package/lib/context/timer/type.d.ts +46 -0
  61. package/lib/context/timer/type.js +24 -0
  62. package/lib/dpParser/README.md +63 -0
  63. package/lib/dpParser/__test__/cycle.test.d.ts +1 -0
  64. package/lib/dpParser/__test__/cycle.test.js +258 -0
  65. package/lib/dpParser/__test__/random.test.d.ts +1 -0
  66. package/lib/dpParser/__test__/random.test.js +211 -0
  67. package/lib/dpParser/__test__/rhythms.test.d.ts +1 -0
  68. package/lib/dpParser/__test__/rhythms.test.js +71 -0
  69. package/lib/dpParser/__test__/rtcTimer.test.d.ts +1 -0
  70. package/lib/dpParser/__test__/rtcTimer.test.js +235 -0
  71. package/lib/dpParser/__test__/sleep.test.d.ts +1 -0
  72. package/lib/dpParser/__test__/sleep.test.js +71 -0
  73. package/lib/dpParser/__test__/sleepCommon.test.d.ts +1 -0
  74. package/lib/dpParser/__test__/sleepCommon.test.js +197 -0
  75. package/lib/dpParser/__test__/timerReport.test.d.ts +1 -0
  76. package/lib/dpParser/__test__/timerReport.test.js +100 -0
  77. package/lib/dpParser/__test__/wakeup.test.d.ts +1 -0
  78. package/lib/dpParser/__test__/wakeup.test.js +69 -0
  79. package/lib/dpParser/__test__/wakeupCommon.test.d.ts +1 -0
  80. package/lib/dpParser/__test__/wakeupCommon.test.js +131 -0
  81. package/lib/dpParser/cycle/index.d.ts +15 -0
  82. package/lib/dpParser/cycle/index.js +134 -0
  83. package/lib/dpParser/index.d.ts +23 -0
  84. package/lib/dpParser/index.js +43 -0
  85. package/lib/dpParser/random/index.d.ts +15 -0
  86. package/lib/dpParser/random/index.js +127 -0
  87. package/lib/dpParser/rhythms.d.ts +41 -0
  88. package/lib/dpParser/rhythms.js +116 -0
  89. package/lib/dpParser/rtcTimer.d.ts +17 -0
  90. package/lib/dpParser/rtcTimer.js +300 -0
  91. package/lib/dpParser/sleep/index.d.ts +9 -0
  92. package/lib/dpParser/sleep/index.js +29 -0
  93. package/lib/dpParser/sleep/sleepCommon.d.ts +11 -0
  94. package/lib/dpParser/sleep/sleepCommon.js +117 -0
  95. package/lib/dpParser/sleep/sleepSigmesh.d.ts +0 -0
  96. package/lib/dpParser/sleep/sleepSigmesh.js +101 -0
  97. package/lib/dpParser/timerReport.d.ts +11 -0
  98. package/lib/dpParser/timerReport.js +43 -0
  99. package/lib/dpParser/utils.d.ts +27 -0
  100. package/lib/dpParser/utils.js +53 -0
  101. package/lib/dpParser/wakeup/index.d.ts +10 -0
  102. package/lib/dpParser/wakeup/index.js +34 -0
  103. package/lib/dpParser/wakeup/wakeupCommon.d.ts +11 -0
  104. package/lib/dpParser/wakeup/wakeupCommon.js +106 -0
  105. package/lib/dpParser/wakeup/wakeupSigmesh.d.ts +15 -0
  106. package/lib/dpParser/wakeup/wakeupSigmesh.js +86 -0
  107. package/lib/hooks/__test__/useCommon.test.d.ts +1 -0
  108. package/lib/hooks/__test__/useCommon.test.js +72 -0
  109. package/lib/hooks/__test__/useCountdownDp.test.d.ts +1 -0
  110. package/lib/hooks/__test__/useCountdownDp.test.js +82 -0
  111. package/lib/hooks/__test__/useCycleDp.test.d.ts +1 -0
  112. package/lib/hooks/__test__/useCycleDp.test.js +92 -0
  113. package/lib/hooks/__test__/useRandomDp.test.d.ts +1 -0
  114. package/lib/hooks/__test__/useRandomDp.test.js +88 -0
  115. package/lib/hooks/__test__/useRhythmsDp.test.d.ts +1 -0
  116. package/lib/hooks/__test__/useRhythmsDp.test.js +81 -0
  117. package/lib/hooks/__test__/useSleepDp.test.d.ts +1 -0
  118. package/lib/hooks/__test__/useSleepDp.test.js +127 -0
  119. package/lib/hooks/__test__/useTimeFlush.test.d.ts +1 -0
  120. package/lib/hooks/__test__/useTimeFlush.test.js +109 -0
  121. package/lib/hooks/__test__/useTimerDp.test.d.ts +1 -0
  122. package/lib/hooks/__test__/useTimerDp.test.js +79 -0
  123. package/lib/hooks/__test__/useTimerOperate.test.d.ts +1 -0
  124. package/lib/hooks/__test__/useTimerOperate.test.js +286 -0
  125. package/lib/hooks/__test__/useTimerOperateCloud.test.d.ts +1 -0
  126. package/lib/hooks/__test__/useTimerOperateCloud.test.js +190 -0
  127. package/lib/hooks/__test__/useTimerOperateLocal.test.d.ts +1 -0
  128. package/lib/hooks/__test__/useTimerOperateLocal.test.js +216 -0
  129. package/lib/hooks/__test__/useTimerReportDp.test.d.ts +1 -0
  130. package/lib/hooks/__test__/useTimerReportDp.test.js +93 -0
  131. package/lib/hooks/__test__/useTimerSupport.test.d.ts +1 -0
  132. package/lib/hooks/__test__/useTimerSupport.test.js +110 -0
  133. package/lib/hooks/__test__/useWakeUpDp.test.d.ts +1 -0
  134. package/lib/hooks/__test__/useWakeUpDp.test.js +129 -0
  135. package/lib/hooks/useBaseLightDp.d.ts +21 -0
  136. package/lib/hooks/useBaseLightDp.js +165 -0
  137. package/lib/hooks/useCommon.d.ts +29 -0
  138. package/lib/hooks/useCommon.js +59 -0
  139. package/lib/hooks/useCommonSupport.d.ts +25 -0
  140. package/lib/hooks/useCommonSupport.js +241 -0
  141. package/lib/hooks/useCountdownDp.d.ts +13 -0
  142. package/lib/hooks/useCountdownDp.js +28 -0
  143. package/lib/hooks/useCountdownSupport.d.ts +9 -0
  144. package/lib/hooks/useCountdownSupport.js +13 -0
  145. package/lib/hooks/useCycleDp.d.ts +7 -0
  146. package/lib/hooks/useCycleDp.js +21 -0
  147. package/lib/hooks/useCycleSupport.d.ts +12 -0
  148. package/lib/hooks/useCycleSupport.js +16 -0
  149. package/lib/hooks/useRandomDp.d.ts +7 -0
  150. package/lib/hooks/useRandomDp.js +21 -0
  151. package/lib/hooks/useRandomSupport.d.ts +12 -0
  152. package/lib/hooks/useRandomSupport.js +16 -0
  153. package/lib/hooks/useRhythmsDp.d.ts +7 -0
  154. package/lib/hooks/useRhythmsDp.js +23 -0
  155. package/lib/hooks/useSleepDp.d.ts +6 -0
  156. package/lib/hooks/useSleepDp.js +21 -0
  157. package/lib/hooks/useSleepSupport.d.ts +8 -0
  158. package/lib/hooks/useSleepSupport.js +13 -0
  159. package/lib/hooks/useTimeFlush.d.ts +8 -0
  160. package/lib/hooks/useTimeFlush.js +31 -0
  161. package/lib/hooks/useTimerDp.d.ts +5 -0
  162. package/lib/hooks/useTimerDp.js +25 -0
  163. package/lib/hooks/useTimerFlushList.d.ts +11 -0
  164. package/lib/hooks/useTimerFlushList.js +53 -0
  165. package/lib/hooks/useTimerOperate.d.ts +68 -0
  166. package/lib/hooks/useTimerOperate.js +403 -0
  167. package/lib/hooks/useTimerOperateCloud.d.ts +31 -0
  168. package/lib/hooks/useTimerOperateCloud.js +233 -0
  169. package/lib/hooks/useTimerOperateLocal.d.ts +40 -0
  170. package/lib/hooks/useTimerOperateLocal.js +310 -0
  171. package/lib/hooks/useTimerReportDp.d.ts +15 -0
  172. package/lib/hooks/useTimerReportDp.js +48 -0
  173. package/lib/hooks/useTimerSupport.d.ts +13 -0
  174. package/lib/hooks/useTimerSupport.js +38 -0
  175. package/lib/hooks/useWakeUpDp.d.ts +6 -0
  176. package/lib/hooks/useWakeUpDp.js +21 -0
  177. package/lib/hooks/useWakeUpSupport.d.ts +8 -0
  178. package/lib/hooks/useWakeUpSupport.js +13 -0
  179. package/lib/hooks/useWakeupDp.d.ts +6 -0
  180. package/lib/hooks/useWakeupDp.js +21 -0
  181. package/lib/hooks/useWakeupSupport.d.ts +8 -0
  182. package/lib/hooks/useWakeupSupport.js +13 -0
  183. package/lib/i18n/index.d.ts +142 -0
  184. package/lib/i18n/index.js +7 -0
  185. package/lib/i18n/rhythms.d.ts +73 -0
  186. package/lib/i18n/rhythms.js +72 -0
  187. package/lib/i18n/strings.d.ts +73 -0
  188. package/lib/i18n/strings.js +6 -0
  189. package/lib/index.d.ts +51 -0
  190. package/lib/index.js +64 -0
  191. package/lib/types/countdown.d.ts +3 -0
  192. package/lib/types/countdown.js +1 -0
  193. package/lib/types/cycle.d.ts +22 -0
  194. package/lib/types/cycle.js +1 -0
  195. package/lib/types/global.d.ts +9 -0
  196. package/lib/types/index.d.ts +331 -0
  197. package/lib/types/index.js +76 -0
  198. package/lib/types/random.d.ts +20 -0
  199. package/lib/types/random.js +1 -0
  200. package/lib/types/rhythms.d.ts +79 -0
  201. package/lib/types/rhythms.js +15 -0
  202. package/lib/types/sleep.d.ts +36 -0
  203. package/lib/types/sleep.js +1 -0
  204. package/lib/types/timer.d.ts +107 -0
  205. package/lib/types/timer.js +1 -0
  206. package/lib/types/wakeup.d.ts +38 -0
  207. package/lib/types/wakeup.js +1 -0
  208. package/lib/utils/ScheduleCache.d.ts +19 -0
  209. package/lib/utils/ScheduleCache.js +39 -0
  210. package/lib/utils/ScheduleCloudProperty.d.ts +75 -0
  211. package/lib/utils/ScheduleCloudProperty.js +220 -0
  212. package/lib/utils/ScheduleDataSync.d.ts +82 -0
  213. package/lib/utils/ScheduleDataSync.js +127 -0
  214. package/lib/utils/ScheduleEmit.d.ts +67 -0
  215. package/lib/utils/ScheduleEmit.js +61 -0
  216. package/lib/utils/ScheduleLogger.d.ts +19 -0
  217. package/lib/utils/ScheduleLogger.js +71 -0
  218. package/lib/utils/ScheduleSupport.d.ts +131 -0
  219. package/lib/utils/ScheduleSupport.js +373 -0
  220. package/lib/utils/ScheduleUtils.d.ts +12 -0
  221. package/lib/utils/ScheduleUtils.js +51 -0
  222. package/lib/utils/__test__/ScheduleCloudProperty.test.d.ts +1 -0
  223. package/lib/utils/__test__/ScheduleCloudProperty.test.js +320 -0
  224. package/lib/utils/__test__/ScheduleSupport.test.d.ts +1 -0
  225. package/lib/utils/__test__/ScheduleSupport.test.js +211 -0
  226. package/lib/utils/__test__/ScheduleUtils.test.d.ts +1 -0
  227. package/lib/utils/__test__/ScheduleUtils.test.js +119 -0
  228. package/lib/utils/__test__/common.test.d.ts +1 -0
  229. package/lib/utils/__test__/common.test.js +147 -0
  230. package/lib/utils/__test__/storage.test.d.ts +1 -0
  231. package/lib/utils/__test__/storage.test.js +98 -0
  232. package/lib/utils/__test__/time.test.d.ts +1 -0
  233. package/lib/utils/__test__/time.test.js +146 -0
  234. package/lib/utils/common.d.ts +23 -0
  235. package/lib/utils/common.js +109 -0
  236. package/lib/utils/dpState.d.ts +5 -0
  237. package/lib/utils/dpState.js +27 -0
  238. package/lib/utils/getCachedSystemInfo.d.ts +39 -0
  239. package/lib/utils/getCachedSystemInfo.js +20 -0
  240. package/lib/utils/isInIDE.d.ts +1 -0
  241. package/lib/utils/isInIDE.js +5 -0
  242. package/lib/utils/storage.d.ts +5 -0
  243. package/lib/utils/storage.js +32 -0
  244. package/lib/utils/time.d.ts +40 -0
  245. package/lib/utils/time.js +84 -0
  246. package/package.json +78 -0
@@ -0,0 +1,69 @@
1
+ import { WakeUpParser } from '../wakeup';
2
+ describe('WakeUpParser', () => {
3
+ const parser = new WakeUpParser();
4
+ it('should return default value when parsing empty string', () => {
5
+ const result = parser.parser('');
6
+ expect(result).toEqual({
7
+ version: 0,
8
+ number: 0,
9
+ nodes: []
10
+ });
11
+ });
12
+ it('should format default value correctly', () => {
13
+ const result = parser.formatter({
14
+ version: 0,
15
+ number: 0,
16
+ nodes: []
17
+ });
18
+ // 根据 wakeupCommon.ts 的 formatter 逻辑,空数据会返回 '0000'
19
+ expect(result).toBe('0000');
20
+ });
21
+ it('should parse a valid dpStr and format it back for WakeUpCommon', () => {
22
+ // 示例 dpStr: 版本0, 节点数1, 节点1: 开, 周一, 步进1, 10:30, H:120,S:50,V:80,B:0,T:0, 持续时间1
23
+ const dpStr = '00010102010a1e012c3250000001';
24
+ const expectedParsedData = {
25
+ version: 0,
26
+ number: 1,
27
+ nodes: [{
28
+ onOff: true,
29
+ loops: '0100000',
30
+ // Monday
31
+ step: 1,
32
+ hour: 10,
33
+ minute: 30,
34
+ hue: 144,
35
+ saturation: 50,
36
+ value: 80,
37
+ brightness: 0,
38
+ temperature: 0,
39
+ duration: 1,
40
+ index: 0
41
+ }]
42
+ };
43
+ const parsedResult = parser.parser(dpStr);
44
+ expect(parsedResult).toEqual(expectedParsedData);
45
+ const formattedResult = parser.formatter(expectedParsedData);
46
+ expect(formattedResult.toLowerCase()).toBe(dpStr.toLowerCase());
47
+ });
48
+ it('should handle dpStr with more than 4 nodes by taking only first 4 for WakeUpCommon', () => {
49
+ // 版本0, 节点数4 (即使dpStr包含5个节点数据)
50
+
51
+ // node 5 (this one should be ignored by parser if number is 4)
52
+ const result = parser.parser('0004' +
53
+ // version 0, number 4
54
+ '0102010a1e012c3250000001' +
55
+ // node 1
56
+ '0104020b2801181e32000002' +
57
+ // node 2
58
+ '0008030c3c00000a19000003' +
59
+ // node 3
60
+ '0110040d460000000f000004' +
61
+ // node 4
62
+ '0120050e500000640a000005');
63
+ expect(result.nodes.length).toBe(4);
64
+ });
65
+
66
+ // 注意: Sigmesh 相关的测试需要模拟 support.isSigMeshDevice() 返回 true
67
+ // 由于当前 SleepParser 和 WakeUpParser 的实现中 Sigmesh 部分被注释掉了,
68
+ // 我们暂时无法直接测试 Sigmesh 的逻辑。如果需要测试,需要解除注释并可能需要 mock `getSupportIns`。
69
+ });
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,131 @@
1
+ import { wakeupParser } from '../wakeup/wakeupCommon';
2
+ describe('WakeUp Parser', () => {
3
+ test('应该返回默认值当输入为空字符串时', () => {
4
+ const result = wakeupParser.parser('');
5
+ expect(result).toEqual({
6
+ version: 0,
7
+ number: 0,
8
+ nodes: []
9
+ });
10
+ });
11
+ test('应该正确解析单个节点的数据', () => {
12
+ // 用 formatter 生成一组数据
13
+ const data = {
14
+ version: 1,
15
+ number: 1,
16
+ nodes: [{
17
+ onOff: true,
18
+ loops: '0000010',
19
+ // 周一
20
+ step: 1,
21
+ hour: 8,
22
+ minute: 30,
23
+ hue: 180,
24
+ saturation: 50,
25
+ value: 50,
26
+ brightness: 50,
27
+ temperature: 50,
28
+ duration: 30,
29
+ index: 0
30
+ }]
31
+ };
32
+ const dpStr = wakeupParser.formatter(data);
33
+ const result = wakeupParser.parser(dpStr);
34
+ expect(result.version).toBe(1);
35
+ expect(result.number).toBe(1);
36
+ expect(result.nodes).toHaveLength(1);
37
+ expect(result.nodes[0]).toEqual(data.nodes[0]);
38
+ });
39
+ test('应该正确格式化数据', () => {
40
+ const data = {
41
+ version: 1,
42
+ number: 1,
43
+ nodes: [{
44
+ onOff: true,
45
+ loops: '0000010',
46
+ // 周一
47
+ step: 1,
48
+ hour: 8,
49
+ minute: 30,
50
+ hue: 180,
51
+ saturation: 50,
52
+ value: 50,
53
+ brightness: 50,
54
+ temperature: 50,
55
+ duration: 30,
56
+ index: 0
57
+ }]
58
+ };
59
+ const result = wakeupParser.formatter(data);
60
+ // 直接用 parser 解析,验证一致性
61
+ const parsed = wakeupParser.parser(result);
62
+ expect(parsed.nodes[0]).toEqual(data.nodes[0]);
63
+ });
64
+ test('应该处理多个节点的情况', () => {
65
+ const data = {
66
+ version: 1,
67
+ number: 2,
68
+ nodes: [{
69
+ onOff: true,
70
+ loops: '0000010',
71
+ // 周一
72
+ step: 1,
73
+ hour: 8,
74
+ minute: 30,
75
+ hue: 180,
76
+ saturation: 50,
77
+ value: 50,
78
+ brightness: 50,
79
+ temperature: 50,
80
+ duration: 30,
81
+ index: 0
82
+ }, {
83
+ onOff: true,
84
+ loops: '0100000',
85
+ // 周六
86
+ step: 2,
87
+ hour: 9,
88
+ minute: 0,
89
+ hue: 200,
90
+ saturation: 60,
91
+ value: 60,
92
+ brightness: 60,
93
+ temperature: 60,
94
+ duration: 45,
95
+ index: 1
96
+ }]
97
+ };
98
+ const result = wakeupParser.formatter(data);
99
+ const parsed = wakeupParser.parser(result);
100
+ expect(parsed.version).toBe(data.version);
101
+ expect(parsed.number).toBe(data.number);
102
+ expect(parsed.nodes).toHaveLength(2);
103
+ expect(parsed.nodes[0]).toEqual(data.nodes[0]);
104
+ expect(parsed.nodes[1]).toEqual(data.nodes[1]);
105
+ });
106
+ test('应该处理默认颜色值', () => {
107
+ const result = wakeupParser.formatter({
108
+ version: 1,
109
+ number: 1,
110
+ nodes: [{
111
+ onOff: true,
112
+ loops: '0000010',
113
+ step: 1,
114
+ hour: 8,
115
+ minute: 30,
116
+ hue: 0,
117
+ saturation: 0,
118
+ value: 0,
119
+ brightness: 0,
120
+ temperature: 0,
121
+ duration: 30,
122
+ index: 0
123
+ }]
124
+ });
125
+ const parsed = wakeupParser.parser(result);
126
+ expect(parsed.nodes[0].saturation).toBe(0);
127
+ expect(parsed.nodes[0].value).toBe(0);
128
+ expect(parsed.nodes[0].brightness).toBe(0);
129
+ expect(parsed.nodes[0].temperature).toBe(0);
130
+ });
131
+ });
@@ -0,0 +1,15 @@
1
+ import { TCycleData, TCycleNode } from '../../types';
2
+ declare class CycleTimerParser {
3
+ parser(dpValue: string): TCycleData;
4
+ formatter(data: TCycleData): string;
5
+ }
6
+ export declare const cycleParser: {
7
+ parser: (dpValue: string) => {
8
+ version: number;
9
+ length: number;
10
+ nodes: TCycleNode[];
11
+ };
12
+ formatter: (data: TCycleData) => string;
13
+ };
14
+ export declare const getCycleParser: () => CycleTimerParser;
15
+ export {};
@@ -0,0 +1,134 @@
1
+ import "core-js/modules/esnext.iterator.map.js";
2
+ import padStart from 'lodash/padStart';
3
+ import padEnd from 'lodash/padEnd';
4
+ import { generateDpStrStep } from '@ray-js/panel-sdk/lib/utils';
5
+ import { scheduleDpCodes } from '../../config/dpCodes';
6
+ import { scheduleLogger as ScheduleLogger } from '../../utils/ScheduleLogger';
7
+ import { numToBinStrPad8, numToHexPad2, numToHexPad4, numToBinStrPad } from '../utils';
8
+ const {
9
+ CYCLE_TIMING
10
+ } = scheduleDpCodes;
11
+ const LENGTH = 16;
12
+ class CycleTimerParser {
13
+ parser(dpValue) {
14
+ ScheduleLogger.debug(`CycleTimerParser dpValue: ${dpValue}`);
15
+ if (!dpValue) {
16
+ ScheduleLogger.warn(`无法解析数据, 请检查数据是否合规1【${CYCLE_TIMING}】: ${dpValue}`);
17
+ return {
18
+ version: 0,
19
+ length: LENGTH,
20
+ nodes: []
21
+ };
22
+ }
23
+ if (dpValue.length <= 4 || (dpValue.length - 4) % 32 !== 0) {
24
+ ScheduleLogger.warn(`节点数量不匹配, 请检查数据是否合规【${CYCLE_TIMING}】: ${dpValue}`);
25
+ return {
26
+ version: 0,
27
+ length: LENGTH,
28
+ nodes: []
29
+ };
30
+ }
31
+ const step = generateDpStrStep(dpValue);
32
+ const version = step().value;
33
+ const length = step().value;
34
+ // 节点数
35
+ const count = (dpValue.length - 4) / length / 2;
36
+ const nodes = [];
37
+ for (let i = 0; i < count; i++) {
38
+ const powerNum = step().value;
39
+ const powerInfo = numToBinStrPad8(powerNum);
40
+ const powerBits = powerInfo.split('');
41
+ const onOff = !!Number(powerBits[powerBits.length - 1]);
42
+ // 通道号
43
+ const channel = parseInt(powerBits.slice(1, powerBits.length - 1).join(''), 2);
44
+ const repeatInt = step(2).value; // 单次定时任务bit0-bit6全为0,bit0-bit6某位为1时,表示对应周几周期定时 bit0 => 周日
45
+ const loops = padEnd(repeatInt.toString(2).split('').reverse().join(''), 7, '0');
46
+ const startTime = step(4).value;
47
+ const endTime = step(4).value;
48
+ const startTimeDuration = step(4).value; // 开始时间持续时间,单位:s
49
+ const endTimeDuration = step(4).value; // 结束时间持续时间,单位:s
50
+
51
+ const hue = step(4).value;
52
+ const saturation = step().value;
53
+ const {
54
+ value
55
+ } = step();
56
+ const brightness = step().value;
57
+ const temperatureStep = step();
58
+ const temperature = temperatureStep.value;
59
+ const node = {
60
+ onOff,
61
+ channel,
62
+ loops,
63
+ startTime,
64
+ endTime,
65
+ startTimeDuration,
66
+ endTimeDuration,
67
+ index: i,
68
+ color: {
69
+ hue,
70
+ saturation,
71
+ value,
72
+ brightness,
73
+ temperature
74
+ }
75
+ };
76
+ nodes.push(node);
77
+ if (temperatureStep.done) {
78
+ break;
79
+ }
80
+ }
81
+ return {
82
+ version,
83
+ length,
84
+ nodes
85
+ };
86
+ }
87
+ formatter(data) {
88
+ const {
89
+ version,
90
+ nodes
91
+ } = data;
92
+ const versionStr = numToHexPad2(version);
93
+ const lengthStr = numToHexPad2(LENGTH);
94
+ const nodesStr = nodes.map(_ref => {
95
+ let {
96
+ onOff,
97
+ channel,
98
+ loops,
99
+ startTime,
100
+ startTimeDuration,
101
+ endTime,
102
+ endTimeDuration,
103
+ color
104
+ } = _ref;
105
+ const channelStr = numToBinStrPad(channel || 1, 7);
106
+ const powerChannel = parseInt(`${channelStr}${onOff ? 1 : 0}`, 2);
107
+ const powerChannelStr = numToHexPad2(powerChannel);
108
+ const weeksValue = padStart([...loops.split('')].reverse().join(''), 8, '0');
109
+ const weeksStr = numToHexPad2(parseInt(weeksValue, 2));
110
+ const startTimeStr = numToHexPad4(startTime);
111
+ const endTimeStr = numToHexPad4(endTime);
112
+ const startTimeDurationStr = numToHexPad4(startTimeDuration);
113
+ const endTimeDurationStr = numToHexPad4(endTimeDuration);
114
+ const {
115
+ hue,
116
+ saturation,
117
+ value,
118
+ brightness,
119
+ temperature
120
+ } = color;
121
+ const hueStr = numToHexPad4(hue);
122
+ const saturationStr = numToHexPad2(saturation);
123
+ const valueStr = numToHexPad2(value);
124
+ const brightnessStr = numToHexPad2(brightness);
125
+ const temperatureStr = numToHexPad2(temperature);
126
+ return `${powerChannelStr}${weeksStr}${startTimeStr}${endTimeStr}${startTimeDurationStr}${endTimeDurationStr}${hueStr}${saturationStr}${valueStr}${brightnessStr}${temperatureStr}`;
127
+ }).join('');
128
+ return `${versionStr}${lengthStr}${nodesStr}`;
129
+ }
130
+ }
131
+ export const cycleParser = new CycleTimerParser();
132
+ export const getCycleParser = () => {
133
+ return cycleParser;
134
+ };
@@ -0,0 +1,23 @@
1
+ /** dp 解析 */
2
+ import { scheduleDpCodes } from '../config/dpCodes';
3
+ export { randomParser, getRandomParser } from './random';
4
+ export { rhythmParser, getRhythmParser } from './rhythms';
5
+ export { sleepParserCommon as sleepParser, getSleepParser, SleepParser } from './sleep';
6
+ export { rtcTimerParser, getRtcParser } from './rtcTimer';
7
+ export { cycleParser, getCycleParser } from './cycle';
8
+ export { wakeupParserCommon as wakeupParser, getWakeUpParser, WakeUpParser } from './wakeup';
9
+ export { timerReportParser } from './timerReport';
10
+ type DpCode = keyof typeof scheduleDpCodes;
11
+ /**
12
+ * 自动匹配 dp 解析函数
13
+ *
14
+ * // 解析函数
15
+ * @returns {
16
+ * parser: (dpValue: string) => Record<string, any>;
17
+ * formatter: (dp: Record<string, any>) => string;
18
+ * }
19
+ */
20
+ export declare const autoDispatchTransDpFun: (dpCode: DpCode | string) => {
21
+ parser: (dpValue: string) => any;
22
+ formatter: (dp: Record<string, any>) => string;
23
+ } | null;
@@ -0,0 +1,43 @@
1
+ /** dp 解析 */
2
+
3
+ import { scheduleDpCodes } from '../config/dpCodes';
4
+ import { randomParser } from './random';
5
+ import { rhythmParser } from './rhythms';
6
+ import { getSleepParser } from './sleep';
7
+ import { rtcTimerParser } from './rtcTimer';
8
+ import { timerReportParser } from './timerReport';
9
+ import { getWakeUpParser } from './wakeup';
10
+ export { randomParser, getRandomParser } from './random';
11
+ export { rhythmParser, getRhythmParser } from './rhythms';
12
+ export { sleepParserCommon as sleepParser, getSleepParser, SleepParser } from './sleep';
13
+ export { rtcTimerParser, getRtcParser } from './rtcTimer';
14
+ export { cycleParser, getCycleParser } from './cycle';
15
+ export { wakeupParserCommon as wakeupParser, getWakeUpParser, WakeUpParser } from './wakeup';
16
+ export { timerReportParser } from './timerReport';
17
+ /**
18
+ * 自动匹配 dp 解析函数
19
+ *
20
+ * // 解析函数
21
+ * @returns {
22
+ * parser: (dpValue: string) => Record<string, any>;
23
+ * formatter: (dp: Record<string, any>) => string;
24
+ * }
25
+ */
26
+ export const autoDispatchTransDpFun = dpCode => {
27
+ switch (dpCode) {
28
+ case scheduleDpCodes.RANDOM_TIMING:
29
+ return randomParser;
30
+ case scheduleDpCodes.RHYTHM_MODE:
31
+ return rhythmParser;
32
+ case scheduleDpCodes.SLEEP_MODE:
33
+ return getSleepParser();
34
+ case scheduleDpCodes.RTC_TIMER:
35
+ return rtcTimerParser;
36
+ case scheduleDpCodes.TIMER_REPORT:
37
+ return timerReportParser;
38
+ case scheduleDpCodes.WAKE_UP_MODE:
39
+ return getWakeUpParser();
40
+ default:
41
+ return null;
42
+ }
43
+ };
@@ -0,0 +1,15 @@
1
+ import { TRandomData, TRandomNode } from '../../types';
2
+ declare class RandomTimerParser {
3
+ parser(dpValue: string): TRandomData;
4
+ formatter(data: TRandomData): string;
5
+ }
6
+ export declare const randomParser: {
7
+ parser: (dpValue: string) => {
8
+ version: number;
9
+ length: number;
10
+ nodes: TRandomNode[];
11
+ };
12
+ formatter: (data: TRandomData) => string;
13
+ };
14
+ export declare const getRandomParser: () => RandomTimerParser;
15
+ export {};
@@ -0,0 +1,127 @@
1
+ import "core-js/modules/esnext.iterator.map.js";
2
+ /* eslint-disable no-console */
3
+ import padStart from 'lodash/padStart';
4
+ import { generateDpStrStep } from '@ray-js/panel-sdk/lib/utils';
5
+ import padEnd from 'lodash/padEnd';
6
+ import { scheduleDpCodes } from '../../config/dpCodes';
7
+ import { scheduleLogger as ScheduleLogger } from '../../utils/ScheduleLogger';
8
+ import { numToBinStrPad8, numToHexPad2, numToHexPad4, numToBinStrPad } from '../utils';
9
+ const {
10
+ RANDOM_TIMING
11
+ } = scheduleDpCodes;
12
+ const LENGTH = 12;
13
+ class RandomTimerParser {
14
+ parser(dpValue) {
15
+ ScheduleLogger.debug(`RandomTimerParser dpValue: ${dpValue}`);
16
+ if (!dpValue) {
17
+ ScheduleLogger.warn(`无法解析数据, 请检查数据是否合规1【${RANDOM_TIMING}】: ${dpValue}`);
18
+ return {
19
+ version: 0,
20
+ length: LENGTH,
21
+ nodes: []
22
+ };
23
+ }
24
+ const step = generateDpStrStep(dpValue);
25
+ const version = step().value;
26
+ const length = step().value;
27
+ if (!dpValue || (dpValue.length - 4) % 24 !== 0) {
28
+ console.log('decodeRandomTask 数据有问题,无法解析');
29
+ // 返回默认值
30
+ return {
31
+ version: 0,
32
+ length: 12,
33
+ nodes: []
34
+ };
35
+ }
36
+ const nodes = [];
37
+ // 节点数
38
+ const count = (dpValue.length - 4) / LENGTH / 2;
39
+ for (let i = 0; i < count; i++) {
40
+ const powerNum = step().value;
41
+ const powerInfo = numToBinStrPad8(powerNum);
42
+ const powerBits = powerInfo.split('');
43
+ const onOff = !!Number(powerBits[powerBits.length - 1]);
44
+ // 通道号
45
+ const channel = parseInt(powerBits.slice(1, powerBits.length - 1).join(''), 2);
46
+ const repeatInt = step(2).value; // 单次定时任务bit0-bit6全为0,bit0-bit6某位为1时,表示对应周几周期定时 bit0 => 周日
47
+ const loops = padEnd(repeatInt.toString(2).split('').reverse().join(''), 7, '0');
48
+ const startTime = step(4).value;
49
+ const endTime = step(4).value;
50
+ const hue = step(4).value;
51
+ const saturation = step().value;
52
+ const {
53
+ value
54
+ } = step();
55
+ const brightness = step().value;
56
+ const temperatureStep = step();
57
+ const temperature = temperatureStep.value;
58
+ const node = {
59
+ onOff,
60
+ channel,
61
+ loops,
62
+ startTime,
63
+ endTime,
64
+ index: i,
65
+ color: {
66
+ hue,
67
+ saturation,
68
+ value,
69
+ brightness,
70
+ temperature
71
+ }
72
+ };
73
+ nodes.push(node);
74
+ if (temperatureStep.done) {
75
+ break;
76
+ }
77
+ }
78
+ return {
79
+ version,
80
+ length,
81
+ nodes
82
+ };
83
+ }
84
+ formatter(data) {
85
+ const {
86
+ version,
87
+ nodes
88
+ } = data;
89
+ const versionStr = numToHexPad2(version);
90
+ const lengthStr = numToHexPad2(LENGTH);
91
+ const nodesStr = nodes.map(_ref => {
92
+ let {
93
+ onOff,
94
+ channel,
95
+ loops,
96
+ startTime,
97
+ endTime,
98
+ color
99
+ } = _ref;
100
+ const channelStr = numToBinStrPad(channel || 1, 7);
101
+ const powerChannel = parseInt(`${channelStr}${onOff ? 1 : 0}`, 2);
102
+ const powerChannelStr = numToHexPad2(powerChannel);
103
+ const weeksValue = padStart([...loops.split('')].reverse().join(''), 8, '0');
104
+ const weeksStr = numToHexPad2(parseInt(weeksValue, 2));
105
+ const startTimeStr = numToHexPad4(startTime);
106
+ const endTimeStr = numToHexPad4(endTime);
107
+ const {
108
+ hue,
109
+ saturation,
110
+ value,
111
+ brightness,
112
+ temperature
113
+ } = color;
114
+ const hueStr = numToHexPad4(hue);
115
+ const saturationStr = numToHexPad2(saturation);
116
+ const valueStr = numToHexPad2(value);
117
+ const brightnessStr = numToHexPad2(brightness);
118
+ const temperatureStr = numToHexPad2(temperature);
119
+ return `${powerChannelStr}${weeksStr}${startTimeStr}${endTimeStr}${hueStr}${saturationStr}${valueStr}${brightnessStr}${temperatureStr}`;
120
+ }).join('');
121
+ return `${versionStr}${lengthStr}${nodesStr}`;
122
+ }
123
+ }
124
+ export const randomParser = new RandomTimerParser();
125
+ export const getRandomParser = () => {
126
+ return randomParser;
127
+ };
@@ -0,0 +1,41 @@
1
+ import { TRhythmData } from '../types/rhythms';
2
+ export default class RhythmFormatter {
3
+ uuid: string;
4
+ defaultValue: any;
5
+ constructor(uuid?: "rhythm_mode", defaultValue?: null);
6
+ parser(dpValue?: string): {
7
+ version: number;
8
+ power: boolean;
9
+ mode: number;
10
+ weeks: number[];
11
+ number: number;
12
+ rhythms: {
13
+ key: number;
14
+ version: number;
15
+ power: boolean;
16
+ mode: number;
17
+ weeks: number[];
18
+ number: number;
19
+ rhythms: {
20
+ power: boolean;
21
+ hour: number;
22
+ minute: number;
23
+ hue: number;
24
+ saturation: number;
25
+ value: number;
26
+ brightness: number;
27
+ temperature: number;
28
+ }[];
29
+ }[];
30
+ } | {
31
+ version: any;
32
+ power: boolean;
33
+ mode: any;
34
+ weeks: number[];
35
+ number: any;
36
+ rhythms: never[];
37
+ };
38
+ formatter(data: TRhythmData): string;
39
+ }
40
+ export declare const rhythmParser: RhythmFormatter;
41
+ export declare const getRhythmParser: () => RhythmFormatter;