@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,241 @@
|
|
|
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.every.js";
|
|
4
|
+
import "core-js/modules/esnext.iterator.for-each.js";
|
|
5
|
+
import "core-js/modules/esnext.iterator.some.js";
|
|
6
|
+
import { useEffect, useMemo, useRef, useState } from 'react';
|
|
7
|
+
import { getDeviceInfo, getGroupDpsInfos, onDpDataChange, registerDeviceListListener } from '@ray-js/ray';
|
|
8
|
+
import { Support } from '../utils/ScheduleSupport';
|
|
9
|
+
import { useTimerContext } from '../context/timer/context';
|
|
10
|
+
import { scheduleLogger, scheduleLogger as ScheduleLogger } from '../utils/ScheduleLogger';
|
|
11
|
+
import { getTimerListWithFlush } from './useTimerOperateLocal';
|
|
12
|
+
import { emitter } from '../utils/ScheduleEmit';
|
|
13
|
+
import { initStorage } from '../utils/storage';
|
|
14
|
+
import { DP_CHANGE_EVENT_KEY } from '../constant';
|
|
15
|
+
import { initDpState } from '../utils/dpState';
|
|
16
|
+
import { getDpCodeByDpId } from '../utils/ScheduleUtils';
|
|
17
|
+
// Support 实例缓存
|
|
18
|
+
let supportIns = {
|
|
19
|
+
isReady: false,
|
|
20
|
+
support: null
|
|
21
|
+
};
|
|
22
|
+
|
|
23
|
+
// Support hooks
|
|
24
|
+
export const useSupport = () => {
|
|
25
|
+
const [_support, setSupport] = useState(supportIns.support);
|
|
26
|
+
useEffect(() => {
|
|
27
|
+
const callback = () => {
|
|
28
|
+
supportIns.support && setSupport(supportIns.support);
|
|
29
|
+
};
|
|
30
|
+
emitter.on('initDone', callback);
|
|
31
|
+
return () => {
|
|
32
|
+
emitter.off('initDone', callback);
|
|
33
|
+
};
|
|
34
|
+
}, []);
|
|
35
|
+
return _support || supportIns.support;
|
|
36
|
+
};
|
|
37
|
+
let _isInit = false;
|
|
38
|
+
|
|
39
|
+
// 添加resetIsInit函数
|
|
40
|
+
export const resetIsInit = () => {
|
|
41
|
+
_isInit = false;
|
|
42
|
+
supportIns = {
|
|
43
|
+
isReady: false,
|
|
44
|
+
support: null
|
|
45
|
+
};
|
|
46
|
+
};
|
|
47
|
+
export const useScheduleInit = props => {
|
|
48
|
+
const [scheduleState, setScheduleState] = useState(supportIns);
|
|
49
|
+
const {
|
|
50
|
+
dispatch,
|
|
51
|
+
actions
|
|
52
|
+
} = useTimerContext();
|
|
53
|
+
const callbackRef = useRef(() => {
|
|
54
|
+
ScheduleLogger.info('getTimerListWithFlush run');
|
|
55
|
+
getTimerListWithFlush(dispatch, actions);
|
|
56
|
+
});
|
|
57
|
+
useEffect(() => {
|
|
58
|
+
ScheduleLogger.info('timerReportFlushList 事件监听');
|
|
59
|
+
// 监听 timerReportFlushList 事件,当 timer_report dp 变化时,触发刷新 timerList
|
|
60
|
+
emitter.off('timerReportFlushList', callbackRef.current);
|
|
61
|
+
emitter.on('timerReportFlushList', callbackRef.current);
|
|
62
|
+
return () => {
|
|
63
|
+
_isInit = false;
|
|
64
|
+
emitter.off('timerReportFlushList', callbackRef.current);
|
|
65
|
+
};
|
|
66
|
+
}, []);
|
|
67
|
+
|
|
68
|
+
// eslint-disable-next-line consistent-return
|
|
69
|
+
useEffect(() => {
|
|
70
|
+
if (_isInit) {
|
|
71
|
+
return;
|
|
72
|
+
}
|
|
73
|
+
if (props.devId) {
|
|
74
|
+
registerDeviceListListener({
|
|
75
|
+
deviceIdList: [props.devId],
|
|
76
|
+
success: () => {
|
|
77
|
+
// 监听dp值变化 并触发
|
|
78
|
+
|
|
79
|
+
if (_isInit) {
|
|
80
|
+
ScheduleLogger.warn('useSupport: support is already initialized');
|
|
81
|
+
return;
|
|
82
|
+
}
|
|
83
|
+
onDpDataChange(res => {
|
|
84
|
+
if (!(res !== null && res !== void 0 && res.dps)) {
|
|
85
|
+
ScheduleLogger.warn(`useScheduleInit fail ${DP_CHANGE_EVENT_KEY}`, res);
|
|
86
|
+
return;
|
|
87
|
+
}
|
|
88
|
+
ScheduleLogger.info(`useScheduleInit ${DP_CHANGE_EVENT_KEY}`, res);
|
|
89
|
+
emitter.emit(DP_CHANGE_EVENT_KEY, {
|
|
90
|
+
deviceId: res.devId || res.deviceId,
|
|
91
|
+
dps: res === null || res === void 0 ? void 0 : res.dps
|
|
92
|
+
});
|
|
93
|
+
});
|
|
94
|
+
}
|
|
95
|
+
});
|
|
96
|
+
}
|
|
97
|
+
}, [_isInit, actions]);
|
|
98
|
+
useEffect(() => {
|
|
99
|
+
if (!props.devId && !props.groupId) {
|
|
100
|
+
ScheduleLogger.warn('useSupport: devId or groupId is required');
|
|
101
|
+
return;
|
|
102
|
+
}
|
|
103
|
+
scheduleLogger.warn('useSupport: panelConfig is initialized');
|
|
104
|
+
const newProps = _objectSpread({}, props);
|
|
105
|
+
if (_isInit) {
|
|
106
|
+
ScheduleLogger.warn('useSupport: support is already initialized');
|
|
107
|
+
return;
|
|
108
|
+
}
|
|
109
|
+
const support = new Support(newProps);
|
|
110
|
+
ScheduleLogger.warn('useSupport initStorage props: ', props);
|
|
111
|
+
const promiseList = Promise.all([initStorage(props.devId, props.groupId), support.init()]);
|
|
112
|
+
promiseList.then(() => {
|
|
113
|
+
if (props.groupId) {
|
|
114
|
+
// 获取群组 dp 数据
|
|
115
|
+
getGroupDpsInfos(props.groupId).then(res => {
|
|
116
|
+
scheduleLogger.debug('getGroupDpsInfos res', res);
|
|
117
|
+
res && Object.keys(res).length && initDpState(res);
|
|
118
|
+
supportIns = {
|
|
119
|
+
isReady: true,
|
|
120
|
+
support
|
|
121
|
+
};
|
|
122
|
+
emitter.emit('initDone');
|
|
123
|
+
_isInit = true;
|
|
124
|
+
ScheduleLogger.debug('useSupport: support init success', true);
|
|
125
|
+
setScheduleState({
|
|
126
|
+
isReady: true
|
|
127
|
+
});
|
|
128
|
+
}).catch(err => {
|
|
129
|
+
scheduleLogger.error('Failed to get group info groupId:', props.groupId);
|
|
130
|
+
scheduleLogger.error('Failed to get group info err:', err);
|
|
131
|
+
});
|
|
132
|
+
} else {
|
|
133
|
+
// 获取单设备 dp 数据
|
|
134
|
+
getDeviceInfo({
|
|
135
|
+
deviceId: props.devId,
|
|
136
|
+
success(res) {
|
|
137
|
+
const {
|
|
138
|
+
dps = {}
|
|
139
|
+
} = res || {};
|
|
140
|
+
const dpMap = {};
|
|
141
|
+
scheduleLogger.debug('getDeviceInfo res', res);
|
|
142
|
+
Object.keys(dps).forEach(dpId => {
|
|
143
|
+
const dpCode = getDpCodeByDpId(dpId);
|
|
144
|
+
dpMap[dpCode] = dps[dpId];
|
|
145
|
+
});
|
|
146
|
+
Object.keys(dpMap).length && initDpState(dpMap);
|
|
147
|
+
supportIns = {
|
|
148
|
+
isReady: true,
|
|
149
|
+
support
|
|
150
|
+
};
|
|
151
|
+
emitter.emit('initDone');
|
|
152
|
+
_isInit = true;
|
|
153
|
+
ScheduleLogger.debug('useSupport: support init success', true);
|
|
154
|
+
setScheduleState({
|
|
155
|
+
isReady: true
|
|
156
|
+
});
|
|
157
|
+
},
|
|
158
|
+
fail(err) {
|
|
159
|
+
scheduleLogger.error('Failed to get device info deviceId:', props.devId);
|
|
160
|
+
scheduleLogger.error('Failed to get device info err:', err);
|
|
161
|
+
}
|
|
162
|
+
});
|
|
163
|
+
}
|
|
164
|
+
}).catch(err => {
|
|
165
|
+
ScheduleLogger.error('useSupport: support init failed: ', err);
|
|
166
|
+
setScheduleState({
|
|
167
|
+
isReady: false
|
|
168
|
+
});
|
|
169
|
+
});
|
|
170
|
+
}, [props.devId, props.groupId]);
|
|
171
|
+
return scheduleState;
|
|
172
|
+
};
|
|
173
|
+
|
|
174
|
+
// 获取 Support 实例
|
|
175
|
+
export const getSupportIns = () => {
|
|
176
|
+
var _supportIns;
|
|
177
|
+
if (!((_supportIns = supportIns) !== null && _supportIns !== void 0 && _supportIns.isReady)) {
|
|
178
|
+
ScheduleLogger.error('getSupportIns: support init failed, please call useScheduleInit first');
|
|
179
|
+
return supportIns.support;
|
|
180
|
+
}
|
|
181
|
+
return supportIns.support;
|
|
182
|
+
};
|
|
183
|
+
|
|
184
|
+
// 判断是否初始化
|
|
185
|
+
export const isInitFn = () => {
|
|
186
|
+
return _isInit;
|
|
187
|
+
};
|
|
188
|
+
export const useInit = () => {
|
|
189
|
+
const [isInit, setIsInit] = useState(_isInit);
|
|
190
|
+
useEffect(() => {
|
|
191
|
+
const callback = () => {
|
|
192
|
+
scheduleLogger.info('useInit: initDone');
|
|
193
|
+
setIsInit(true);
|
|
194
|
+
};
|
|
195
|
+
emitter.on('initDone', callback);
|
|
196
|
+
return () => {
|
|
197
|
+
emitter.off('initDone', callback);
|
|
198
|
+
};
|
|
199
|
+
}, []);
|
|
200
|
+
return isInit || _isInit;
|
|
201
|
+
};
|
|
202
|
+
|
|
203
|
+
/**
|
|
204
|
+
* @description: 判断是否支持某个功能 通过dpCode 来判断
|
|
205
|
+
* @param defaultCodes: 默认检测的 dpCode
|
|
206
|
+
* @param dpCodeList: dpCode 列表 string[], 非必填,默认为 [], 会检测标准计划 dp,如果不为 [],则检测 dpCodeList 中的 dp 支持情况
|
|
207
|
+
* @param checkType: 检测类型,every 必须支持 dpCodeList或defaultCodes 中所有的 dp 值,some 为支持其中一个即可。
|
|
208
|
+
* @return boolean
|
|
209
|
+
*/
|
|
210
|
+
export const useCommonSupport = function (defaultCodes) {
|
|
211
|
+
let dpCodeList = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : [];
|
|
212
|
+
let checkType = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 'some';
|
|
213
|
+
const support = useSupport();
|
|
214
|
+
const isSupport = useMemo(() => {
|
|
215
|
+
if (!support) {
|
|
216
|
+
return false;
|
|
217
|
+
}
|
|
218
|
+
let _isSupport = false;
|
|
219
|
+
if (dpCodeList.length === 0) {
|
|
220
|
+
const _dpCodeList = defaultCodes;
|
|
221
|
+
if (checkType === 'some') {
|
|
222
|
+
_isSupport = _dpCodeList.some(_dpCode => support.isSupportDp(_dpCode));
|
|
223
|
+
} else if (checkType === 'every') {
|
|
224
|
+
_isSupport = _dpCodeList.every(_dpCode => support.isSupportDp(_dpCode));
|
|
225
|
+
}
|
|
226
|
+
// 默认检测本地定时 DP
|
|
227
|
+
return _isSupport;
|
|
228
|
+
}
|
|
229
|
+
// 自定义检测本地 定时 DP
|
|
230
|
+
if (checkType === 'some') {
|
|
231
|
+
_isSupport = dpCodeList.some(_dpCode => support.isSupportDp(_dpCode));
|
|
232
|
+
} else if (checkType === 'every') {
|
|
233
|
+
_isSupport = dpCodeList.every(_dpCode => support.isSupportDp(_dpCode));
|
|
234
|
+
}
|
|
235
|
+
return _isSupport;
|
|
236
|
+
}, [JSON.stringify(dpCodeList), checkType, JSON.stringify(defaultCodes), support]);
|
|
237
|
+
return {
|
|
238
|
+
isReady: true,
|
|
239
|
+
isSupport
|
|
240
|
+
};
|
|
241
|
+
};
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { DpValue } from '../types';
|
|
2
|
+
export declare function useCountdownDp(dpCode?: "countdown"): {
|
|
3
|
+
dpValue: DpValue | null;
|
|
4
|
+
updateDp: (value: DpValue) => void;
|
|
5
|
+
};
|
|
6
|
+
/**
|
|
7
|
+
* 主动拉取倒计时dp数据
|
|
8
|
+
* @param countdownCode 倒计时dpCode
|
|
9
|
+
* @returns refresh 函数 刷新dp数据
|
|
10
|
+
*/
|
|
11
|
+
export declare const useCountdownDpPull: (countdownCode?: "countdown") => {
|
|
12
|
+
refresh: () => void;
|
|
13
|
+
};
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { useBaseLightDp, useFetchDpDataByMesh } from './useBaseLightDp';
|
|
2
|
+
import { scheduleDpCodes } from '../config/dpCodes';
|
|
3
|
+
export function useCountdownDp() {
|
|
4
|
+
let dpCode = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : scheduleDpCodes.COUNTDOWN;
|
|
5
|
+
const {
|
|
6
|
+
dpValue,
|
|
7
|
+
updateDp
|
|
8
|
+
} = useBaseLightDp(dpCode);
|
|
9
|
+
return {
|
|
10
|
+
dpValue,
|
|
11
|
+
updateDp
|
|
12
|
+
};
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* 主动拉取倒计时dp数据
|
|
17
|
+
* @param countdownCode 倒计时dpCode
|
|
18
|
+
* @returns refresh 函数 刷新dp数据
|
|
19
|
+
*/
|
|
20
|
+
export const useCountdownDpPull = function () {
|
|
21
|
+
let countdownCode = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : scheduleDpCodes.COUNTDOWN;
|
|
22
|
+
const {
|
|
23
|
+
refresh
|
|
24
|
+
} = useFetchDpDataByMesh([countdownCode]);
|
|
25
|
+
return {
|
|
26
|
+
refresh
|
|
27
|
+
};
|
|
28
|
+
};
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { scheduleDpCodes } from '../config/dpCodes';
|
|
2
|
+
import { useCommonSupport } from './useCommonSupport';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* @description: 判断是否支持倒计时功能
|
|
6
|
+
* @param dpCodeList: 倒计时 dpCode 列表 string[]
|
|
7
|
+
* @return {isReady, isSupport}
|
|
8
|
+
*/
|
|
9
|
+
export const useCountdownSupport = function () {
|
|
10
|
+
let dpCodeList = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : [];
|
|
11
|
+
const support = useCommonSupport([scheduleDpCodes.COUNTDOWN], dpCodeList);
|
|
12
|
+
return support;
|
|
13
|
+
};
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { useMemo } from 'react';
|
|
2
|
+
import { useBaseLightDp } from './useBaseLightDp';
|
|
3
|
+
import { scheduleDpCodes } from '../config/dpCodes';
|
|
4
|
+
import { getCycleParser } from '../dpParser/cycle';
|
|
5
|
+
export function useCycleDp() {
|
|
6
|
+
let dpCode = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : scheduleDpCodes.CYCLE_TIMING;
|
|
7
|
+
const {
|
|
8
|
+
dpValue,
|
|
9
|
+
updateDp
|
|
10
|
+
} = useBaseLightDp(dpCode);
|
|
11
|
+
const cycleParser = getCycleParser();
|
|
12
|
+
const _dpValue = useMemo(() => {
|
|
13
|
+
return cycleParser.parser(dpValue);
|
|
14
|
+
}, [dpValue]);
|
|
15
|
+
return {
|
|
16
|
+
dpValue: _dpValue,
|
|
17
|
+
updateDp: dpData => {
|
|
18
|
+
updateDp(cycleParser.formatter(dpData));
|
|
19
|
+
}
|
|
20
|
+
};
|
|
21
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @description: 判断是否支持循环定时
|
|
3
|
+
* @param dpCodeList: dpCode 列表 string[]
|
|
4
|
+
* @return {
|
|
5
|
+
* isReady: boolean,
|
|
6
|
+
* isSupport: boolean
|
|
7
|
+
* }
|
|
8
|
+
*/
|
|
9
|
+
export declare const useCycleSupport: (dpCodeList?: string[]) => {
|
|
10
|
+
isReady: boolean;
|
|
11
|
+
isSupport: boolean;
|
|
12
|
+
};
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { scheduleDpCodes } from '../config/dpCodes';
|
|
2
|
+
import { useCommonSupport } from './useCommonSupport';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* @description: 判断是否支持循环定时
|
|
6
|
+
* @param dpCodeList: dpCode 列表 string[]
|
|
7
|
+
* @return {
|
|
8
|
+
* isReady: boolean,
|
|
9
|
+
* isSupport: boolean
|
|
10
|
+
* }
|
|
11
|
+
*/
|
|
12
|
+
export const useCycleSupport = function () {
|
|
13
|
+
let dpCodeList = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : [];
|
|
14
|
+
const support = useCommonSupport([scheduleDpCodes.CYCLE_TIMING], dpCodeList);
|
|
15
|
+
return support;
|
|
16
|
+
};
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { useMemo } from 'react';
|
|
2
|
+
import { useBaseLightDp } from './useBaseLightDp';
|
|
3
|
+
import { scheduleDpCodes } from '../config/dpCodes';
|
|
4
|
+
import { getRandomParser } from '../dpParser/random';
|
|
5
|
+
export function useRandomDp() {
|
|
6
|
+
let dpCode = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : scheduleDpCodes.RANDOM_TIMING;
|
|
7
|
+
const {
|
|
8
|
+
dpValue,
|
|
9
|
+
updateDp
|
|
10
|
+
} = useBaseLightDp(dpCode);
|
|
11
|
+
const randomParser = getRandomParser();
|
|
12
|
+
const _dpValue = useMemo(() => {
|
|
13
|
+
return randomParser.parser(dpValue);
|
|
14
|
+
}, [dpValue]);
|
|
15
|
+
return {
|
|
16
|
+
dpValue: _dpValue,
|
|
17
|
+
updateDp: dpData => {
|
|
18
|
+
updateDp(randomParser.formatter(dpData));
|
|
19
|
+
}
|
|
20
|
+
};
|
|
21
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @description: 判断是否支持随机定时(灯光看家)
|
|
3
|
+
* @param dpCodeList: 倒计时 dpCode 列表 string[]
|
|
4
|
+
* @return {
|
|
5
|
+
* isReady: boolean,
|
|
6
|
+
* isSupport: boolean
|
|
7
|
+
* }
|
|
8
|
+
*/
|
|
9
|
+
export declare const useRandomSupport: (dpCodeList?: string[]) => {
|
|
10
|
+
isReady: boolean;
|
|
11
|
+
isSupport: boolean;
|
|
12
|
+
};
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { scheduleDpCodes } from '../config/dpCodes';
|
|
2
|
+
import { useCommonSupport } from './useCommonSupport';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* @description: 判断是否支持随机定时(灯光看家)
|
|
6
|
+
* @param dpCodeList: 倒计时 dpCode 列表 string[]
|
|
7
|
+
* @return {
|
|
8
|
+
* isReady: boolean,
|
|
9
|
+
* isSupport: boolean
|
|
10
|
+
* }
|
|
11
|
+
*/
|
|
12
|
+
export const useRandomSupport = function () {
|
|
13
|
+
let dpCodeList = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : [];
|
|
14
|
+
const support = useCommonSupport([scheduleDpCodes.RANDOM_TIMING], dpCodeList);
|
|
15
|
+
return support;
|
|
16
|
+
};
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { useMemo } from 'react';
|
|
2
|
+
import { useBaseLightDp } from './useBaseLightDp';
|
|
3
|
+
import { scheduleDpCodes } from '../config/dpCodes';
|
|
4
|
+
import { rhythmParser } from '../dpParser/rhythms';
|
|
5
|
+
export function useRhythmsDp() {
|
|
6
|
+
let dpCode = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : scheduleDpCodes.RHYTHM_MODE;
|
|
7
|
+
const {
|
|
8
|
+
dpValue,
|
|
9
|
+
updateDp
|
|
10
|
+
} = useBaseLightDp(dpCode);
|
|
11
|
+
const _dpValue = useMemo(() => {
|
|
12
|
+
if (typeof dpValue === 'string') {
|
|
13
|
+
return rhythmParser.parser(dpValue);
|
|
14
|
+
}
|
|
15
|
+
return dpValue;
|
|
16
|
+
}, [dpValue]);
|
|
17
|
+
return {
|
|
18
|
+
dpValue: _dpValue,
|
|
19
|
+
updateDp: dpData => {
|
|
20
|
+
updateDp(rhythmParser.formatter(dpData));
|
|
21
|
+
}
|
|
22
|
+
};
|
|
23
|
+
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { useMemo } from 'react';
|
|
2
|
+
import { useBaseLightDp } from './useBaseLightDp';
|
|
3
|
+
import { scheduleDpCodes } from '../config/dpCodes';
|
|
4
|
+
import { getSleepParser } from '../dpParser/sleep';
|
|
5
|
+
export function useSleepDp() {
|
|
6
|
+
let dpCode = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : scheduleDpCodes.SLEEP_MODE;
|
|
7
|
+
const {
|
|
8
|
+
dpValue,
|
|
9
|
+
updateDp
|
|
10
|
+
} = useBaseLightDp(dpCode);
|
|
11
|
+
const sleepParser = getSleepParser();
|
|
12
|
+
const _dpValue = useMemo(() => {
|
|
13
|
+
return sleepParser.parser(dpValue);
|
|
14
|
+
}, [dpValue]);
|
|
15
|
+
return {
|
|
16
|
+
dpValue: _dpValue,
|
|
17
|
+
updateDp: dpData => {
|
|
18
|
+
updateDp(sleepParser.formatter(dpData));
|
|
19
|
+
}
|
|
20
|
+
};
|
|
21
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { scheduleDpCodes } from '../config/dpCodes';
|
|
2
|
+
import { useCommonSupport } from './useCommonSupport';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* @description: 判断是否入睡功能
|
|
6
|
+
* @param dpCodeList: 倒计时 dpCode 列表 string[]
|
|
7
|
+
* @return {isReady: boolean, isSupport: boolean}
|
|
8
|
+
*/
|
|
9
|
+
export const useSleepSupport = function () {
|
|
10
|
+
let dpCodeList = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : [];
|
|
11
|
+
const support = useCommonSupport([scheduleDpCodes.SLEEP_MODE], dpCodeList);
|
|
12
|
+
return support;
|
|
13
|
+
};
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { IContext } from '../context/timer/type';
|
|
2
|
+
import { TTimerData } from '../types';
|
|
3
|
+
export declare const useTimerContext: () => IContext;
|
|
4
|
+
export { useCloudTimerListFlush } from '../hooks/useTimerFlushList';
|
|
5
|
+
export declare const useTimerListFlush: () => {
|
|
6
|
+
isReady: boolean;
|
|
7
|
+
flushTimerList: (data: TTimerData[]) => void;
|
|
8
|
+
};
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
/* eslint-disable @typescript-eslint/explicit-module-boundary-types */
|
|
2
|
+
import { useContext, useCallback } from 'react';
|
|
3
|
+
import { TimerContext } from '../context/timer/context';
|
|
4
|
+
import { useSupportLocalTimer } from './useTimerSupport';
|
|
5
|
+
export const useTimerContext = () => {
|
|
6
|
+
return useContext(TimerContext);
|
|
7
|
+
};
|
|
8
|
+
export { useCloudTimerListFlush } from '../hooks/useTimerFlushList';
|
|
9
|
+
|
|
10
|
+
// 获取定时刷新, 内部判断云定时或本地定时
|
|
11
|
+
export const useTimerListFlush = () => {
|
|
12
|
+
const {
|
|
13
|
+
isSupport,
|
|
14
|
+
isReady
|
|
15
|
+
} = useSupportLocalTimer();
|
|
16
|
+
const {
|
|
17
|
+
actions,
|
|
18
|
+
dispatch
|
|
19
|
+
} = useTimerContext();
|
|
20
|
+
const flushTimerList = useCallback(data => {
|
|
21
|
+
if (isSupport) {
|
|
22
|
+
dispatch(actions.flushRtcTimerList(data));
|
|
23
|
+
} else {
|
|
24
|
+
dispatch(actions.flushCloudTimerList(data));
|
|
25
|
+
}
|
|
26
|
+
}, [actions, dispatch, isSupport, isReady]);
|
|
27
|
+
return {
|
|
28
|
+
isReady,
|
|
29
|
+
flushTimerList
|
|
30
|
+
};
|
|
31
|
+
};
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
/* eslint-disable no-param-reassign */
|
|
2
|
+
import { useMemo } from 'react';
|
|
3
|
+
import { useBaseLightDp } from './useBaseLightDp';
|
|
4
|
+
import { scheduleDpCodes } from '../config/dpCodes';
|
|
5
|
+
import { rtcTimerParser } from '../dpParser/rtcTimer';
|
|
6
|
+
// 本地定时dp下发
|
|
7
|
+
export function useTimerDp() {
|
|
8
|
+
let dpCode = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : scheduleDpCodes.RTC_TIMER;
|
|
9
|
+
const {
|
|
10
|
+
dpValue,
|
|
11
|
+
updateDp
|
|
12
|
+
} = useBaseLightDp(dpCode);
|
|
13
|
+
const _dpValue = useMemo(() => {
|
|
14
|
+
if (typeof dpValue === 'string') {
|
|
15
|
+
return rtcTimerParser.parser(dpValue);
|
|
16
|
+
}
|
|
17
|
+
return dpValue;
|
|
18
|
+
}, [dpValue, rtcTimerParser]);
|
|
19
|
+
return {
|
|
20
|
+
dpValue: _dpValue,
|
|
21
|
+
updateDp: rtcTimerDp => {
|
|
22
|
+
updateDp(rtcTimerParser.formatter(rtcTimerDp));
|
|
23
|
+
}
|
|
24
|
+
};
|
|
25
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { TTimerData, TTimerDataUpdate } from '../types';
|
|
2
|
+
export declare const useCloudTimerListFlush: () => {
|
|
3
|
+
flushCloudTimerList: (data: TTimerDataUpdate[]) => void;
|
|
4
|
+
};
|
|
5
|
+
export declare const useRtcTimerListFlush: () => {
|
|
6
|
+
flushRtcTimerList: (data: TTimerData[]) => void;
|
|
7
|
+
};
|
|
8
|
+
export declare const useTimerListFlush: () => {
|
|
9
|
+
isReady: boolean;
|
|
10
|
+
flushTimerList: (data: TTimerData[]) => void;
|
|
11
|
+
};
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import { useCallback } from 'react';
|
|
2
|
+
import { useTimerContext } from '../context/timer/context';
|
|
3
|
+
import { useSupportLocalTimer } from './useTimerSupport';
|
|
4
|
+
// 获取云定时刷新
|
|
5
|
+
export const useCloudTimerListFlush = () => {
|
|
6
|
+
const {
|
|
7
|
+
actions,
|
|
8
|
+
dispatch
|
|
9
|
+
} = useTimerContext();
|
|
10
|
+
const flushCloudTimerList = useCallback(data => {
|
|
11
|
+
dispatch(actions.flushCloudTimerList(data));
|
|
12
|
+
}, [actions, dispatch]);
|
|
13
|
+
return {
|
|
14
|
+
flushCloudTimerList
|
|
15
|
+
};
|
|
16
|
+
};
|
|
17
|
+
|
|
18
|
+
// 获取本地定时刷新
|
|
19
|
+
export const useRtcTimerListFlush = () => {
|
|
20
|
+
const {
|
|
21
|
+
actions,
|
|
22
|
+
dispatch
|
|
23
|
+
} = useTimerContext();
|
|
24
|
+
const flushRtcTimerList = useCallback(data => {
|
|
25
|
+
dispatch(actions.flushRtcTimerList(data));
|
|
26
|
+
}, [actions, dispatch]);
|
|
27
|
+
return {
|
|
28
|
+
flushRtcTimerList
|
|
29
|
+
};
|
|
30
|
+
};
|
|
31
|
+
|
|
32
|
+
// 获取定时刷新, 内部判断云定时或本地定时
|
|
33
|
+
export const useTimerListFlush = () => {
|
|
34
|
+
const {
|
|
35
|
+
isSupport,
|
|
36
|
+
isReady
|
|
37
|
+
} = useSupportLocalTimer();
|
|
38
|
+
const {
|
|
39
|
+
actions,
|
|
40
|
+
dispatch
|
|
41
|
+
} = useTimerContext();
|
|
42
|
+
const flushTimerList = useCallback(data => {
|
|
43
|
+
if (isSupport) {
|
|
44
|
+
dispatch(actions.flushRtcTimerList(data));
|
|
45
|
+
} else {
|
|
46
|
+
dispatch(actions.flushCloudTimerList(data));
|
|
47
|
+
}
|
|
48
|
+
}, [actions, dispatch, isSupport, isReady]);
|
|
49
|
+
return {
|
|
50
|
+
isReady,
|
|
51
|
+
flushTimerList
|
|
52
|
+
};
|
|
53
|
+
};
|