@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,454 @@
1
+ import { timerDataToSchedule, timerListToScheduleList, wakeUpNodeToSchedule, wakeUpDataToScheduleList, sleepNodeToSchedule, sleepDataToScheduleList, countdownToSchedule, rhythmToSchedule, randomNodeToSchedule, randomDataToScheduleList, cycleNodeToSchedule, cycleDataToScheduleList, transScheduleListToConflictList } from '../transform';
2
+ import { EScheduleFunctionType } from '../../types';
3
+ // 模拟 dayjs 的 format 方法
4
+ jest.mock('dayjs', () => {
5
+ return jest.fn(() => ({
6
+ format: jest.fn(() => '10:00'),
7
+ subtract: jest.fn(() => ({
8
+ format: jest.fn(() => '09:00')
9
+ })),
10
+ add: jest.fn(() => ({
11
+ format: jest.fn(() => '11:00')
12
+ }))
13
+ }));
14
+ });
15
+
16
+ // 模拟时间工具函数
17
+ jest.mock('../../utils/time', () => ({
18
+ getBackwardOffsetTimeByHourMins: jest.fn((hour, minute, offset) => `${hour}:${minute + offset}`),
19
+ getPreOffsetTimeByHourMins: jest.fn((hour, minute, offset) => `${hour}:${minute - offset}`),
20
+ getTimerStrByMinutes: jest.fn(minutes => {
21
+ const hour = Math.floor(minutes / 60);
22
+ const minute = minutes % 60;
23
+ return `${hour < 10 ? '0' + hour : hour}:${minute < 10 ? '0' + minute : minute}`;
24
+ })
25
+ }));
26
+
27
+ // 模拟日志函数
28
+ jest.mock('../../utils/ScheduleLogger', () => ({
29
+ scheduleLogger: {
30
+ debug: jest.fn(),
31
+ error: jest.fn()
32
+ }
33
+ }));
34
+ describe('transform', () => {
35
+ describe('timerDataToSchedule', () => {
36
+ it('应该将定时数据转换为日程对象', () => {
37
+ const result = timerDataToSchedule({
38
+ time: '10:00',
39
+ loops: '1000000',
40
+ status: true,
41
+ timerId: '1',
42
+ dps: {},
43
+ aliasName: 'aliasName',
44
+ isAppPush: false
45
+ });
46
+ expect(result).toEqual({
47
+ id: `${EScheduleFunctionType.TIMER}_10:00_1000000`,
48
+ type: EScheduleFunctionType.TIMER,
49
+ data: {
50
+ status: true,
51
+ weeks: [1, 0, 0, 0, 0, 0, 0],
52
+ startTime: '10:00',
53
+ endTime: '10:00'
54
+ }
55
+ });
56
+ });
57
+ it('应该处理缺少状态的定时数据', () => {
58
+ const result = timerDataToSchedule({
59
+ time: '10:00',
60
+ loops: '1000000',
61
+ timerId: '1',
62
+ dps: {},
63
+ aliasName: 'aliasName',
64
+ isAppPush: false
65
+ });
66
+ expect(result.data.status).toBe(false);
67
+ });
68
+ });
69
+ describe('timerListToScheduleList', () => {
70
+ it('应该将定时数据列表转换为日程对象列表', () => {
71
+ const result = timerListToScheduleList([{
72
+ time: '10:00',
73
+ loops: '1000000',
74
+ timerId: '1',
75
+ status: true,
76
+ dps: {},
77
+ aliasName: 'aliasName',
78
+ isAppPush: false
79
+ }, {
80
+ time: '12:00',
81
+ loops: '0100000',
82
+ timerId: '2',
83
+ status: false,
84
+ dps: {},
85
+ aliasName: 'aliasName',
86
+ isAppPush: false
87
+ }]);
88
+ expect(result.length).toBe(2);
89
+ expect(result[0].id).toBe(`${EScheduleFunctionType.TIMER}_10:00_1000000`);
90
+ expect(result[1].id).toBe(`${EScheduleFunctionType.TIMER}_12:00_0100000`);
91
+ });
92
+ });
93
+ describe('wakeUpNodeToSchedule', () => {
94
+ it('应该将唤醒数据转换为日程对象', () => {
95
+ const result = wakeUpNodeToSchedule({
96
+ hour: 8,
97
+ minute: 30,
98
+ loops: '1000000',
99
+ onOff: true,
100
+ step: 2,
101
+ duration: 3,
102
+ hue: 0,
103
+ saturation: 1000,
104
+ value: 1000,
105
+ brightness: 1000,
106
+ temperature: 1000,
107
+ index: 1
108
+ });
109
+ expect(result).toEqual({
110
+ id: `${EScheduleFunctionType.WAKEUP}_08_30_1000000`,
111
+ type: EScheduleFunctionType.WAKEUP,
112
+ data: {
113
+ status: true,
114
+ weeks: [1, 0, 0, 0, 0, 0, 0],
115
+ startTime: '8:20',
116
+ endTime: '8:45'
117
+ }
118
+ });
119
+ });
120
+ });
121
+ describe('wakeUpDataToScheduleList', () => {
122
+ it('应该将唤醒数据列表转换为日程对象列表', () => {
123
+ const result = wakeUpDataToScheduleList([{
124
+ hour: 8,
125
+ minute: 30,
126
+ loops: '1000000',
127
+ onOff: true,
128
+ step: 2,
129
+ duration: 3,
130
+ hue: 0,
131
+ saturation: 1000,
132
+ value: 1000,
133
+ brightness: 1000,
134
+ temperature: 1000,
135
+ index: 1
136
+ }, {
137
+ hour: 9,
138
+ minute: 0,
139
+ loops: '0100000',
140
+ onOff: false,
141
+ step: 1,
142
+ duration: 2,
143
+ hue: 0,
144
+ saturation: 1000,
145
+ value: 1000,
146
+ brightness: 1000,
147
+ temperature: 1000,
148
+ index: 2
149
+ }]);
150
+ expect(result.length).toBe(2);
151
+ expect(result[0].id).toBe(`${EScheduleFunctionType.WAKEUP}_08_30_1000000`);
152
+ expect(result[1].id).toBe(`${EScheduleFunctionType.WAKEUP}_09_00_0100000`);
153
+ });
154
+ });
155
+ describe('sleepNodeToSchedule', () => {
156
+ it('应该将入睡数据转换为日程对象', () => {
157
+ const result = sleepNodeToSchedule({
158
+ hour: 22,
159
+ minute: 20,
160
+ loops: '1000000',
161
+ onOff: true,
162
+ step: 2,
163
+ time: '22:30',
164
+ hue: 0,
165
+ saturation: 1000,
166
+ value: 1000,
167
+ brightness: 1000,
168
+ temperature: 1000,
169
+ index: 2
170
+ });
171
+ expect(result).toEqual({
172
+ id: `${EScheduleFunctionType.SLEEP}_22_20_1000000`,
173
+ type: EScheduleFunctionType.SLEEP,
174
+ data: {
175
+ status: true,
176
+ weeks: [1, 0, 0, 0, 0, 0, 0],
177
+ startTime: '22:10',
178
+ endTime: '22:30'
179
+ }
180
+ });
181
+ });
182
+ });
183
+ describe('sleepDataToScheduleList', () => {
184
+ it('应该将入睡数据列表转换为日程对象列表', () => {
185
+ const result = sleepDataToScheduleList([{
186
+ hour: 22,
187
+ minute: 20,
188
+ loops: '1000000',
189
+ onOff: true,
190
+ step: 2,
191
+ time: '22:30',
192
+ hue: 0,
193
+ saturation: 1000,
194
+ value: 1000,
195
+ brightness: 1000,
196
+ temperature: 1000,
197
+ index: 2
198
+ }, {
199
+ hour: 23,
200
+ minute: 20,
201
+ loops: '0100000',
202
+ onOff: true,
203
+ step: 2,
204
+ time: '23:30',
205
+ hue: 0,
206
+ saturation: 1000,
207
+ value: 1000,
208
+ brightness: 1000,
209
+ temperature: 1000,
210
+ index: 2
211
+ }]);
212
+ expect(result.length).toBe(2);
213
+ expect(result[0].id).toBe(`${EScheduleFunctionType.SLEEP}_22_20_1000000`);
214
+ expect(result[1].id).toBe(`${EScheduleFunctionType.SLEEP}_23_20_0100000`);
215
+ });
216
+ });
217
+ describe('countdownToSchedule', () => {
218
+ it('应该将倒计时数据转换为日程对象', () => {
219
+ const result = countdownToSchedule({
220
+ countdown: 600 // 10分钟
221
+ });
222
+ expect(result).toEqual({
223
+ id: EScheduleFunctionType.COUNTDOWN,
224
+ type: EScheduleFunctionType.COUNTDOWN,
225
+ data: {
226
+ status: true,
227
+ weeks: [0, 0, 0, 0, 0, 0, 0],
228
+ startTime: '10:00',
229
+ endTime: '10:10'
230
+ }
231
+ });
232
+ });
233
+ it('应该处理倒计时为0的情况', () => {
234
+ const result = countdownToSchedule({
235
+ countdown: 0
236
+ });
237
+ expect(result.data.status).toBe(false);
238
+ });
239
+ });
240
+ describe('rhythmToSchedule', () => {
241
+ it('应该将生物节律数据转换为日程对象', () => {
242
+ const result = rhythmToSchedule({
243
+ power: true,
244
+ weeks: [1, 1, 1, 1, 1, 0, 0],
245
+ version: 1,
246
+ mode: 1,
247
+ number: 4,
248
+ rhythms: []
249
+ });
250
+ expect(result).toEqual({
251
+ id: EScheduleFunctionType.RHYTHM,
252
+ type: EScheduleFunctionType.RHYTHM,
253
+ data: {
254
+ status: true,
255
+ weeks: [1, 1, 1, 1, 1, 0, 0],
256
+ startTime: '00:00',
257
+ endTime: '23:59'
258
+ }
259
+ });
260
+ });
261
+ });
262
+ describe('randomNodeToSchedule', () => {
263
+ it('应该将随机定时数据转换为日程对象', () => {
264
+ const result = randomNodeToSchedule({
265
+ startTime: 600,
266
+ // 10:00
267
+ endTime: 720,
268
+ // 12:00
269
+ loops: '1000000',
270
+ onOff: true,
271
+ channel: 1,
272
+ index: 1,
273
+ color: {
274
+ hue: 0,
275
+ saturation: 1000,
276
+ value: 1000,
277
+ brightness: 1000,
278
+ temperature: 1000
279
+ }
280
+ });
281
+ expect(result).toEqual({
282
+ id: `${EScheduleFunctionType.RANDOM}_600_720_1000000`,
283
+ type: EScheduleFunctionType.RANDOM,
284
+ data: {
285
+ status: true,
286
+ weeks: [1, 0, 0, 0, 0, 0, 0],
287
+ startTime: '10:00',
288
+ endTime: '12:00'
289
+ }
290
+ });
291
+ });
292
+ });
293
+ describe('randomDataToScheduleList', () => {
294
+ it('应该将随机定时数据列表转换为日程对象列表', () => {
295
+ const result = randomDataToScheduleList([{
296
+ startTime: 600,
297
+ // 10:00
298
+ endTime: 720,
299
+ // 12:00
300
+ loops: '1000000',
301
+ onOff: true,
302
+ channel: 1,
303
+ index: 1,
304
+ color: {
305
+ hue: 0,
306
+ saturation: 1000,
307
+ value: 1000,
308
+ brightness: 1000,
309
+ temperature: 1000
310
+ }
311
+ }, {
312
+ startTime: 780,
313
+ // 13:00
314
+ endTime: 840,
315
+ // 14:00
316
+ loops: '0100000',
317
+ onOff: false,
318
+ channel: 1,
319
+ index: 1,
320
+ color: {
321
+ hue: 0,
322
+ saturation: 1000,
323
+ value: 1000,
324
+ brightness: 1000,
325
+ temperature: 1000
326
+ }
327
+ }]);
328
+ expect(result.length).toBe(2);
329
+ expect(result[0].id).toBe(`${EScheduleFunctionType.RANDOM}_600_720_1000000`);
330
+ expect(result[1].id).toBe(`${EScheduleFunctionType.RANDOM}_780_840_0100000`);
331
+ });
332
+ });
333
+ describe('cycleNodeToSchedule', () => {
334
+ it('应该将循环定时数据转换为日程对象', () => {
335
+ const result = cycleNodeToSchedule({
336
+ startTime: 600,
337
+ // 10:00
338
+ endTime: 720,
339
+ // 12:00
340
+ loops: '1000000',
341
+ onOff: true,
342
+ channel: 1,
343
+ startTimeDuration: 10,
344
+ endTimeDuration: 10,
345
+ index: 1,
346
+ color: {
347
+ hue: 0,
348
+ saturation: 1000,
349
+ value: 1000,
350
+ brightness: 1000,
351
+ temperature: 1000
352
+ }
353
+ });
354
+ expect(result).toEqual({
355
+ id: `${EScheduleFunctionType.CYCLE}_600_720_1000000`,
356
+ type: EScheduleFunctionType.CYCLE,
357
+ data: {
358
+ status: true,
359
+ weeks: [1, 0, 0, 0, 0, 0, 0],
360
+ startTime: '10:00',
361
+ endTime: '12:00'
362
+ }
363
+ });
364
+ });
365
+ });
366
+ describe('cycleDataToScheduleList', () => {
367
+ it('应该将循环定时数据列表转换为日程对象列表', () => {
368
+ const result = cycleDataToScheduleList([{
369
+ startTime: 600,
370
+ // 10:00
371
+ endTime: 720,
372
+ // 12:00
373
+ loops: '1000000',
374
+ onOff: true,
375
+ channel: 1,
376
+ startTimeDuration: 10,
377
+ endTimeDuration: 10,
378
+ index: 1,
379
+ color: {
380
+ hue: 0,
381
+ saturation: 1000,
382
+ value: 1000,
383
+ brightness: 1000,
384
+ temperature: 1000
385
+ }
386
+ }, {
387
+ startTime: 780,
388
+ // 13:00
389
+ endTime: 840,
390
+ // 14:00
391
+ loops: '0100000',
392
+ onOff: false,
393
+ channel: 1,
394
+ startTimeDuration: 10,
395
+ endTimeDuration: 10,
396
+ index: 1,
397
+ color: {
398
+ hue: 0,
399
+ saturation: 1000,
400
+ value: 1000,
401
+ brightness: 1000,
402
+ temperature: 1000
403
+ }
404
+ }]);
405
+ expect(result.length).toBe(2);
406
+ expect(result[0].id).toBe(`${EScheduleFunctionType.CYCLE}_600_720_1000000`);
407
+ expect(result[1].id).toBe(`${EScheduleFunctionType.CYCLE}_780_840_0100000`);
408
+ });
409
+ });
410
+ describe('transScheduleListToConflictList', () => {
411
+ it('应该将折叠的日程列表转换为冲突列表', () => {
412
+ const foldScheduleList = [{
413
+ type: EScheduleFunctionType.TIMER,
414
+ detail: [{
415
+ time: '10:00',
416
+ loops: '1000000',
417
+ status: true,
418
+ timerId: '1',
419
+ dps: {},
420
+ aliasName: '',
421
+ isAppPush: false
422
+ }]
423
+ }, {
424
+ type: EScheduleFunctionType.RANDOM,
425
+ detail: [{
426
+ startTime: 600,
427
+ endTime: 720,
428
+ loops: '0100000',
429
+ onOff: true,
430
+ channel: 1,
431
+ index: 1,
432
+ color: {
433
+ hue: 0,
434
+ saturation: 1000,
435
+ value: 1000,
436
+ brightness: 1000,
437
+ temperature: 1000
438
+ }
439
+ }]
440
+ }];
441
+ const result = transScheduleListToConflictList(foldScheduleList);
442
+ expect(result.length).toBe(2);
443
+ expect(result[0].type).toBe(EScheduleFunctionType.TIMER);
444
+ expect(result[1].type).toBe(EScheduleFunctionType.RANDOM);
445
+ });
446
+ it('应该处理未知类型的情况', () => {
447
+ const result = transScheduleListToConflictList([{
448
+ type: 'unknown',
449
+ detail: []
450
+ }]);
451
+ expect(result.length).toBe(0);
452
+ });
453
+ });
454
+ });
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,114 @@
1
+ import { updateDeviceDp } from '../updateDeviceDp';
2
+ import { publishDps, publishGroupDpCodes } from '@ray-js/ray';
3
+ import { scheduleLogger as ScheduleLogger } from '../../utils/ScheduleLogger';
4
+
5
+ // 模拟 ray-js 的 publishDps 和 publishGroupDpCodes
6
+ jest.mock('@ray-js/ray', () => ({
7
+ publishDps: jest.fn(),
8
+ publishGroupDpCodes: jest.fn()
9
+ }));
10
+
11
+ // 模拟日志函数
12
+ jest.mock('../../utils/ScheduleLogger', () => ({
13
+ scheduleLogger: {
14
+ debug: jest.fn(),
15
+ error: jest.fn(),
16
+ warn: jest.fn()
17
+ }
18
+ }));
19
+
20
+ // 模拟 getSupportIns 函数
21
+ jest.mock('../../hooks/useCommonSupport', () => ({
22
+ getSupportIns: jest.fn()
23
+ }));
24
+
25
+ // 模拟 scheduleDpCodes
26
+ jest.mock('../../config', () => ({
27
+ scheduleDpCodes: {
28
+ LOCAL_TIMER: 'local_timer',
29
+ STRIP_LOCAL_TIMER: 'strip_local_timer',
30
+ RTC_TIMER: 'rtc_timer',
31
+ COUNTDOWN: 'countdown',
32
+ CYCLE_TIMING: 'cycle_timing',
33
+ RANDOM_TIMING: 'random_timing',
34
+ RHYTHM_MODE: 'rhythm_mode',
35
+ SLEEP_MODE: 'sleep_mode',
36
+ WAKE_UP_MODE: 'wake_up_mode'
37
+ }
38
+ }));
39
+ describe('DPProcessor', () => {
40
+ // 在每个测试前重置模拟函数
41
+ beforeEach(() => {
42
+ jest.clearAllMocks();
43
+ // 重置 __deviceCapabilities
44
+ // @ts-ignore - 访问私有变量进行测试
45
+ global.__deviceCapabilities = null;
46
+ });
47
+ describe('updateDeviceDp', () => {
48
+ it('应该处理空的 dps 对象', () => {
49
+ updateDeviceDp('device1', '', {});
50
+ expect(ScheduleLogger.warn).toHaveBeenCalled();
51
+ expect(publishDps).not.toHaveBeenCalled();
52
+ expect(publishGroupDpCodes).not.toHaveBeenCalled();
53
+ });
54
+ it('应该处理缺少 devId 和 groupId 的情况', () => {
55
+ updateDeviceDp('', '', {
56
+ dp1: true
57
+ });
58
+ expect(ScheduleLogger.warn).toHaveBeenCalled();
59
+ expect(publishDps).not.toHaveBeenCalled();
60
+ expect(publishGroupDpCodes).not.toHaveBeenCalled();
61
+ });
62
+ it('应该为设备发布 DP', () => {
63
+ const dps = {
64
+ dp1: true,
65
+ dp2: 'value'
66
+ };
67
+ updateDeviceDp('device1', '', dps);
68
+ expect(publishDps).toHaveBeenCalledWith({
69
+ deviceId: 'device1',
70
+ dps,
71
+ mode: 2,
72
+ pipelines: [0, 1, 2, 3, 4, 5, 6],
73
+ options: {},
74
+ success: expect.any(Function),
75
+ fail: expect.any(Function)
76
+ });
77
+ expect(publishGroupDpCodes).not.toHaveBeenCalled();
78
+
79
+ // 测试成功回调
80
+ const successCallback = publishDps.mock.calls[0][0].success;
81
+ successCallback();
82
+ expect(ScheduleLogger.debug).toHaveBeenCalled();
83
+
84
+ // 测试失败回调
85
+ const failCallback = publishDps.mock.calls[0][0].fail;
86
+ failCallback('error');
87
+ expect(ScheduleLogger.error).toHaveBeenCalled();
88
+ });
89
+ it('应该为群组发布 DP', () => {
90
+ const dps = {
91
+ dp1: true,
92
+ dp2: 'value'
93
+ };
94
+ updateDeviceDp('', 'group1', dps);
95
+ expect(publishGroupDpCodes).toHaveBeenCalledWith({
96
+ groupId: 'group1',
97
+ dpCodes: dps,
98
+ success: expect.any(Function),
99
+ fail: expect.any(Function)
100
+ });
101
+ expect(publishDps).not.toHaveBeenCalled();
102
+
103
+ // 测试成功回调
104
+ const successCallback = publishGroupDpCodes.mock.calls[0][0].success;
105
+ successCallback();
106
+ expect(ScheduleLogger.debug).toHaveBeenCalled();
107
+
108
+ // 测试失败回调
109
+ const failCallback = publishGroupDpCodes.mock.calls[0][0].fail;
110
+ failCallback('error');
111
+ expect(ScheduleLogger.error).toHaveBeenCalled();
112
+ });
113
+ });
114
+ });
@@ -0,0 +1,42 @@
1
+ import { TConflictRes, ConflictRule, TFoldScheduleList, TSchedule } from './type';
2
+ /**
3
+ * 冲突检测
4
+ */
5
+ export declare class Conflict {
6
+ static rule: ConflictRule;
7
+ static isInit: boolean;
8
+ /**
9
+ * 添加冲突规则
10
+ */
11
+ static addConflictRule(rule: ConflictRule): void;
12
+ /**
13
+ * 添加新日程时检测冲突
14
+ *
15
+ * @param current - 待添加的日程对象,类型为 Schedule
16
+ * @returns 返回冲突检测结果对象,包含:
17
+ * isConflict - 是否存在冲突的布尔值
18
+ * conflictList - 具体的冲突检测结果数组
19
+ */
20
+ static add(current: TSchedule): TConflictRes;
21
+ /**
22
+ * 删除日程
23
+ *
24
+ * @param current - 待添加的日程对象,类型为 Schedule
25
+ * @returns void
26
+ */
27
+ static remove(current: TSchedule): void;
28
+ /**
29
+ * 更新新日程时检测冲突
30
+ *
31
+ * @param current - 待更新的日程对象,类型为 Schedule
32
+ * @returns 返回冲突检测结果对象,包含:
33
+ * isConflict - 是否存在冲突的布尔值
34
+ * conflictList - 具体的冲突检测结果数组
35
+ */
36
+ static update(current: TSchedule, prevSchedule: TSchedule): TConflictRes;
37
+ /**
38
+ * 当进入面板后,初始化需要冲突判断的计划数据,便于后续增删改冲突判断
39
+ * @param scheduleList - 需要冲突判断的计划数据
40
+ */
41
+ static init(scheduleList: TFoldScheduleList): void;
42
+ }