@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,103 @@
1
+ import _objectSpread from "@babel/runtime/helpers/esm/objectSpread2";
2
+ import "core-js/modules/esnext.iterator.constructor.js";
3
+ import "core-js/modules/esnext.iterator.find.js";
4
+ import { scheduleLogger } from '../utils/ScheduleLogger';
5
+ import { checkConflicts } from './ConflictResolver';
6
+ import { ScheduleDataManager } from './scheduleDataManager';
7
+ import { transScheduleListToConflictList } from './transform';
8
+
9
+ /**
10
+ * 冲突检测
11
+ */
12
+ export class Conflict {
13
+ /**
14
+ * 添加冲突规则
15
+ */
16
+ static addConflictRule(rule) {
17
+ Conflict.rule = rule;
18
+ scheduleLogger.debug('Conflict.addConflictRule:', rule);
19
+ }
20
+
21
+ /**
22
+ * 添加新日程时检测冲突
23
+ *
24
+ * @param current - 待添加的日程对象,类型为 Schedule
25
+ * @returns 返回冲突检测结果对象,包含:
26
+ * isConflict - 是否存在冲突的布尔值
27
+ * conflictList - 具体的冲突检测结果数组
28
+ */
29
+ static add(current) {
30
+ const instance = ScheduleDataManager.getInstance();
31
+ const preList = instance.getData() || [];
32
+ const [cur] = transScheduleListToConflictList([current]);
33
+ scheduleLogger.debug('Conflict.add cur, current:', cur, current);
34
+ const conflictList = checkConflicts(preList, cur, Conflict.rule);
35
+ const isConflict = conflictList.length > 0;
36
+ // 如果存在冲突,不保存数据
37
+ !isConflict && instance.setData(cur);
38
+ return {
39
+ isConflict,
40
+ conflictList
41
+ };
42
+ }
43
+
44
+ /**
45
+ * 删除日程
46
+ *
47
+ * @param current - 待添加的日程对象,类型为 Schedule
48
+ * @returns void
49
+ */
50
+ static remove(current) {
51
+ const [cur] = transScheduleListToConflictList([current]);
52
+ scheduleLogger.debug('Conflict.remove cur, current:', cur, current);
53
+ cur && ScheduleDataManager.getInstance().deleteData(cur);
54
+ }
55
+
56
+ /**
57
+ * 更新新日程时检测冲突
58
+ *
59
+ * @param current - 待更新的日程对象,类型为 Schedule
60
+ * @returns 返回冲突检测结果对象,包含:
61
+ * isConflict - 是否存在冲突的布尔值
62
+ * conflictList - 具体的冲突检测结果数组
63
+ */
64
+ static update(current, prevSchedule) {
65
+ scheduleLogger.debug('Conflict.update:', current, prevSchedule);
66
+ if (!prevSchedule) {
67
+ scheduleLogger.error('Conflict.update: prevSchedule is empty: current', current);
68
+ }
69
+ const instance = ScheduleDataManager.getInstance();
70
+ const [cur, prev] = transScheduleListToConflictList([current, prevSchedule]);
71
+ scheduleLogger.debug('Conflict.update1:', cur, prev);
72
+ const preList = instance.getData() || [];
73
+ const _current = _objectSpread(_objectSpread({}, cur), {}, {
74
+ prevId: prev.id
75
+ });
76
+ const conflictList = checkConflicts(preList, _current, Conflict.rule);
77
+ const isConflict = conflictList.length > 0;
78
+ if (!isConflict && prev) {
79
+ // 如果没有冲突说明可以更新,需要删除之前的项,防止之前项目一致存在影响正常判断冲突
80
+ const preItem = preList.find(i => i.id === prev.id);
81
+ preItem && instance.deleteData(preItem);
82
+ instance.setData(_current);
83
+ }
84
+ return {
85
+ isConflict,
86
+ conflictList
87
+ };
88
+ }
89
+
90
+ /**
91
+ * 当进入面板后,初始化需要冲突判断的计划数据,便于后续增删改冲突判断
92
+ * @param scheduleList - 需要冲突判断的计划数据
93
+ */
94
+ static init(scheduleList) {
95
+ if (!Array.isArray(scheduleList)) {
96
+ return;
97
+ }
98
+ const instance = ScheduleDataManager.getInstance();
99
+ const _scheduleList = transScheduleListToConflictList(scheduleList);
100
+ scheduleLogger.debug('Conflict.init scheduleList, _scheduleList:', scheduleList, _scheduleList);
101
+ instance.setData(_scheduleList);
102
+ }
103
+ }
@@ -0,0 +1,12 @@
1
+ import { Schedule } from './type';
2
+ export declare class ScheduleDataManager {
3
+ static instance: ScheduleDataManager;
4
+ static list: Record<string, any>[];
5
+ static getInstance(): ScheduleDataManager;
6
+ getData(): Record<string, any>[];
7
+ setData(value: Record<string, any>[] | Record<string, any>): void;
8
+ clearData(): void;
9
+ deleteData(current: Schedule): void;
10
+ remove(id: string): void;
11
+ }
12
+ export default ScheduleDataManager;
@@ -0,0 +1,79 @@
1
+ import "core-js/modules/esnext.iterator.constructor.js";
2
+ import "core-js/modules/esnext.iterator.filter.js";
3
+ import "core-js/modules/esnext.iterator.for-each.js";
4
+ // 统一管理 计划 数据列表,用来判断是否存在冲突
5
+ export class ScheduleDataManager {
6
+ static list = [];
7
+ static getInstance() {
8
+ if (!ScheduleDataManager.instance) {
9
+ ScheduleDataManager.instance = new ScheduleDataManager();
10
+ }
11
+ return ScheduleDataManager.instance;
12
+ }
13
+ getData() {
14
+ return ScheduleDataManager.list;
15
+ }
16
+ setData(value) {
17
+ if (!value) {
18
+ return;
19
+ }
20
+
21
+ // 创建一个新的列表,而不是修改现有列表
22
+ let newList = [...ScheduleDataManager.list];
23
+ if (Array.isArray(value)) {
24
+ value.forEach(item => {
25
+ if (Array.isArray(item)) {
26
+ item.forEach(_item => {
27
+ if (!_item || !_item.id) {
28
+ return;
29
+ }
30
+ // 如果跟之前id相同需要先删除
31
+ newList = newList.filter(i => i.id !== _item.id);
32
+ // 添加新项
33
+ newList.push(_item);
34
+ });
35
+ } else {
36
+ if (!item || !item.id) {
37
+ return;
38
+ }
39
+ // 如果跟之前id相同需要先删除
40
+ newList = newList.filter(i => i.id !== item.id);
41
+ // 添加新项
42
+ newList.push(item);
43
+ }
44
+ });
45
+ } else {
46
+ if (!value || !value.id) {
47
+ return;
48
+ }
49
+ // 如果跟之前id相同需要先删除
50
+ newList = newList.filter(i => i.id !== value.id);
51
+ // 添加新项
52
+ newList.push(value);
53
+ }
54
+
55
+ // 更新列表
56
+ ScheduleDataManager.list = newList;
57
+ }
58
+ clearData() {
59
+ ScheduleDataManager.list = [];
60
+ }
61
+ deleteData(current) {
62
+ if (!current) {
63
+ return;
64
+ }
65
+ const index = ScheduleDataManager.list.findIndex(item => item.id === current.id);
66
+ if (index !== -1) {
67
+ ScheduleDataManager.list.splice(index, 1);
68
+ }
69
+ }
70
+
71
+ // 添加remove方法作为deleteData的别名,用于测试
72
+ remove(id) {
73
+ const index = ScheduleDataManager.list.findIndex(item => item.id === id);
74
+ if (index !== -1) {
75
+ ScheduleDataManager.list.splice(index, 1);
76
+ }
77
+ }
78
+ }
79
+ export default ScheduleDataManager;
@@ -0,0 +1,71 @@
1
+ import { TWakeUpNode, TSleepNode, TRandomNode, TRhythmData, TCountdownSchedule, TTimerDataUpdate, TCycleNode } from '../types';
2
+ import { Schedule, TFoldScheduleList } from './type';
3
+ /**
4
+ * TTimerDataAdd => Schedule
5
+ * 定时数据转换成适合冲突判断的日程对象
6
+ * @param data TTimerDataAdd
7
+ * @returns Schedule
8
+ */
9
+ export declare const timerDataToSchedule: <T extends TTimerDataUpdate>(data: T) => Schedule;
10
+ /**
11
+ * @description: 定时转换为适合冲突判断的日程列表
12
+ * @param {TTimerDataAdd} data
13
+ * @return Schedule[]
14
+ */
15
+ export declare const timerListToScheduleList: <T extends TTimerDataUpdate>(data: T[]) => Schedule[];
16
+ /**
17
+ * TWakeUpData => Schedule
18
+ * 唤醒数据转换成适合冲突判断的日程对象
19
+ * @param data TWakeUpData
20
+ * @returns Schedule
21
+ */
22
+ export declare const wakeUpNodeToSchedule: <T extends TWakeUpNode>(data: T) => Schedule;
23
+ /**
24
+ * @description: 入睡定时转换为适合冲突判断的日程列表
25
+ * @param {TWakeUpNode[]} data
26
+ * @return Schedule[]
27
+ */
28
+ export declare const wakeUpDataToScheduleList: <T extends TWakeUpNode>(data: T[]) => Schedule[];
29
+ /**
30
+ * TSleepNode => Schedule
31
+ * 唤醒数据转换成适合冲突判断的日程对象
32
+ * @param data TSleepNode
33
+ * @returns Schedule
34
+ */
35
+ export declare const sleepNodeToSchedule: <T extends TSleepNode>(data: T) => Schedule;
36
+ /**
37
+ * @description: 入睡定时转换为适合冲突判断的日程列表
38
+ * @param {TSleepNode[]} data
39
+ * @return Schedule[]
40
+ */
41
+ export declare const sleepDataToScheduleList: <T extends TSleepNode>(data: T[]) => Schedule[];
42
+ /**
43
+ * @description: 倒计时定时转换为适合冲突判断的日程列表
44
+ */
45
+ export declare const countdownToSchedule: <T extends TCountdownSchedule>(data: T) => Schedule;
46
+ export declare const rhythmToSchedule: <T extends TRhythmData>(rhythm: T) => Schedule;
47
+ /**
48
+ * @description 将随机定时数据转换为适合冲突判断的日程对象
49
+ * @param data TRandomNode
50
+ * @returns Schedule
51
+ */
52
+ export declare const randomNodeToSchedule: <T extends TRandomNode>(data: T) => Schedule;
53
+ /**
54
+ * @description: 随机定时转换为适合冲突判断的日程列表
55
+ * @param {TRandomNode[]} data
56
+ * @return Schedule[]
57
+ */
58
+ export declare const randomDataToScheduleList: <T extends TRandomNode>(data: T[]) => Schedule[];
59
+ /**
60
+ * @description 将循环定时数据转换为适合冲突判断的日程对象
61
+ * @param data TCycleNode
62
+ * @returns Schedule
63
+ */
64
+ export declare const cycleNodeToSchedule: <T extends TCycleNode>(data: T) => Schedule;
65
+ /**
66
+ * @description: 循环定时转换为适合冲突判断的日程列表
67
+ * @param {TCycleNode[]} data
68
+ * @return Schedule[]
69
+ */
70
+ export declare const cycleDataToScheduleList: <T extends TCycleNode>(data: T[]) => Schedule[];
71
+ export declare const transScheduleListToConflictList: (foldScheduleList: TFoldScheduleList) => Schedule[];
@@ -0,0 +1,251 @@
1
+ import "core-js/modules/esnext.iterator.constructor.js";
2
+ import "core-js/modules/esnext.iterator.for-each.js";
3
+ import "core-js/modules/esnext.iterator.map.js";
4
+ import dayjs from 'dayjs';
5
+ import { getBackwardOffsetTimeByHourMins, getPreOffsetTimeByHourMins, getTimerStrByMinutes } from '../utils/time';
6
+ import { EScheduleFunctionType } from '../types';
7
+ import { scheduleLogger } from '../utils/ScheduleLogger';
8
+ const numAddZero = num => {
9
+ return +num < 10 ? `0${+num}` : +num;
10
+ };
11
+
12
+ /**
13
+ * TTimerDataAdd => Schedule
14
+ * 定时数据转换成适合冲突判断的日程对象
15
+ * @param data TTimerDataAdd
16
+ * @returns Schedule
17
+ */
18
+ export const timerDataToSchedule = data => {
19
+ var _data$status;
20
+ scheduleLogger.debug('timerDataToSchedule:', data);
21
+ return {
22
+ id: `${EScheduleFunctionType.TIMER}_${data.time}_${data.loops}`,
23
+ type: EScheduleFunctionType.TIMER,
24
+ data: {
25
+ status: (_data$status = data.status) !== null && _data$status !== void 0 ? _data$status : false,
26
+ weeks: data.loops.split('').map(item => Number(item)),
27
+ startTime: data.time,
28
+ endTime: data.time
29
+ }
30
+ };
31
+ };
32
+
33
+ /**
34
+ * @description: 定时转换为适合冲突判断的日程列表
35
+ * @param {TTimerDataAdd} data
36
+ * @return Schedule[]
37
+ */
38
+ export const timerListToScheduleList = data => {
39
+ return data.map(node => {
40
+ return timerDataToSchedule(node);
41
+ });
42
+ };
43
+
44
+ /**
45
+ * TWakeUpData => Schedule
46
+ * 唤醒数据转换成适合冲突判断的日程对象
47
+ * @param data TWakeUpData
48
+ * @returns Schedule
49
+ */
50
+ export const wakeUpNodeToSchedule = data => {
51
+ const startTime = getPreOffsetTimeByHourMins(data.hour, data.minute, data.step * 5 || 0);
52
+ const endTime = getBackwardOffsetTimeByHourMins(data.hour, data.minute, data.duration * 5);
53
+ scheduleLogger.debug('wakeUpNodeToSchedule:', data);
54
+ return {
55
+ id: `${EScheduleFunctionType.WAKEUP}_${numAddZero(data.hour)}_${numAddZero(data.minute)}_${data.loops}`,
56
+ type: EScheduleFunctionType.WAKEUP,
57
+ data: {
58
+ status: data.onOff,
59
+ weeks: data.loops.split('').map(item => Number(item)),
60
+ startTime,
61
+ endTime
62
+ }
63
+ };
64
+ };
65
+
66
+ /**
67
+ * @description: 入睡定时转换为适合冲突判断的日程列表
68
+ * @param {TWakeUpNode[]} data
69
+ * @return Schedule[]
70
+ */
71
+ export const wakeUpDataToScheduleList = data => {
72
+ return data.map(node => {
73
+ return wakeUpNodeToSchedule(node);
74
+ });
75
+ };
76
+
77
+ /**
78
+ * TSleepNode => Schedule
79
+ * 唤醒数据转换成适合冲突判断的日程对象
80
+ * @param data TSleepNode
81
+ * @returns Schedule
82
+ */
83
+ export const sleepNodeToSchedule = data => {
84
+ const startTime = getPreOffsetTimeByHourMins(data.hour, data.minute, data.step * 5);
85
+ scheduleLogger.debug('sleepNodeToSchedule:', data);
86
+ return {
87
+ id: `${EScheduleFunctionType.SLEEP}_${numAddZero(data.hour)}_${numAddZero(data.minute)}_${data.loops}`,
88
+ type: EScheduleFunctionType.SLEEP,
89
+ data: {
90
+ status: data.onOff,
91
+ weeks: data.loops.split('').map(item => Number(item)),
92
+ startTime,
93
+ endTime: data.time
94
+ }
95
+ };
96
+ };
97
+
98
+ /**
99
+ * @description: 入睡定时转换为适合冲突判断的日程列表
100
+ * @param {TSleepNode[]} data
101
+ * @return Schedule[]
102
+ */
103
+ export const sleepDataToScheduleList = data => {
104
+ return data.map(node => {
105
+ return sleepNodeToSchedule(node);
106
+ });
107
+ };
108
+
109
+ /**
110
+ * @description: 倒计时定时转换为适合冲突判断的日程列表
111
+ */
112
+ export const countdownToSchedule = data => {
113
+ scheduleLogger.debug('countdownToSchedule:', data);
114
+ const {
115
+ countdown
116
+ } = data;
117
+ const now = dayjs().format('HH:mm');
118
+ const [hour, minute] = now === null || now === void 0 ? void 0 : now.split(':');
119
+ const endTime = getBackwardOffsetTimeByHourMins(+hour, +minute, Math.floor(countdown / 60));
120
+ return {
121
+ id: `${EScheduleFunctionType.COUNTDOWN}`,
122
+ type: EScheduleFunctionType.COUNTDOWN,
123
+ data: {
124
+ status: !!countdown,
125
+ weeks: [0, 0, 0, 0, 0, 0, 0],
126
+ startTime: now,
127
+ endTime
128
+ }
129
+ };
130
+ };
131
+ export const rhythmToSchedule = rhythm => {
132
+ scheduleLogger.debug('rhythmToSchedule:', rhythm);
133
+ return {
134
+ id: `${EScheduleFunctionType.RHYTHM}`,
135
+ type: EScheduleFunctionType.RHYTHM,
136
+ data: {
137
+ status: rhythm.power,
138
+ weeks: rhythm.weeks,
139
+ startTime: '00:00',
140
+ endTime: '23:59'
141
+ }
142
+ };
143
+ };
144
+
145
+ /**
146
+ * @description 将随机定时数据转换为适合冲突判断的日程对象
147
+ * @param data TRandomNode
148
+ * @returns Schedule
149
+ */
150
+ export const randomNodeToSchedule = data => {
151
+ scheduleLogger.debug('randomNodeToSchedule:', data);
152
+ const {
153
+ startTime,
154
+ endTime
155
+ } = data;
156
+ const startTimeStr = getTimerStrByMinutes(startTime);
157
+ const endTimeStr = getTimerStrByMinutes(endTime);
158
+ return {
159
+ id: `${EScheduleFunctionType.RANDOM}_${data.startTime}_${data.endTime}_${data.loops}`,
160
+ type: EScheduleFunctionType.RANDOM,
161
+ data: {
162
+ status: data.onOff,
163
+ weeks: data.loops.split('').map(item => Number(item)),
164
+ startTime: startTimeStr,
165
+ endTime: endTimeStr
166
+ }
167
+ };
168
+ };
169
+
170
+ /**
171
+ * @description: 随机定时转换为适合冲突判断的日程列表
172
+ * @param {TRandomNode[]} data
173
+ * @return Schedule[]
174
+ */
175
+ export const randomDataToScheduleList = data => {
176
+ return data.map(node => {
177
+ return randomNodeToSchedule(node);
178
+ });
179
+ };
180
+
181
+ /**
182
+ * @description 将循环定时数据转换为适合冲突判断的日程对象
183
+ * @param data TCycleNode
184
+ * @returns Schedule
185
+ */
186
+ export const cycleNodeToSchedule = data => {
187
+ scheduleLogger.debug('randomNodeToSchedule:', data);
188
+ const {
189
+ startTime,
190
+ endTime
191
+ } = data;
192
+ const startTimeStr = getTimerStrByMinutes(startTime);
193
+ const endTimeStr = getTimerStrByMinutes(endTime);
194
+ return {
195
+ id: `${EScheduleFunctionType.CYCLE}_${data.startTime}_${data.endTime}_${data.loops}`,
196
+ type: EScheduleFunctionType.CYCLE,
197
+ data: {
198
+ status: data.onOff,
199
+ weeks: data.loops.split('').map(item => Number(item)),
200
+ startTime: startTimeStr,
201
+ endTime: endTimeStr
202
+ }
203
+ };
204
+ };
205
+
206
+ /**
207
+ * @description: 循环定时转换为适合冲突判断的日程列表
208
+ * @param {TCycleNode[]} data
209
+ * @return Schedule[]
210
+ */
211
+ export const cycleDataToScheduleList = data => {
212
+ return data.map(node => {
213
+ return cycleNodeToSchedule(node);
214
+ });
215
+ };
216
+ export const transScheduleListToConflictList = foldScheduleList => {
217
+ let arr = [];
218
+ try {
219
+ foldScheduleList.forEach(item => {
220
+ if (item.type === EScheduleFunctionType.RANDOM) {
221
+ const list = randomDataToScheduleList(Array.isArray(item.detail) ? item.detail : [item.detail]);
222
+ arr = arr.concat(list);
223
+ } else if (item.type === EScheduleFunctionType.CYCLE) {
224
+ const list = cycleDataToScheduleList(Array.isArray(item.detail) ? item.detail : [item.detail]);
225
+ arr = arr.concat(list);
226
+ } else if (item.type === EScheduleFunctionType.TIMER) {
227
+ const list = timerListToScheduleList(Array.isArray(item.detail) ? item.detail : [item.detail]);
228
+ arr = arr.concat(list);
229
+ } else if (item.type === EScheduleFunctionType.WAKEUP) {
230
+ const list = wakeUpDataToScheduleList(Array.isArray(item.detail) ? item.detail : [item.detail]);
231
+ arr = arr.concat(list);
232
+ } else if (item.type === EScheduleFunctionType.SLEEP) {
233
+ const list = sleepDataToScheduleList(Array.isArray(item.detail) ? item.detail : [item.detail]);
234
+ arr = arr.concat(list);
235
+ } else if (item.type === EScheduleFunctionType.RHYTHM) {
236
+ var _item$detail;
237
+ const list = rhythmToSchedule(Array.isArray(item.detail) ? item === null || item === void 0 || (_item$detail = item.detail) === null || _item$detail === void 0 ? void 0 : _item$detail[0] : item.detail);
238
+ arr = arr.concat(list);
239
+ } else if (item.type === EScheduleFunctionType.COUNTDOWN) {
240
+ var _item$detail2;
241
+ const list = countdownToSchedule(Array.isArray(item.detail) ? item === null || item === void 0 || (_item$detail2 = item.detail) === null || _item$detail2 === void 0 ? void 0 : _item$detail2[0] : item.detail);
242
+ arr = arr.concat(list);
243
+ } else {
244
+ scheduleLogger.error('getScheduleListByType', item, '未匹配到类型');
245
+ }
246
+ });
247
+ } catch (error) {
248
+ scheduleLogger.error('transScheduleListToConflictList', error);
249
+ }
250
+ return arr;
251
+ };
@@ -0,0 +1,55 @@
1
+ import { EScheduleFunctionType, TRandomNode, TTimerDataUpdate, TWakeUpNode, TSleepNode, TRhythmData, TCountdownSchedule } from '../types';
2
+ export interface Schedule {
3
+ id: string;
4
+ prevId?: string;
5
+ type: EScheduleFunctionType;
6
+ data: {
7
+ status: boolean;
8
+ weeks: number[];
9
+ time?: string;
10
+ startTime?: string;
11
+ endTime?: string;
12
+ };
13
+ }
14
+ export declare enum DayOfWeek {
15
+ Sunday = "Sunday",
16
+ Monday = "Monday",
17
+ Tuesday = "Tuesday",
18
+ Wednesday = "Wednesday",
19
+ Thursday = "Thursday",
20
+ Friday = "Friday",
21
+ Saturday = "Saturday",
22
+ Single = "single"
23
+ }
24
+ export type TConflictRes = {
25
+ isConflict: boolean;
26
+ conflictList: {
27
+ current: Schedule;
28
+ other: Schedule;
29
+ }[];
30
+ };
31
+ export interface ConflictResult {
32
+ current: Schedule;
33
+ other: Schedule;
34
+ }
35
+ export interface UnifiedTimeRange {
36
+ id: string;
37
+ type: EScheduleFunctionType;
38
+ dayOfWeek: DayOfWeek;
39
+ startMinutes: number;
40
+ endMinutes: number;
41
+ originalSchedule: Schedule;
42
+ isCrossDay: boolean;
43
+ }
44
+ export interface ConflictRule {
45
+ isConflict(a: UnifiedTimeRange, b: UnifiedTimeRange): boolean;
46
+ shouldIgnore?(a: UnifiedTimeRange, b: UnifiedTimeRange): boolean;
47
+ }
48
+ type ScheduleNodeType = TRandomNode | TTimerDataUpdate | TWakeUpNode | TSleepNode | TRhythmData | TCountdownSchedule;
49
+ export type TSchedule = {
50
+ id?: string;
51
+ type: EScheduleFunctionType;
52
+ detail: ScheduleNodeType[];
53
+ };
54
+ export type TFoldScheduleList = TSchedule[];
55
+ export {};
@@ -0,0 +1,17 @@
1
+ export let DayOfWeek = /*#__PURE__*/function (DayOfWeek) {
2
+ DayOfWeek["Sunday"] = "Sunday";
3
+ DayOfWeek["Monday"] = "Monday";
4
+ DayOfWeek["Tuesday"] = "Tuesday";
5
+ DayOfWeek["Wednesday"] = "Wednesday";
6
+ DayOfWeek["Thursday"] = "Thursday";
7
+ DayOfWeek["Friday"] = "Friday";
8
+ DayOfWeek["Saturday"] = "Saturday";
9
+ DayOfWeek["Single"] = "single";
10
+ return DayOfWeek;
11
+ }({});
12
+
13
+ // 冲突结果接口
14
+
15
+ // 统一时间范围类型
16
+
17
+ // 规则接口
@@ -0,0 +1 @@
1
+ export declare const updateDeviceDp: (devId: string, groupId: string, dps: Record<string, {}>) => void;
@@ -0,0 +1,41 @@
1
+ /* eslint-disable @typescript-eslint/explicit-module-boundary-types */
2
+ /* eslint-disable @typescript-eslint/ban-types */
3
+ import { publishDps, publishGroupDpCodes } from '@ray-js/ray';
4
+ import { scheduleLogger as ScheduleLogger } from '../utils/ScheduleLogger';
5
+ export const updateDeviceDp = (devId, groupId, dps) => {
6
+ if (Object.keys(dps).length === 0) {
7
+ ScheduleLogger.warn('updateDeviceDp', 'dps is empty');
8
+ return;
9
+ }
10
+ if (!devId && !groupId) {
11
+ ScheduleLogger.warn('updateDeviceDp', 'devId or groupId is empty');
12
+ return;
13
+ }
14
+ if (groupId) {
15
+ publishGroupDpCodes({
16
+ groupId,
17
+ dpCodes: dps,
18
+ success: () => {
19
+ ScheduleLogger.debug('publishGroupDpCodes dp success');
20
+ },
21
+ fail: err => {
22
+ ScheduleLogger.error('publishGroupDpCodes dp fail', err);
23
+ }
24
+ });
25
+ return;
26
+ }
27
+ ScheduleLogger.debug('updateDeviceDp publishDps dps:', dps);
28
+ publishDps({
29
+ deviceId: devId,
30
+ dps,
31
+ mode: 2,
32
+ pipelines: [0, 1, 2, 3, 4, 5, 6],
33
+ options: {},
34
+ success: () => {
35
+ ScheduleLogger.debug('publishDps dp success', dps);
36
+ },
37
+ fail: err => {
38
+ ScheduleLogger.error('publishDps dp fail', err);
39
+ }
40
+ });
41
+ };
@@ -0,0 +1,5 @@
1
+ export declare const LOG_PREFIX = "[lamp-schedule-core] => ";
2
+ export declare const COMPONENT_NAME = "lamp-schedule";
3
+ export declare const LOCAL_TIMER_CATEGORY = "TimerKey";
4
+ export declare const CLOUD_TIMER_CATEGORY = "timer";
5
+ export declare const DP_CHANGE_EVENT_KEY = "dpChange";
@@ -0,0 +1,5 @@
1
+ export const LOG_PREFIX = '[lamp-schedule-core] => ';
2
+ export const COMPONENT_NAME = 'lamp-schedule';
3
+ export const LOCAL_TIMER_CATEGORY = 'TimerKey';
4
+ export const CLOUD_TIMER_CATEGORY = 'timer';
5
+ export const DP_CHANGE_EVENT_KEY = 'dpChange';
@@ -0,0 +1,3 @@
1
+ export { useRhythmContext, ContextProvider as RhythmsContextProvider, getRhythmsState, } from './rhythms';
2
+ export { useTimerContext, ContextProviderTimer as TimerContextProvider, getTimerState, } from './timer';
3
+ export { useScheduleContext, ContextProviderSchedule as ScheduleContextProvider, getScheduleState, } from './schedule';
@@ -0,0 +1,3 @@
1
+ export { useRhythmContext, ContextProvider as RhythmsContextProvider, getRhythmsState } from './rhythms';
2
+ export { useTimerContext, ContextProviderTimer as TimerContextProvider, getTimerState } from './timer';
3
+ export { useScheduleContext, ContextProviderSchedule as ScheduleContextProvider, getScheduleState } from './schedule';
@@ -0,0 +1,20 @@
1
+ import { ERhythm } from '../../types/rhythms';
2
+ interface IReturn {
3
+ type: ERhythm;
4
+ payload: any;
5
+ }
6
+ export declare const updateRhythmsMessage: (data: Record<string, any>) => IReturn;
7
+ export declare const updateRhythms: (data: Record<string, any>) => IReturn;
8
+ export declare const updateLocalMessage: (data: Record<string, any>) => IReturn;
9
+ export declare const updateUI: (data: Record<string, any>) => IReturn;
10
+ export declare const initSystemInfo: (data: Record<string, any>) => IReturn;
11
+ export declare const updateDp: (data: Record<string, any>) => IReturn;
12
+ declare const _default: {
13
+ updateLocalMessage: (data: Record<string, any>) => IReturn;
14
+ updateRhythms: (data: Record<string, any>) => IReturn;
15
+ updateRhythmsMessage: (data: Record<string, any>) => IReturn;
16
+ updateUI: (data: Record<string, any>) => IReturn;
17
+ initSystemInfo: (data: Record<string, any>) => IReturn;
18
+ updateDp: (data: Record<string, any>) => IReturn;
19
+ };
20
+ export default _default;