@ray-js/lamp-schedule-core 1.0.0-beta-5 → 1.0.1-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.
@@ -237,7 +237,7 @@ function mergeListByOtherId(list) {
237
237
  return Object.values(mergedData);
238
238
  }
239
239
 
240
- // 冲突检测核心函数(修改后的版本)
240
+ // 冲突检测核心函数
241
241
  export function checkConflicts(scheduleList, currentSchedule) {
242
242
  let rule = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : defaultRule;
243
243
  const currentRanges = convertToTimeRanges([currentSchedule]);
@@ -260,6 +260,11 @@ export function checkConflicts(scheduleList, currentSchedule) {
260
260
  const currentPreId = current === null || current === void 0 || (_current$originalSche = current.originalSchedule) === null || _current$originalSche === void 0 ? void 0 : _current$originalSche.prevId;
261
261
  const currentId = current === null || current === void 0 || (_current$originalSche2 = current.originalSchedule) === null || _current$originalSche2 === void 0 ? void 0 : _current$originalSche2.id;
262
262
  const otherId = other.id;
263
+ // 针对定时,如果当前定时自身修改 且 与自身冲突 则忽略
264
+ if (currentPreId && currentId === currentPreId && current.type === 'timer') {
265
+ return;
266
+ }
267
+ // FIXME:还是存在bug
263
268
  // 如果当前定时自身修改 且 与自身冲突 并且其他定时不等于当前定时id 则忽略
264
269
  if (currentPreId && currentId === currentPreId && otherId !== currentId) {
265
270
  return;
@@ -43,16 +43,14 @@ describe('transform', () => {
43
43
  aliasName: 'aliasName',
44
44
  isAppPush: false
45
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
- }
46
+ expect(result.type).toBe(EScheduleFunctionType.TIMER);
47
+ expect(result.data).toEqual({
48
+ status: true,
49
+ weeks: [1, 0, 0, 0, 0, 0, 0],
50
+ startTime: '10:00',
51
+ endTime: '10:00'
55
52
  });
53
+ expect(result.id).toMatch(/^timer_/);
56
54
  });
57
55
  it('应该处理缺少状态的定时数据', () => {
58
56
  const result = timerDataToSchedule({
@@ -86,8 +84,10 @@ describe('transform', () => {
86
84
  isAppPush: false
87
85
  }]);
88
86
  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`);
87
+ expect(result[0].type).toBe(EScheduleFunctionType.TIMER);
88
+ expect(result[1].type).toBe(EScheduleFunctionType.TIMER);
89
+ expect(result[0].id).toMatch(/^timer_/);
90
+ expect(result[1].id).toMatch(/^timer_/);
91
91
  });
92
92
  });
93
93
  describe('wakeUpNodeToSchedule', () => {
@@ -106,16 +106,14 @@ describe('transform', () => {
106
106
  temperature: 1000,
107
107
  index: 1
108
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
- }
109
+ expect(result.type).toBe(EScheduleFunctionType.WAKEUP);
110
+ expect(result.data).toEqual({
111
+ status: true,
112
+ weeks: [1, 0, 0, 0, 0, 0, 0],
113
+ startTime: '8:20',
114
+ endTime: '8:45'
118
115
  });
116
+ expect(result.id).toMatch(/^wakeup_/);
119
117
  });
120
118
  });
121
119
  describe('wakeUpDataToScheduleList', () => {
@@ -148,8 +146,10 @@ describe('transform', () => {
148
146
  index: 2
149
147
  }]);
150
148
  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`);
149
+ expect(result[0].type).toBe(EScheduleFunctionType.WAKEUP);
150
+ expect(result[1].type).toBe(EScheduleFunctionType.WAKEUP);
151
+ expect(result[0].id).toMatch(/^wakeup_/);
152
+ expect(result[1].id).toMatch(/^wakeup_/);
153
153
  });
154
154
  });
155
155
  describe('sleepNodeToSchedule', () => {
@@ -168,16 +168,14 @@ describe('transform', () => {
168
168
  temperature: 1000,
169
169
  index: 2
170
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
- }
171
+ expect(result.type).toBe(EScheduleFunctionType.SLEEP);
172
+ expect(result.data).toEqual({
173
+ status: true,
174
+ weeks: [1, 0, 0, 0, 0, 0, 0],
175
+ startTime: '22:10',
176
+ endTime: '22:30'
180
177
  });
178
+ expect(result.id).toMatch(/^sleep_/);
181
179
  });
182
180
  });
