@ray-js/lamp-schedule-core 1.0.4-beta-5 → 1.0.4-beta-6
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/lib/conflict/__test__/transform.test.js +3 -2
- package/lib/conflict/transform.d.ts +3 -0
- package/lib/conflict/transform.js +5 -2
- package/lib/hooks/useCommonSupport.js +7 -1
- package/lib/hooks/useCycleDp.js +9 -5
- package/lib/hooks/useRandomDp.js +9 -5
- package/lib/utils/ScheduleSupport.js +2 -2
- package/package.json +1 -1
|
@@ -176,8 +176,9 @@ describe('transform', () => {
|
|
|
176
176
|
expect(result.data).toEqual({
|
|
177
177
|
status: true,
|
|
178
178
|
weeks: [1, 0, 0, 0, 0, 0, 0],
|
|
179
|
-
startTime: '22:
|
|
180
|
-
|
|
179
|
+
startTime: '22:20',
|
|
180
|
+
// 开始入睡时间 = hour:minute
|
|
181
|
+
endTime: '22:30' // 淡出至关灯时间 = hour:minute + step*5分钟 = 22:20 + 10 = 22:30
|
|
181
182
|
});
|
|
182
183
|
expect(result.id).toMatch(/^sleep_/);
|
|
183
184
|
});
|
|
@@ -31,6 +31,9 @@ export declare const wakeUpDataToScheduleList: <T extends TWakeUpNode>(data: T[]
|
|
|
31
31
|
* 入睡数据转换成适合冲突判断的日程对象
|
|
32
32
|
* @param data TSleepNode
|
|
33
33
|
* @returns Schedule
|
|
34
|
+
* 入睡任务时间段为开始入睡到淡出至关灯的时间段
|
|
35
|
+
* startTime = hour:minute(开始入睡时间)
|
|
36
|
+
* endTime = hour:minute + step*5分钟(淡出至关灯的时间)
|
|
34
37
|
*/
|
|
35
38
|
export declare const sleepNodeToSchedule: <T extends TSleepNode>(data: T) => Schedule;
|
|
36
39
|
/**
|
|
@@ -86,10 +86,13 @@ export const wakeUpDataToScheduleList = data => {
|
|
|
86
86
|
* 入睡数据转换成适合冲突判断的日程对象
|
|
87
87
|
* @param data TSleepNode
|
|
88
88
|
* @returns Schedule
|
|
89
|
+
* 入睡任务时间段为开始入睡到淡出至关灯的时间段
|
|
90
|
+
* startTime = hour:minute(开始入睡时间)
|
|
91
|
+
* endTime = hour:minute + step*5分钟(淡出至关灯的时间)
|
|
89
92
|
*/
|
|
90
93
|
export const sleepNodeToSchedule = data => {
|
|
91
|
-
const startTime =
|
|
92
|
-
const endTime = data.
|
|
94
|
+
const startTime = getTimeFormatStrByHourMins(data.hour, data.minute);
|
|
95
|
+
const endTime = getBackwardOffsetTimeByHourMins(data.hour, data.minute, (data.step || 0) * 5);
|
|
93
96
|
const _data = {
|
|
94
97
|
status: data.onOff,
|
|
95
98
|
weeks: data.loops.split('').map(item => Number(item)),
|
|
@@ -243,7 +243,13 @@ export const isInitFn = () => {
|
|
|
243
243
|
};
|
|
244
244
|
export const useInit = () => {
|
|
245
245
|
const [isInit, setIsInit] = useState(_isInit);
|
|
246
|
+
const initCheckedRef = useRef(false);
|
|
246
247
|
useEffect(() => {
|
|
248
|
+
// 如果初始化已经完成,立即更新状态(只检查一次)
|
|
249
|
+
if (!initCheckedRef.current && _isInit) {
|
|
250
|
+
initCheckedRef.current = true;
|
|
251
|
+
setIsInit(true);
|
|
252
|
+
}
|
|
247
253
|
const callback = () => {
|
|
248
254
|
scheduleLogger.info('useInit: initDone');
|
|
249
255
|
setIsInit(true);
|
|
@@ -253,7 +259,7 @@ export const useInit = () => {
|
|
|
253
259
|
emitter.off('initDone', callback);
|
|
254
260
|
};
|
|
255
261
|
}, []);
|
|
256
|
-
return isInit
|
|
262
|
+
return isInit;
|
|
257
263
|
};
|
|
258
264
|
|
|
259
265
|
/**
|
package/lib/hooks/useCycleDp.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { useMemo } from 'react';
|
|
1
|
+
import { useCallback, useMemo } from 'react';
|
|
2
2
|
import { useBaseLightDp } from './useBaseLightDp';
|
|
3
3
|
import { scheduleDpCodes } from '../config/dpCodes';
|
|
4
4
|
import { getCycleParser } from '../dpParser/cycle';
|
|
@@ -9,13 +9,17 @@ export function useCycleDp() {
|
|
|
9
9
|
updateDp
|
|
10
10
|
} = useBaseLightDp(dpCode);
|
|
11
11
|
const cycleParser = getCycleParser();
|
|
12
|
+
const _updateDp = useCallback(dpData => {
|
|
13
|
+
updateDp(cycleParser.formatter(dpData));
|
|
14
|
+
}, [cycleParser]);
|
|
12
15
|
const _dpValue = useMemo(() => {
|
|
16
|
+
if (dpValue === null || dpValue === undefined) {
|
|
17
|
+
return cycleParser.defaultValue;
|
|
18
|
+
}
|
|
13
19
|
return cycleParser.parser(dpValue);
|
|
14
|
-
}, [dpValue]);
|
|
20
|
+
}, [dpValue, cycleParser]);
|
|
15
21
|
return {
|
|
16
22
|
dpValue: _dpValue,
|
|
17
|
-
updateDp:
|
|
18
|
-
updateDp(cycleParser.formatter(dpData));
|
|
19
|
-
}
|
|
23
|
+
updateDp: _updateDp
|
|
20
24
|
};
|
|
21
25
|
}
|
package/lib/hooks/useRandomDp.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { useMemo } from 'react';
|
|
1
|
+
import { useCallback, useMemo } from 'react';
|
|
2
2
|
import { useBaseLightDp } from './useBaseLightDp';
|
|
3
3
|
import { scheduleDpCodes } from '../config/dpCodes';
|
|
4
4
|
import { getRandomParser } from '../dpParser/random';
|
|
@@ -9,13 +9,17 @@ export function useRandomDp() {
|
|
|
9
9
|
updateDp
|
|
10
10
|
} = useBaseLightDp(dpCode);
|
|
11
11
|
const randomParser = getRandomParser();
|
|
12
|
+
const _updateDp = useCallback(dpData => {
|
|
13
|
+
updateDp(randomParser.formatter(dpData));
|
|
14
|
+
}, [randomParser]);
|
|
12
15
|
const _dpValue = useMemo(() => {
|
|
16
|
+
if (dpValue === null || dpValue === undefined) {
|
|
17
|
+
return randomParser.defaultValue;
|
|
18
|
+
}
|
|
13
19
|
return randomParser.parser(dpValue);
|
|
14
|
-
}, [dpValue]);
|
|
20
|
+
}, [dpValue, randomParser]);
|
|
15
21
|
return {
|
|
16
22
|
dpValue: _dpValue,
|
|
17
|
-
updateDp:
|
|
18
|
-
updateDp(randomParser.formatter(dpData));
|
|
19
|
-
}
|
|
23
|
+
updateDp: _updateDp
|
|
20
24
|
};
|
|
21
25
|
}
|
|
@@ -96,12 +96,12 @@ export class Support {
|
|
|
96
96
|
getGroupInfo({
|
|
97
97
|
groupId,
|
|
98
98
|
success: groupRes => {
|
|
99
|
-
this.groupDevInfo = groupRes;
|
|
99
|
+
this.groupDevInfo = groupRes || {};
|
|
100
100
|
ScheduleLogger.debug('getGroupInfo groupId: ', groupId);
|
|
101
101
|
ScheduleLogger.debug('getGroupInfo success1: ', groupRes);
|
|
102
102
|
const {
|
|
103
103
|
deviceList = []
|
|
104
|
-
} = groupRes;
|
|
104
|
+
} = groupRes || {};
|
|
105
105
|
const firstDevice = deviceList === null || deviceList === void 0 ? void 0 : deviceList[0];
|
|
106
106
|
getDeviceInfo({
|
|
107
107
|
deviceId: firstDevice === null || firstDevice === void 0 ? void 0 : firstDevice.devId,
|