@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.
- package/README.md +565 -0
- package/lib/config/dpCodes.d.ts +27 -0
- package/lib/config/dpCodes.js +30 -0
- package/lib/config/index.d.ts +2 -0
- package/lib/config/index.js +2 -0
- package/lib/config/rhythms/defaultValue.d.ts +18 -0
- package/lib/config/rhythms/defaultValue.js +72 -0
- package/lib/config/rhythms/index.d.ts +10 -0
- package/lib/config/rhythms/index.js +35 -0
- package/lib/conflict/ConflictResolver.d.ts +2 -0
- package/lib/conflict/ConflictResolver.js +284 -0
- package/lib/conflict/__test__/ConflictResolver.test.d.ts +1 -0
- package/lib/conflict/__test__/ConflictResolver.test.js +183 -0
- package/lib/conflict/__test__/index.test.d.ts +1 -0
- package/lib/conflict/__test__/index.test.js +385 -0
- package/lib/conflict/__test__/scheduleDataManager.test.d.ts +1 -0
- package/lib/conflict/__test__/scheduleDataManager.test.js +170 -0
- package/lib/conflict/__test__/transform.test.d.ts +1 -0
- package/lib/conflict/__test__/transform.test.js +454 -0
- package/lib/conflict/__test__/updateDeviceDp.d.ts +1 -0
- package/lib/conflict/__test__/updateDeviceDp.js +114 -0
- package/lib/conflict/index.d.ts +42 -0
- package/lib/conflict/index.js +103 -0
- package/lib/conflict/scheduleDataManager.d.ts +12 -0
- package/lib/conflict/scheduleDataManager.js +79 -0
- package/lib/conflict/transform.d.ts +71 -0
- package/lib/conflict/transform.js +251 -0
- package/lib/conflict/type.d.ts +55 -0
- package/lib/conflict/type.js +17 -0
- package/lib/conflict/updateDeviceDp.d.ts +1 -0
- package/lib/conflict/updateDeviceDp.js +41 -0
- package/lib/constant/index.d.ts +5 -0
- package/lib/constant/index.js +5 -0
- package/lib/context/index.d.ts +3 -0
- package/lib/context/index.js +3 -0
- package/lib/context/rhythms/actions.d.ts +20 -0
- package/lib/context/rhythms/actions.js +52 -0
- package/lib/context/rhythms/index.d.ts +5 -0
- package/lib/context/rhythms/index.js +51 -0
- package/lib/context/rhythms/reducer.d.ts +24 -0
- package/lib/context/rhythms/reducer.js +38 -0
- package/lib/context/schedule/actions.d.ts +7 -0
- package/lib/context/schedule/actions.js +51 -0
- package/lib/context/schedule/context.d.ts +6 -0
- package/lib/context/schedule/context.js +52 -0
- package/lib/context/schedule/index.d.ts +1 -0
- package/lib/context/schedule/index.js +1 -0
- package/lib/context/schedule/reducer.d.ts +16 -0
- package/lib/context/schedule/reducer.js +104 -0
- package/lib/context/schedule/type.d.ts +41 -0
- package/lib/context/schedule/type.js +11 -0
- package/lib/context/timer/actions.d.ts +8 -0
- package/lib/context/timer/actions.js +52 -0
- package/lib/context/timer/context.d.ts +10 -0
- package/lib/context/timer/context.js +53 -0
- package/lib/context/timer/index.d.ts +1 -0
- package/lib/context/timer/index.js +1 -0
- package/lib/context/timer/reducer.d.ts +15 -0
- package/lib/context/timer/reducer.js +70 -0
- package/lib/context/timer/type.d.ts +46 -0
- package/lib/context/timer/type.js +24 -0
- package/lib/dpParser/README.md +63 -0
- package/lib/dpParser/__test__/cycle.test.d.ts +1 -0
- package/lib/dpParser/__test__/cycle.test.js +258 -0
- package/lib/dpParser/__test__/random.test.d.ts +1 -0
- package/lib/dpParser/__test__/random.test.js +211 -0
- package/lib/dpParser/__test__/rhythms.test.d.ts +1 -0
- package/lib/dpParser/__test__/rhythms.test.js +71 -0
- package/lib/dpParser/__test__/rtcTimer.test.d.ts +1 -0
- package/lib/dpParser/__test__/rtcTimer.test.js +235 -0
- package/lib/dpParser/__test__/sleep.test.d.ts +1 -0
- package/lib/dpParser/__test__/sleep.test.js +71 -0
- package/lib/dpParser/__test__/sleepCommon.test.d.ts +1 -0
- package/lib/dpParser/__test__/sleepCommon.test.js +197 -0
- package/lib/dpParser/__test__/timerReport.test.d.ts +1 -0
- package/lib/dpParser/__test__/timerReport.test.js +100 -0
- package/lib/dpParser/__test__/wakeup.test.d.ts +1 -0
- package/lib/dpParser/__test__/wakeup.test.js +69 -0
- package/lib/dpParser/__test__/wakeupCommon.test.d.ts +1 -0
- package/lib/dpParser/__test__/wakeupCommon.test.js +131 -0
- package/lib/dpParser/cycle/index.d.ts +15 -0
- package/lib/dpParser/cycle/index.js +134 -0
- package/lib/dpParser/index.d.ts +23 -0
- package/lib/dpParser/index.js +43 -0
- package/lib/dpParser/random/index.d.ts +15 -0
- package/lib/dpParser/random/index.js +127 -0
- package/lib/dpParser/rhythms.d.ts +41 -0
- package/lib/dpParser/rhythms.js +116 -0
- package/lib/dpParser/rtcTimer.d.ts +17 -0
- package/lib/dpParser/rtcTimer.js +300 -0
- package/lib/dpParser/sleep/index.d.ts +9 -0
- package/lib/dpParser/sleep/index.js +29 -0
- package/lib/dpParser/sleep/sleepCommon.d.ts +11 -0
- package/lib/dpParser/sleep/sleepCommon.js +117 -0
- package/lib/dpParser/sleep/sleepSigmesh.d.ts +0 -0
- package/lib/dpParser/sleep/sleepSigmesh.js +101 -0
- package/lib/dpParser/timerReport.d.ts +11 -0
- package/lib/dpParser/timerReport.js +43 -0
- package/lib/dpParser/utils.d.ts +27 -0
- package/lib/dpParser/utils.js +53 -0
- package/lib/dpParser/wakeup/index.d.ts +10 -0
- package/lib/dpParser/wakeup/index.js +34 -0
- package/lib/dpParser/wakeup/wakeupCommon.d.ts +11 -0
- package/lib/dpParser/wakeup/wakeupCommon.js +106 -0
- package/lib/dpParser/wakeup/wakeupSigmesh.d.ts +15 -0
- package/lib/dpParser/wakeup/wakeupSigmesh.js +86 -0
- package/lib/hooks/__test__/useCommon.test.d.ts +1 -0
- package/lib/hooks/__test__/useCommon.test.js +72 -0
- package/lib/hooks/__test__/useCountdownDp.test.d.ts +1 -0
- package/lib/hooks/__test__/useCountdownDp.test.js +82 -0
- package/lib/hooks/__test__/useCycleDp.test.d.ts +1 -0
- package/lib/hooks/__test__/useCycleDp.test.js +92 -0
- package/lib/hooks/__test__/useRandomDp.test.d.ts +1 -0
- package/lib/hooks/__test__/useRandomDp.test.js +88 -0
- package/lib/hooks/__test__/useRhythmsDp.test.d.ts +1 -0
- package/lib/hooks/__test__/useRhythmsDp.test.js +81 -0
- package/lib/hooks/__test__/useSleepDp.test.d.ts +1 -0
- package/lib/hooks/__test__/useSleepDp.test.js +127 -0
- package/lib/hooks/__test__/useTimeFlush.test.d.ts +1 -0
- package/lib/hooks/__test__/useTimeFlush.test.js +109 -0
- package/lib/hooks/__test__/useTimerDp.test.d.ts +1 -0
- package/lib/hooks/__test__/useTimerDp.test.js +79 -0
- package/lib/hooks/__test__/useTimerOperate.test.d.ts +1 -0
- package/lib/hooks/__test__/useTimerOperate.test.js +286 -0
- package/lib/hooks/__test__/useTimerOperateCloud.test.d.ts +1 -0
- package/lib/hooks/__test__/useTimerOperateCloud.test.js +190 -0
- package/lib/hooks/__test__/useTimerOperateLocal.test.d.ts +1 -0
- package/lib/hooks/__test__/useTimerOperateLocal.test.js +216 -0
- package/lib/hooks/__test__/useTimerReportDp.test.d.ts +1 -0
- package/lib/hooks/__test__/useTimerReportDp.test.js +93 -0
- package/lib/hooks/__test__/useTimerSupport.test.d.ts +1 -0
- package/lib/hooks/__test__/useTimerSupport.test.js +110 -0
- package/lib/hooks/__test__/useWakeUpDp.test.d.ts +1 -0
- package/lib/hooks/__test__/useWakeUpDp.test.js +129 -0
- package/lib/hooks/useBaseLightDp.d.ts +21 -0
- package/lib/hooks/useBaseLightDp.js +165 -0
- package/lib/hooks/useCommon.d.ts +29 -0
- package/lib/hooks/useCommon.js +59 -0
- package/lib/hooks/useCommonSupport.d.ts +25 -0
- package/lib/hooks/useCommonSupport.js +241 -0
- package/lib/hooks/useCountdownDp.d.ts +13 -0
- package/lib/hooks/useCountdownDp.js +28 -0
- package/lib/hooks/useCountdownSupport.d.ts +9 -0
- package/lib/hooks/useCountdownSupport.js +13 -0
- package/lib/hooks/useCycleDp.d.ts +7 -0
- package/lib/hooks/useCycleDp.js +21 -0
- package/lib/hooks/useCycleSupport.d.ts +12 -0
- package/lib/hooks/useCycleSupport.js +16 -0
- package/lib/hooks/useRandomDp.d.ts +7 -0
- package/lib/hooks/useRandomDp.js +21 -0
- package/lib/hooks/useRandomSupport.d.ts +12 -0
- package/lib/hooks/useRandomSupport.js +16 -0
- package/lib/hooks/useRhythmsDp.d.ts +7 -0
- package/lib/hooks/useRhythmsDp.js +23 -0
- package/lib/hooks/useSleepDp.d.ts +6 -0
- package/lib/hooks/useSleepDp.js +21 -0
- package/lib/hooks/useSleepSupport.d.ts +8 -0
- package/lib/hooks/useSleepSupport.js +13 -0
- package/lib/hooks/useTimeFlush.d.ts +8 -0
- package/lib/hooks/useTimeFlush.js +31 -0
- package/lib/hooks/useTimerDp.d.ts +5 -0
- package/lib/hooks/useTimerDp.js +25 -0
- package/lib/hooks/useTimerFlushList.d.ts +11 -0
- package/lib/hooks/useTimerFlushList.js +53 -0
- package/lib/hooks/useTimerOperate.d.ts +68 -0
- package/lib/hooks/useTimerOperate.js +403 -0
- package/lib/hooks/useTimerOperateCloud.d.ts +31 -0
- package/lib/hooks/useTimerOperateCloud.js +233 -0
- package/lib/hooks/useTimerOperateLocal.d.ts +40 -0
- package/lib/hooks/useTimerOperateLocal.js +310 -0
- package/lib/hooks/useTimerReportDp.d.ts +15 -0
- package/lib/hooks/useTimerReportDp.js +48 -0
- package/lib/hooks/useTimerSupport.d.ts +13 -0
- package/lib/hooks/useTimerSupport.js +38 -0
- package/lib/hooks/useWakeUpDp.d.ts +6 -0
- package/lib/hooks/useWakeUpDp.js +21 -0
- package/lib/hooks/useWakeUpSupport.d.ts +8 -0
- package/lib/hooks/useWakeUpSupport.js +13 -0
- package/lib/hooks/useWakeupDp.d.ts +6 -0
- package/lib/hooks/useWakeupDp.js +21 -0
- package/lib/hooks/useWakeupSupport.d.ts +8 -0
- package/lib/hooks/useWakeupSupport.js +13 -0
- package/lib/i18n/index.d.ts +142 -0
- package/lib/i18n/index.js +7 -0
- package/lib/i18n/rhythms.d.ts +73 -0
- package/lib/i18n/rhythms.js +72 -0
- package/lib/i18n/strings.d.ts +73 -0
- package/lib/i18n/strings.js +6 -0
- package/lib/index.d.ts +51 -0
- package/lib/index.js +64 -0
- package/lib/types/countdown.d.ts +3 -0
- package/lib/types/countdown.js +1 -0
- package/lib/types/cycle.d.ts +22 -0
- package/lib/types/cycle.js +1 -0
- package/lib/types/global.d.ts +9 -0
- package/lib/types/index.d.ts +331 -0
- package/lib/types/index.js +76 -0
- package/lib/types/random.d.ts +20 -0
- package/lib/types/random.js +1 -0
- package/lib/types/rhythms.d.ts +79 -0
- package/lib/types/rhythms.js +15 -0
- package/lib/types/sleep.d.ts +36 -0
- package/lib/types/sleep.js +1 -0
- package/lib/types/timer.d.ts +107 -0
- package/lib/types/timer.js +1 -0
- package/lib/types/wakeup.d.ts +38 -0
- package/lib/types/wakeup.js +1 -0
- package/lib/utils/ScheduleCache.d.ts +19 -0
- package/lib/utils/ScheduleCache.js +39 -0
- package/lib/utils/ScheduleCloudProperty.d.ts +75 -0
- package/lib/utils/ScheduleCloudProperty.js +220 -0
- package/lib/utils/ScheduleDataSync.d.ts +82 -0
- package/lib/utils/ScheduleDataSync.js +127 -0
- package/lib/utils/ScheduleEmit.d.ts +67 -0
- package/lib/utils/ScheduleEmit.js +61 -0
- package/lib/utils/ScheduleLogger.d.ts +19 -0
- package/lib/utils/ScheduleLogger.js +71 -0
- package/lib/utils/ScheduleSupport.d.ts +131 -0
- package/lib/utils/ScheduleSupport.js +373 -0
- package/lib/utils/ScheduleUtils.d.ts +12 -0
- package/lib/utils/ScheduleUtils.js +51 -0
- package/lib/utils/__test__/ScheduleCloudProperty.test.d.ts +1 -0
- package/lib/utils/__test__/ScheduleCloudProperty.test.js +320 -0
- package/lib/utils/__test__/ScheduleSupport.test.d.ts +1 -0
- package/lib/utils/__test__/ScheduleSupport.test.js +211 -0
- package/lib/utils/__test__/ScheduleUtils.test.d.ts +1 -0
- package/lib/utils/__test__/ScheduleUtils.test.js +119 -0
- package/lib/utils/__test__/common.test.d.ts +1 -0
- package/lib/utils/__test__/common.test.js +147 -0
- package/lib/utils/__test__/storage.test.d.ts +1 -0
- package/lib/utils/__test__/storage.test.js +98 -0
- package/lib/utils/__test__/time.test.d.ts +1 -0
- package/lib/utils/__test__/time.test.js +146 -0
- package/lib/utils/common.d.ts +23 -0
- package/lib/utils/common.js +109 -0
- package/lib/utils/dpState.d.ts +5 -0
- package/lib/utils/dpState.js +27 -0
- package/lib/utils/getCachedSystemInfo.d.ts +39 -0
- package/lib/utils/getCachedSystemInfo.js +20 -0
- package/lib/utils/isInIDE.d.ts +1 -0
- package/lib/utils/isInIDE.js +5 -0
- package/lib/utils/storage.d.ts +5 -0
- package/lib/utils/storage.js +32 -0
- package/lib/utils/time.d.ts +40 -0
- package/lib/utils/time.js +84 -0
- 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
|
+
}
|