183
181
  describe('sleepDataToScheduleList', () => {
@@ -210,8 +208,10 @@ describe('transform', () => {
210
208
  index: 2
211
209
  }]);
212
210
  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`);
211
+ expect(result[0].type).toBe(EScheduleFunctionType.SLEEP);
212
+ expect(result[1].type).toBe(EScheduleFunctionType.SLEEP);
213
+ expect(result[0].id).toMatch(/^sleep_/);
214
+ expect(result[1].id).toMatch(/^sleep_/);
215
215
  });
216
216
  });
217
217
  describe('countdownToSchedule', () => {
@@ -278,16 +278,14 @@ describe('transform', () => {
278
278
  temperature: 1000
279
279
  }
280
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
- }
281
+ expect(result.type).toBe(EScheduleFunctionType.RANDOM);
282
+ expect(result.data).toEqual({
283
+ status: true,
284
+ weeks: [1, 0, 0, 0, 0, 0, 0],
285
+ startTime: '10:00',
286
+ endTime: '12:00'
290
287
  });
288
+ expect(result.id).toMatch(/^random_/);
291
289
  });
292
290
  });
293
291
  describe('randomDataToScheduleList', () => {
@@ -326,8 +324,10 @@ describe('transform', () => {
326
324
  }
327
325
  }]);
328
326
  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`);
327
+ expect(result[0].type).toBe(EScheduleFunctionType.RANDOM);
328
+ expect(result[1].type).toBe(EScheduleFunctionType.RANDOM);
329
+ expect(result[0].id).toMatch(/^random_/);
330
+ expect(result[1].id).toMatch(/^random_/);
331
331
  });
332
332
  });
333
333
  describe('cycleNodeToSchedule', () => {
@@ -351,16 +351,14 @@ describe('transform', () => {
351
351
  temperature: 1000
352
352
  }
353
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
- }
354
+ expect(result.type).toBe(EScheduleFunctionType.CYCLE);
355
+ expect(result.data).toEqual({
356
+ status: true,
357
+ weeks: [1, 0, 0, 0, 0, 0, 0],
358
+ startTime: '10:00',
359
+ endTime: '12:00'
363
360
  });
361
+ expect(result.id).toMatch(/^cycle_/);
364
362
  });
365
363
  });
366
364
  describe('cycleDataToScheduleList', () => {
@@ -403,8 +401,10 @@ describe('transform', () => {
403
401
  }
404
402
  }]);
405
403
  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`);
404
+ expect(result[0].type).toBe(EScheduleFunctionType.CYCLE);
405
+ expect(result[1].type).toBe(EScheduleFunctionType.CYCLE);
406
+ expect(result[0].id).toMatch(/^cycle_/);
407
+ expect(result[1].id).toMatch(/^cycle_/);
408
408
  });
409
409
  });
410
410
  describe('transScheduleListToConflictList', () => {
@@ -23,10 +23,15 @@ export const timerDataToSchedule = data => {
23
23
  status: (_data$status = data.status) !== null && _data$status !== void 0 ? _data$status : false,
24
24
  weeks: data.loops.split('').map(item => Number(item)),
25
25
  startTime: data.time,
26
- endTime: data.time
26
+ endTime: data.time,
27
+ dps: data.dps,
28
+ aliasName: data.aliasName || '',
29
+ isAppPush: data.isAppPush || false,
30
+ id: (data === null || data === void 0 ? void 0 : data.id) || data.timerId
27
31
  };
32
+ const timerId = `${EScheduleFunctionType.TIMER}_${_data.id}`;
28
33
  return {
29
- id: objectToId(_data, `${EScheduleFunctionType.TIMER}_`),
34
+ id: timerId || objectToId(_data, `${EScheduleFunctionType.TIMER}_`),
30
35
  type: EScheduleFunctionType.TIMER,
31
36
  data: _data
32
37
  };
@@ -1,6 +1,6 @@
1
1
  import { renderHook, act } from '@testing-library/react-hooks';
2
2
  import { useCountdownDp, useCountdownDpPull } from '../useCountdownDp';
3
- import { useBaseLightDp, useFetchDpDataByMesh } from '../useBaseLightDp';
3
+ import { useBaseLightDp, useFetchDpData } from '../useBaseLightDp';
4
4
  import { scheduleDpCodes } from '../../config/dpCodes';
5
5
  // Mock dependencies
6
6
  jest.mock('../useBaseLightDp');
@@ -51,7 +51,7 @@ describe('useCountdownDpPull', () => {
51
51
  const mockRefresh = jest.fn();
52
52
  beforeEach(() => {
53
53
  jest.clearAllMocks();
54
- useFetchDpDataByMesh.mockReturnValue({
54
+ useFetchDpData.mockReturnValue({
55
55
  refresh: mockRefresh
56
56
  });
57
57
  });
@@ -72,11 +72,11 @@ describe('useCountdownDpPull', () => {
72
72
  });
73
73
  it('should use correct dpCode', () => {
74
74
  renderHook(() => useCountdownDpPull());
75
- expect(useFetchDpDataByMesh).toHaveBeenCalledWith([scheduleDpCodes.COUNTDOWN]);
75
+ expect(useFetchDpData).toHaveBeenCalledWith([scheduleDpCodes.COUNTDOWN]);
76
76
  });
77
77
  it('should handle custom dpCode', () => {
78
78
  const customDpCode = scheduleDpCodes.COUNTDOWN;
79
79
  renderHook(() => useCountdownDpPull(customDpCode));
80
- expect(useFetchDpDataByMesh).toHaveBeenCalledWith([customDpCode]);
80
+ expect(useFetchDpData).toHaveBeenCalledWith([customDpCode]);
81
81
  });
82
82
  });
@@ -1,6 +1,6 @@
1
1
  import { renderHook, act } from '@testing-library/react-hooks';
2
2
  import { useTimerReportDp, useTimerReportDpPull } from '../useTimerReportDp';
3
- import { useBaseLightDp, useFetchDpDataByMesh } from '../useBaseLightDp';
3
+ import { useBaseLightDp, useFetchDpData } from '../useBaseLightDp';
4
4
  import { useSupport } from '../useCommonSupport';
5
5
  import { scheduleDpCodes } from '../../config/dpCodes';
6
6
  import { timerReportParser } from '../../dpParser';
@@ -66,7 +66,7 @@ describe('useTimerReportDpPull', () => {
66
66
  const mockRefresh = jest.fn();
67
67
  beforeEach(() => {
68
68
  jest.clearAllMocks();
69
- useFetchDpDataByMesh.mockReturnValue({
69
+ useFetchDpData.mockReturnValue({
70
70
  refresh: mockRefresh
71
71
  });
72
72
  });
@@ -88,6 +88,6 @@ describe('useTimerReportDpPull', () => {
88
88
  });
89
89
  it('should use correct dpCode', () => {
90
90
  renderHook(() => useTimerReportDpPull());
91
- expect(useFetchDpDataByMesh).toHaveBeenCalledWith([scheduleDpCodes.TIMER_REPORT]);
91
+ expect(useFetchDpData).toHaveBeenCalledWith([scheduleDpCodes.TIMER_REPORT]);
92
92
  });
93
93
  });
package/lib/index.d.ts CHANGED
@@ -19,7 +19,7 @@ export { useWakeUpDp } from './hooks/useWakeUpDp';
19
19
  export { useRandomDp } from './hooks/useRandomDp';
20
20
  export { useCycleDp } from './hooks/useCycleDp';
21
21
  export { useWakeUpSupport } from './hooks/useWakeUpSupport';
22
- export { useBaseLightDp, useFetchDpDataByMesh, getDpDataByMesh, useFetchDpData } from './hooks/useBaseLightDp';
22
+ export { useBaseLightDp, useFetchDpDataByMesh, getDpDataByMesh, useFetchDpData, } from './hooks/useBaseLightDp';
23
23
  export { useTimerReportDp, useTimerReportDpPull } from './hooks/useTimerReportDp';
24
24
  /** Conflict 冲突判断 */
25
25
  export { transScheduleListToConflictList } from './conflict/transform';
@@ -24,7 +24,9 @@ export const objectToId = function (obj) {
24
24
  // 简单哈希算法
25
25
  let hash = 5381;
26
26
  for (let i = 0; i < str.length; i++) {
27
+ // eslint-disable-next-line no-bitwise
27
28
  hash = (hash << 5) + hash + str.charCodeAt(i);
29
+ // eslint-disable-next-line operator-assignment, no-bitwise
28
30
  hash = hash & hash; // 转换为32位整数
29
31
  }
30
32
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ray-js/lamp-schedule-core",
3
- "version": "1.0.0-beta-5",
3
+ "version": "1.0.1-beta-1",
4
4
  "description": "照明计划模块核心能力",
5
5
  "main": "./lib/index.js",
6
6
  "files": [