@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,233 @@
|
|
|
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.for-each.js";
|
|
4
|
+
/* eslint-disable @typescript-eslint/ban-types */
|
|
5
|
+
/**
|
|
6
|
+
* 包含定时的增删改查
|
|
7
|
+
*/
|
|
8
|
+
import { useCallback, useState } from 'react';
|
|
9
|
+
import { device } from '@ray-js/ray';
|
|
10
|
+
import { scheduleLogger as ScheduleLogger } from '../utils/ScheduleLogger';
|
|
11
|
+
import { getDpIdByDpCode } from '../utils/ScheduleUtils';
|
|
12
|
+
import { devIdOrGroupIdCache } from '../utils/ScheduleCache';
|
|
13
|
+
import { CLOUD_TIMER_CATEGORY } from '../constant';
|
|
14
|
+
const {
|
|
15
|
+
addTimer: addTimerTTT,
|
|
16
|
+
removeTimer: removeTimerTTT,
|
|
17
|
+
updateTimer: updateTimerTTT,
|
|
18
|
+
syncTimerTask: syncTimerTaskTTT,
|
|
19
|
+
updateTimerStatus: updateTimerStatusTTT
|
|
20
|
+
} = device;
|
|
21
|
+
export const useCloudTimerAdd = isSupportLocalTimer => {
|
|
22
|
+
const [isLoading, setIsLoading] = useState(false);
|
|
23
|
+
const {
|
|
24
|
+
devId,
|
|
25
|
+
groupId
|
|
26
|
+
} = devIdOrGroupIdCache.get();
|
|
27
|
+
const addTimer = useCallback(function (timer) {
|
|
28
|
+
let category = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : CLOUD_TIMER_CATEGORY;
|
|
29
|
+
return new Promise((resolve, reject) => {
|
|
30
|
+
const _dps = {};
|
|
31
|
+
Object.keys(timer.dps).forEach(i => {
|
|
32
|
+
const dpVal = timer.dps[i];
|
|
33
|
+
// eslint-disable-next-line no-self-compare
|
|
34
|
+
if (+i !== +i) {
|
|
35
|
+
// 不为数字
|
|
36
|
+
const dpId = getDpIdByDpCode(i);
|
|
37
|
+
if (dpVal !== undefined && dpId !== undefined) {
|
|
38
|
+
_dps[dpId] = dpVal;
|
|
39
|
+
}
|
|
40
|
+
} else {
|
|
41
|
+
_dps[+i] = dpVal;
|
|
42
|
+
}
|
|
43
|
+
});
|
|
44
|
+
const params = {
|
|
45
|
+
category,
|
|
46
|
+
timer: _objectSpread(_objectSpread({}, timer), {}, {
|
|
47
|
+
dps: _dps,
|
|
48
|
+
time: timer.time
|
|
49
|
+
}),
|
|
50
|
+
success: info => {
|
|
51
|
+
setIsLoading(false);
|
|
52
|
+
resolve(_objectSpread({
|
|
53
|
+
timerId: info.timerId || info.id
|
|
54
|
+
}, params.timer));
|
|
55
|
+
ScheduleLogger.debug('useCloudTimerAdd success:', info);
|
|
56
|
+
},
|
|
57
|
+
fail: error => {
|
|
58
|
+
setIsLoading(false);
|
|
59
|
+
reject(error);
|
|
60
|
+
ScheduleLogger.error('useCloudTimerAdd fail:', error);
|
|
61
|
+
}
|
|
62
|
+
};
|
|
63
|
+
if (groupId) {
|
|
64
|
+
params.groupId = groupId;
|
|
65
|
+
} else if (devId) {
|
|
66
|
+
params.deviceId = devId;
|
|
67
|
+
}
|
|
68
|
+
ScheduleLogger.debug('useCloudTimerAdd params:', params);
|
|
69
|
+
setIsLoading(true);
|
|
70
|
+
addTimerTTT(params);
|
|
71
|
+
});
|
|
72
|
+
}, [isSupportLocalTimer]);
|
|
73
|
+
return {
|
|
74
|
+
isLoading,
|
|
75
|
+
isSupportLocalTimer,
|
|
76
|
+
addTimer
|
|
77
|
+
};
|
|
78
|
+
};
|
|
79
|
+
export const useCloudTimerUpdate = isSupportLocalTimer => {
|
|
80
|
+
const [isLoading, setIsLoading] = useState(false);
|
|
81
|
+
const {
|
|
82
|
+
devId,
|
|
83
|
+
groupId
|
|
84
|
+
} = devIdOrGroupIdCache.get();
|
|
85
|
+
const updateTimer = useCallback(timer => {
|
|
86
|
+
return new Promise((resolve, reject) => {
|
|
87
|
+
const params = {
|
|
88
|
+
timer: _objectSpread(_objectSpread({}, timer), {}, {
|
|
89
|
+
time: timer.time
|
|
90
|
+
})
|
|
91
|
+
};
|
|
92
|
+
if (groupId) {
|
|
93
|
+
params.groupId = groupId;
|
|
94
|
+
} else if (devId) {
|
|
95
|
+
params.deviceId = devId;
|
|
96
|
+
}
|
|
97
|
+
ScheduleLogger.debug('useCloudTimerUpdate updateTimer params:', params);
|
|
98
|
+
setIsLoading(true);
|
|
99
|
+
updateTimerTTT(_objectSpread(_objectSpread({}, params), {}, {
|
|
100
|
+
success: info => {
|
|
101
|
+
setIsLoading(false);
|
|
102
|
+
resolve(true);
|
|
103
|
+
ScheduleLogger.debug('useCloudTimerUpdate updateTimer success:', info);
|
|
104
|
+
},
|
|
105
|
+
fail: error => {
|
|
106
|
+
setIsLoading(false);
|
|
107
|
+
reject(error);
|
|
108
|
+
ScheduleLogger.error('useCloudTimerUpdate addTimer fail:', error);
|
|
109
|
+
}
|
|
110
|
+
}));
|
|
111
|
+
});
|
|
112
|
+
}, []);
|
|
113
|
+
return {
|
|
114
|
+
isLoading,
|
|
115
|
+
isSupportLocalTimer,
|
|
116
|
+
updateTimer
|
|
117
|
+
};
|
|
118
|
+
};
|
|
119
|
+
export const useCloudTimerRemove = isSupportLocalTimer => {
|
|
120
|
+
const [isLoading, setIsLoading] = useState(false);
|
|
121
|
+
const {
|
|
122
|
+
devId,
|
|
123
|
+
groupId
|
|
124
|
+
} = devIdOrGroupIdCache.get();
|
|
125
|
+
const removeTimer = useCallback(timerId => {
|
|
126
|
+
return new Promise((resolve, reject) => {
|
|
127
|
+
setIsLoading(true);
|
|
128
|
+
const params = {
|
|
129
|
+
timerId
|
|
130
|
+
};
|
|
131
|
+
if (groupId) {
|
|
132
|
+
params.groupId = groupId;
|
|
133
|
+
} else if (devId) {
|
|
134
|
+
params.deviceId = devId;
|
|
135
|
+
}
|
|
136
|
+
ScheduleLogger.debug('useCloudTimerRemove removeTimer params:', params);
|
|
137
|
+
removeTimerTTT(_objectSpread(_objectSpread({}, params), {}, {
|
|
138
|
+
success: () => {
|
|
139
|
+
resolve(true);
|
|
140
|
+
ScheduleLogger.debug('useCloudTimerRemove removeTimer success');
|
|
141
|
+
},
|
|
142
|
+
fail: error => {
|
|
143
|
+
reject(error);
|
|
144
|
+
ScheduleLogger.error('useCloudTimerRemove removeTimer fail:', error);
|
|
145
|
+
}
|
|
146
|
+
}));
|
|
147
|
+
});
|
|
148
|
+
}, []);
|
|
149
|
+
return {
|
|
150
|
+
isLoading,
|
|
151
|
+
isSupportLocalTimer,
|
|
152
|
+
removeTimer
|
|
153
|
+
};
|
|
154
|
+
};
|
|
155
|
+
export const useCloudTimerList = isSupportLocalTimer => {
|
|
156
|
+
const [isLoading, setIsLoading] = useState(false);
|
|
157
|
+
const getTimerList = useCallback(function () {
|
|
158
|
+
let category = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : CLOUD_TIMER_CATEGORY;
|
|
159
|
+
setIsLoading(true);
|
|
160
|
+
const params = {
|
|
161
|
+
category
|
|
162
|
+
};
|
|
163
|
+
const {
|
|
164
|
+
devId,
|
|
165
|
+
groupId
|
|
166
|
+
} = devIdOrGroupIdCache.get();
|
|
167
|
+
if (groupId) {
|
|
168
|
+
params.groupId = groupId;
|
|
169
|
+
} else if (devId) {
|
|
170
|
+
params.deviceId = devId;
|
|
171
|
+
}
|
|
172
|
+
return new Promise((resolve, reject) => {
|
|
173
|
+
syncTimerTaskTTT(_objectSpread(_objectSpread({}, params), {}, {
|
|
174
|
+
success: info => {
|
|
175
|
+
setIsLoading(false);
|
|
176
|
+
ScheduleLogger.debug('useCloudTimerList success:', info);
|
|
177
|
+
resolve(info);
|
|
178
|
+
},
|
|
179
|
+
fail: error => {
|
|
180
|
+
setIsLoading(false);
|
|
181
|
+
ScheduleLogger.error('useCloudTimerList fail:', error);
|
|
182
|
+
reject(error);
|
|
183
|
+
}
|
|
184
|
+
}));
|
|
185
|
+
});
|
|
186
|
+
}, []);
|
|
187
|
+
return {
|
|
188
|
+
isLoading,
|
|
189
|
+
isSupportLocalTimer,
|
|
190
|
+
getTimerList
|
|
191
|
+
};
|
|
192
|
+
};
|
|
193
|
+
/**
|
|
194
|
+
* 更新定时开关状态
|
|
195
|
+
*/
|
|
196
|
+
export const useCloudTimerUpdateStatus = isSupportLocalTimer => {
|
|
197
|
+
const [isLoading, setIsLoading] = useState(false);
|
|
198
|
+
const updateTimerStatus = useCallback((timerId, status) => {
|
|
199
|
+
return new Promise((resolve, reject) => {
|
|
200
|
+
setIsLoading(true);
|
|
201
|
+
const params = {
|
|
202
|
+
timerId,
|
|
203
|
+
status
|
|
204
|
+
};
|
|
205
|
+
const {
|
|
206
|
+
devId,
|
|
207
|
+
groupId
|
|
208
|
+
} = devIdOrGroupIdCache.get();
|
|
209
|
+
if (groupId) {
|
|
210
|
+
params.groupId = groupId;
|
|
211
|
+
} else if (devId) {
|
|
212
|
+
params.deviceId = devId;
|
|
213
|
+
}
|
|
214
|
+
updateTimerStatusTTT(_objectSpread(_objectSpread({}, params), {}, {
|
|
215
|
+
success: () => {
|
|
216
|
+
setIsLoading(false);
|
|
217
|
+
resolve(true);
|
|
218
|
+
ScheduleLogger.debug('useCloudTimerUpdateStatus success');
|
|
219
|
+
},
|
|
220
|
+
fail: error => {
|
|
221
|
+
setIsLoading(false);
|
|
222
|
+
reject(error);
|
|
223
|
+
ScheduleLogger.error('useCloudTimerUpdateStatus fail:', error);
|
|
224
|
+
}
|
|
225
|
+
}));
|
|
226
|
+
});
|
|
227
|
+
}, []);
|
|
228
|
+
return {
|
|
229
|
+
isLoading,
|
|
230
|
+
isSupportLocalTimer,
|
|
231
|
+
updateTimerStatus
|
|
232
|
+
};
|
|
233
|
+
};
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 包含定时的增删改查
|
|
3
|
+
*/
|
|
4
|
+
import { Dispatch } from 'react';
|
|
5
|
+
import { TTimerDataUpdate, TTimerData, TTimerDataAdd } from '../types';
|
|
6
|
+
import { TActions } from '../context/timer/type';
|
|
7
|
+
export declare const useLocalTimerAdd: (isSupportLocalTimer: boolean) => {
|
|
8
|
+
isLoading: boolean;
|
|
9
|
+
isSupportLocalTimer: boolean;
|
|
10
|
+
addTimer: (timer: TTimerDataAdd) => Promise<boolean>;
|
|
11
|
+
};
|
|
12
|
+
export declare const useLocalTimerUpdate: (isSupportLocalTimer: boolean) => {
|
|
13
|
+
isLoading: boolean;
|
|
14
|
+
isSupportLocalTimer: boolean;
|
|
15
|
+
updateTimer: (data: TTimerDataUpdate) => Promise<boolean>;
|
|
16
|
+
};
|
|
17
|
+
export declare const useLocalTimerRemove: (isSupportLocalTimer: boolean) => {
|
|
18
|
+
isLoading: boolean;
|
|
19
|
+
isSupportLocalTimer: boolean;
|
|
20
|
+
removeTimer: (timerId: string) => Promise<boolean>;
|
|
21
|
+
};
|
|
22
|
+
/**
|
|
23
|
+
* 获取本地定时器列表并刷新 context
|
|
24
|
+
*/
|
|
25
|
+
export declare const getTimerListWithFlush: (dispatch: Dispatch<any>, actions: TActions) => Promise<void>;
|
|
26
|
+
export declare const useLocalTimerList: (isSupportLocalTimer: boolean) => {
|
|
27
|
+
isLoading: boolean;
|
|
28
|
+
isSupportLocalTimer: boolean;
|
|
29
|
+
getTimerList: () => Promise<{
|
|
30
|
+
timers: TTimerData[];
|
|
31
|
+
}>;
|
|
32
|
+
};
|
|
33
|
+
/**
|
|
34
|
+
* 更新本地定时开关状态
|
|
35
|
+
*/
|
|
36
|
+
export declare const useLocalTimerUpdateStatus: (isSupportLocalTimer: boolean) => {
|
|
37
|
+
isLoading: boolean;
|
|
38
|
+
isSupportLocalTimer: boolean;
|
|
39
|
+
updateTimerStatus: (timerId: string, status: boolean) => Promise<boolean>;
|
|
40
|
+
};
|
|
@@ -0,0 +1,310 @@
|
|
|
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.filter.js";
|
|
4
|
+
import "core-js/modules/esnext.iterator.find.js";
|
|
5
|
+
import "core-js/modules/esnext.iterator.map.js";
|
|
6
|
+
/* eslint-disable @typescript-eslint/no-unused-vars */
|
|
7
|
+
/* eslint-disable @typescript-eslint/ban-types */
|
|
8
|
+
/* eslint-disable @typescript-eslint/explicit-module-boundary-types */
|
|
9
|
+
/**
|
|
10
|
+
* 包含定时的增删改查
|
|
11
|
+
*/
|
|
12
|
+
import { useCallback, useState, useEffect } from 'react';
|
|
13
|
+
import { offDpDataChange, onDpDataChange } from '@ray-js/ray';
|
|
14
|
+
import { devIdOrGroupIdCache } from '../utils/ScheduleCache';
|
|
15
|
+
import { scheduleLogger as ScheduleLogger } from '../utils/ScheduleLogger';
|
|
16
|
+
import { LOCAL_TIMER_CATEGORY } from '../constant';
|
|
17
|
+
import { getAll, useLocalTimerCloudProperty } from '../utils/ScheduleCloudProperty';
|
|
18
|
+
import { getTimerState, getTimerReducer } from '../context/timer';
|
|
19
|
+
import { timerReportParser } from '../dpParser';
|
|
20
|
+
|
|
21
|
+
// 添加本地定时
|
|
22
|
+
export const useLocalTimerAdd = isSupportLocalTimer => {
|
|
23
|
+
const [isLoading, setIsLoading] = useState(false);
|
|
24
|
+
const {
|
|
25
|
+
set
|
|
26
|
+
} = useLocalTimerCloudProperty();
|
|
27
|
+
const addTimer = useCallback((timer, timerId) => {
|
|
28
|
+
return new Promise((resolve, reject) => {
|
|
29
|
+
ScheduleLogger.debug('useLocalTimerAdd addTimer params:', timer);
|
|
30
|
+
setIsLoading(true);
|
|
31
|
+
set(timer, timerId).then(() => {
|
|
32
|
+
ScheduleLogger.debug('useLocalTimerAdd set success:', timer);
|
|
33
|
+
resolve(true);
|
|
34
|
+
}).catch(error => {
|
|
35
|
+
ScheduleLogger.debug('useLocalTimerAdd set fail:', error);
|
|
36
|
+
reject(error);
|
|
37
|
+
}).finally(() => {
|
|
38
|
+
setIsLoading(false);
|
|
39
|
+
});
|
|
40
|
+
});
|
|
41
|
+
}, []);
|
|
42
|
+
return {
|
|
43
|
+
isLoading,
|
|
44
|
+
addTimer,
|
|
45
|
+
isSupportLocalTimer
|
|
46
|
+
};
|
|
47
|
+
};
|
|
48
|
+
|
|
49
|
+
// 更新本地定时
|
|
50
|
+
export const useLocalTimerUpdate = isSupportLocalTimer => {
|
|
51
|
+
const [isLoading, setIsLoading] = useState(false);
|
|
52
|
+
const {
|
|
53
|
+
devId,
|
|
54
|
+
groupId
|
|
55
|
+
} = devIdOrGroupIdCache.get();
|
|
56
|
+
const {
|
|
57
|
+
update
|
|
58
|
+
} = useLocalTimerCloudProperty();
|
|
59
|
+
const updateTimer = useCallback(timer => {
|
|
60
|
+
return new Promise((resolve, reject) => {
|
|
61
|
+
const params = {
|
|
62
|
+
timer
|
|
63
|
+
};
|
|
64
|
+
if (groupId) {
|
|
65
|
+
params.groupId = groupId;
|
|
66
|
+
} else if (devId) {
|
|
67
|
+
params.deviceId = devId;
|
|
68
|
+
}
|
|
69
|
+
ScheduleLogger.debug('updateTimer params:', params);
|
|
70
|
+
setIsLoading(true);
|
|
71
|
+
update(timer).then(() => {
|
|
72
|
+
resolve(true);
|
|
73
|
+
}).catch(error => {
|
|
74
|
+
reject(error);
|
|
75
|
+
});
|
|
76
|
+
});
|
|
77
|
+
}, [update]);
|
|
78
|
+
return {
|
|
79
|
+
isSupportLocalTimer,
|
|
80
|
+
isLoading,
|
|
81
|
+
updateTimer
|
|
82
|
+
};
|
|
83
|
+
};
|
|
84
|
+
|
|
85
|
+
// 删除本地定时器
|
|
86
|
+
export const useLocalTimerRemove = isSupportLocalTimer => {
|
|
87
|
+
const [isLoading, setIsLoading] = useState(false);
|
|
88
|
+
const {
|
|
89
|
+
remove
|
|
90
|
+
} = useLocalTimerCloudProperty();
|
|
91
|
+
const removeTimer = useCallback(timerId => {
|
|
92
|
+
return new Promise((resolve, reject) => {
|
|
93
|
+
setIsLoading(true);
|
|
94
|
+
remove(timerId).then(() => {
|
|
95
|
+
resolve(true);
|
|
96
|
+
}).catch(err => {
|
|
97
|
+
reject(err);
|
|
98
|
+
});
|
|
99
|
+
});
|
|
100
|
+
}, []);
|
|
101
|
+
return {
|
|
102
|
+
isSupportLocalTimer,
|
|
103
|
+
isLoading,
|
|
104
|
+
removeTimer
|
|
105
|
+
};
|
|
106
|
+
};
|
|
107
|
+
const getTimerList = () => {
|
|
108
|
+
return new Promise((resolve, reject) => {
|
|
109
|
+
getAll().then(res => {
|
|
110
|
+
ScheduleLogger.debug('useLocalTimerList getAll res:', res);
|
|
111
|
+
const {
|
|
112
|
+
properties = {}
|
|
113
|
+
} = res;
|
|
114
|
+
const localTimerList = Object.entries(properties || {}).filter(_ref => {
|
|
115
|
+
let [key] = _ref;
|
|
116
|
+
return key.startsWith(LOCAL_TIMER_CATEGORY);
|
|
117
|
+
});
|
|
118
|
+
const validLocalTimerList = localTimerList.filter(_ref2 => {
|
|
119
|
+
let [_, value] = _ref2;
|
|
120
|
+
let v = value;
|
|
121
|
+
try {
|
|
122
|
+
if (value === '1') {
|
|
123
|
+
return false;
|
|
124
|
+
}
|
|
125
|
+
if (value === 'null') {
|
|
126
|
+
return false;
|
|
127
|
+
}
|
|
128
|
+
v = JSON.parse(value);
|
|
129
|
+
} catch (err) {
|
|
130
|
+
return false;
|
|
131
|
+
}
|
|
132
|
+
return v.time;
|
|
133
|
+
});
|
|
134
|
+
const _localTimerList = validLocalTimerList.map(_ref3 => {
|
|
135
|
+
let [key, value] = _ref3;
|
|
136
|
+
const timerId = key.replace(`${LOCAL_TIMER_CATEGORY}_`, '');
|
|
137
|
+
const {
|
|
138
|
+
time,
|
|
139
|
+
loops,
|
|
140
|
+
status = false,
|
|
141
|
+
dps
|
|
142
|
+
} = JSON.parse(value);
|
|
143
|
+
return {
|
|
144
|
+
timerId,
|
|
145
|
+
time,
|
|
146
|
+
loops,
|
|
147
|
+
status,
|
|
148
|
+
dps,
|
|
149
|
+
// 为了跟云端数据保持一致,本地定时写死的数据
|
|
150
|
+
aliasName: '',
|
|
151
|
+
isAppPush: false
|
|
152
|
+
};
|
|
153
|
+
});
|
|
154
|
+
resolve({
|
|
155
|
+
timers: _localTimerList
|
|
156
|
+
});
|
|
157
|
+
}).catch(err => {
|
|
158
|
+
ScheduleLogger.error('useLocalTimerList getAll error:', err);
|
|
159
|
+
reject(err);
|
|
160
|
+
});
|
|
161
|
+
});
|
|
162
|
+
};
|
|
163
|
+
const flushRtcTimerList = (timerList, dispatch, actions) => {
|
|
164
|
+
dispatch(actions === null || actions === void 0 ? void 0 : actions.flushRtcTimerList(timerList));
|
|
165
|
+
};
|
|
166
|
+
|
|
167
|
+
/**
|
|
168
|
+
* 获取本地定时器列表并刷新 context
|
|
169
|
+
*/
|
|
170
|
+
export const getTimerListWithFlush = (dispatch, actions) => {
|
|
171
|
+
return getTimerList().then(res => {
|
|
172
|
+
return flushRtcTimerList(res.timers, dispatch, actions);
|
|
173
|
+
});
|
|
174
|
+
};
|
|
175
|
+
const onDpChangeFn = data => {
|
|
176
|
+
var _data$dps;
|
|
177
|
+
// 专门处理 timer_report dp 变化
|
|
178
|
+
if (data !== null && data !== void 0 && (_data$dps = data.dps) !== null && _data$dps !== void 0 && _data$dps[38]) {
|
|
179
|
+
var _data$dps2;
|
|
180
|
+
const {
|
|
181
|
+
rtcTimerList = []
|
|
182
|
+
} = getTimerState();
|
|
183
|
+
const {
|
|
184
|
+
actions,
|
|
185
|
+
dispatch
|
|
186
|
+
} = getTimerReducer();
|
|
187
|
+
const dpValue = data === null || data === void 0 || (_data$dps2 = data.dps) === null || _data$dps2 === void 0 ? void 0 : _data$dps2[38];
|
|
188
|
+
const dpParsedValue = timerReportParser.parser(dpValue);
|
|
189
|
+
const timerList = rtcTimerList.map(item => {
|
|
190
|
+
var _dpParsedValue$find$s, _dpParsedValue$find;
|
|
191
|
+
return _objectSpread(_objectSpread({}, item), {}, {
|
|
192
|
+
status: (_dpParsedValue$find$s = dpParsedValue === null || dpParsedValue === void 0 || (_dpParsedValue$find = dpParsedValue.find(i => +i.id === +item.timerId)) === null || _dpParsedValue$find === void 0 ? void 0 : _dpParsedValue$find.status) !== null && _dpParsedValue$find$s !== void 0 ? _dpParsedValue$find$s : false
|
|
193
|
+
});
|
|
194
|
+
});
|
|
195
|
+
dispatch && dispatch(actions.flushRtcTimerList(timerList));
|
|
196
|
+
}
|
|
197
|
+
};
|
|
198
|
+
|
|
199
|
+
// 获取本地定时任务列表
|
|
200
|
+
export const useLocalTimerList = isSupportLocalTimer => {
|
|
201
|
+
const [isLoading, setIsLoading] = useState(false);
|
|
202
|
+
const {
|
|
203
|
+
getAll
|
|
204
|
+
} = useLocalTimerCloudProperty();
|
|
205
|
+
useEffect(() => {
|
|
206
|
+
// 监听 dp 变化
|
|
207
|
+
// 监听 timer_report dp 变化 用来同步本地定时列表状态
|
|
208
|
+
offDpDataChange(onDpChangeFn);
|
|
209
|
+
onDpDataChange(onDpChangeFn);
|
|
210
|
+
}, []);
|
|
211
|
+
const getTimerList = useCallback(() => {
|
|
212
|
+
setIsLoading(true);
|
|
213
|
+
return new Promise((resolve, reject) => {
|
|
214
|
+
getAll().then(res => {
|
|
215
|
+
ScheduleLogger.debug('useLocalTimerList getAll res:', res);
|
|
216
|
+
const {
|
|
217
|
+
properties = {}
|
|
218
|
+
} = res;
|
|
219
|
+
const localTimerList = Object.entries(properties || {}).filter(_ref4 => {
|
|
220
|
+
let [key] = _ref4;
|
|
221
|
+
return key.startsWith(LOCAL_TIMER_CATEGORY);
|
|
222
|
+
});
|
|
223
|
+
const validLocalTimerList = localTimerList.filter(_ref5 => {
|
|
224
|
+
let [_, value] = _ref5;
|
|
225
|
+
let v = value;
|
|
226
|
+
try {
|
|
227
|
+
if (value === '1') {
|
|
228
|
+
return false;
|
|
229
|
+
}
|
|
230
|
+
if (value === 'null') {
|
|
231
|
+
return false;
|
|
232
|
+
}
|
|
233
|
+
v = JSON.parse(value);
|
|
234
|
+
} catch (err) {
|
|
235
|
+
return false;
|
|
236
|
+
}
|
|
237
|
+
return v.time;
|
|
238
|
+
});
|
|
239
|
+
const _localTimerList = validLocalTimerList.map(_ref6 => {
|
|
240
|
+
let [key, value] = _ref6;
|
|
241
|
+
const timerId = key.replace(`${LOCAL_TIMER_CATEGORY}_`, '');
|
|
242
|
+
const {
|
|
243
|
+
time,
|
|
244
|
+
loops,
|
|
245
|
+
status = false,
|
|
246
|
+
dps
|
|
247
|
+
} = JSON.parse(value);
|
|
248
|
+
return {
|
|
249
|
+
timerId,
|
|
250
|
+
time,
|
|
251
|
+
loops,
|
|
252
|
+
status,
|
|
253
|
+
dps,
|
|
254
|
+
// 为了跟云端数据保持一致,本地定时写死的数据
|
|
255
|
+
aliasName: '',
|
|
256
|
+
isAppPush: false
|
|
257
|
+
};
|
|
258
|
+
});
|
|
259
|
+
resolve({
|
|
260
|
+
timers: _localTimerList
|
|
261
|
+
});
|
|
262
|
+
}).catch(err => {
|
|
263
|
+
ScheduleLogger.error('useLocalTimerList getAll error:', err);
|
|
264
|
+
reject(err);
|
|
265
|
+
});
|
|
266
|
+
});
|
|
267
|
+
}, []);
|
|
268
|
+
return {
|
|
269
|
+
isLoading,
|
|
270
|
+
isSupportLocalTimer,
|
|
271
|
+
getTimerList
|
|
272
|
+
};
|
|
273
|
+
};
|
|
274
|
+
|
|
275
|
+
/**
|
|
276
|
+
* 更新本地定时开关状态
|
|
277
|
+
*/
|
|
278
|
+
export const useLocalTimerUpdateStatus = isSupportLocalTimer => {
|
|
279
|
+
const [isLoading, setIsLoading] = useState(false);
|
|
280
|
+
const {
|
|
281
|
+
updateStatus
|
|
282
|
+
} = useLocalTimerCloudProperty();
|
|
283
|
+
const updateTimerStatus = useCallback((timerId, status) => {
|
|
284
|
+
return new Promise((resolve, reject) => {
|
|
285
|
+
setIsLoading(true);
|
|
286
|
+
const {
|
|
287
|
+
rtcTimerList = []
|
|
288
|
+
} = getTimerState();
|
|
289
|
+
const currentTimer = rtcTimerList.find(i => i.timerId === timerId);
|
|
290
|
+
if (!currentTimer) {
|
|
291
|
+
ScheduleLogger.warn(`useLocalTimerUpdateStatus: currentTimer with timerId ${timerId} is undefined`);
|
|
292
|
+
return;
|
|
293
|
+
}
|
|
294
|
+
updateStatus(timerId, status).then(() => {
|
|
295
|
+
ScheduleLogger.debug('updateTimerStatus success');
|
|
296
|
+
setIsLoading(false);
|
|
297
|
+
resolve(true);
|
|
298
|
+
}).catch(error => {
|
|
299
|
+
ScheduleLogger.error('updateTimerStatus fail:', error);
|
|
300
|
+
setIsLoading(false);
|
|
301
|
+
reject(error);
|
|
302
|
+
});
|
|
303
|
+
});
|
|
304
|
+
}, [updateStatus]);
|
|
305
|
+
return {
|
|
306
|
+
isLoading,
|
|
307
|
+
isSupportLocalTimer,
|
|
308
|
+
updateTimerStatus
|
|
309
|
+
};
|
|
310
|
+
};
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { TTimerReport } from '../types';
|
|
2
|
+
export declare function useTimerReportDp(dpCode?: "timer_report"): {
|
|
3
|
+
dpValue: TTimerReport[];
|
|
4
|
+
isSupport: boolean;
|
|
5
|
+
updateDp: (dps: TTimerReport[]) => void;
|
|
6
|
+
};
|
|
7
|
+
/**
|
|
8
|
+
* 主动拉取定时 timer_report dp 数据
|
|
9
|
+
* 由于本地定时数据不会主动上报,所以需要主动拉取用来同步定时数据
|
|
10
|
+
* @param timerReport 定时上报 dpCode
|
|
11
|
+
* @returns refresh 刷新 dp 数据
|
|
12
|
+
*/
|
|
13
|
+
export declare const useTimerReportDpPull: (timerReport?: "timer_report") => {
|
|
14
|
+
refresh: () => void;
|
|
15
|
+
};
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
/* eslint-disable no-param-reassign */
|
|
2
|
+
import { useMemo } from 'react';
|
|
3
|
+
import { useBaseLightDp, useFetchDpDataByMesh } from './useBaseLightDp';
|
|
4
|
+
import { scheduleDpCodes } from '../config/dpCodes';
|
|
5
|
+
import { scheduleLogger as ScheduleLogger } from '../utils/ScheduleLogger';
|
|
6
|
+
import { timerReportParser } from '../dpParser';
|
|
7
|
+
import { useSupport } from './useCommonSupport';
|
|
8
|
+
|
|
9
|
+
// sigmesh 本地定时状态 dp
|
|
10
|
+
export function useTimerReportDp() {
|
|
11
|
+
let dpCode = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : scheduleDpCodes.TIMER_REPORT;
|
|
12
|
+
const support = useSupport();
|
|
13
|
+
const {
|
|
14
|
+
dpValue,
|
|
15
|
+
updateDp
|
|
16
|
+
} = useBaseLightDp(dpCode);
|
|
17
|
+
const _dpValue = useMemo(() => {
|
|
18
|
+
if (typeof dpValue === 'string') {
|
|
19
|
+
return timerReportParser.parser(dpValue);
|
|
20
|
+
}
|
|
21
|
+
return dpValue;
|
|
22
|
+
}, [dpValue, timerReportParser]);
|
|
23
|
+
const isSupport = support.isSupportDp(scheduleDpCodes.TIMER_REPORT);
|
|
24
|
+
return {
|
|
25
|
+
isSupport,
|
|
26
|
+
dpValue: _dpValue,
|
|
27
|
+
updateDp: timerReportDp => {
|
|
28
|
+
updateDp(timerReportParser.formatter(timerReportDp));
|
|
29
|
+
}
|
|
30
|
+
};
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
/**
|
|
34
|
+
* 主动拉取定时 timer_report dp 数据
|
|
35
|
+
* 由于本地定时数据不会主动上报,所以需要主动拉取用来同步定时数据
|
|
36
|
+
* @param timerReport 定时上报 dpCode
|
|
37
|
+
* @returns refresh 刷新 dp 数据
|
|
38
|
+
*/
|
|
39
|
+
export const useTimerReportDpPull = function () {
|
|
40
|
+
let timerReport = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : scheduleDpCodes.TIMER_REPORT;
|
|
41
|
+
ScheduleLogger.debug('useTimerReportDpPull 执行');
|
|
42
|
+
const {
|
|
43
|
+
refresh
|
|
44
|
+
} = useFetchDpDataByMesh([timerReport]);
|
|
45
|
+
return {
|
|
46
|
+
refresh
|
|
47
|
+
};
|
|
48
|
+
};
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @description: 判断是否支持倒计时功能
|
|
3
|
+
* @param dpCodeList: 倒计时 dpCode 列表 string[]
|
|
4
|
+
* @return {isReady: boolean, isSupport: boolean}
|
|
5
|
+
*/
|
|
6
|
+
export declare const useSupportLocalTimer: (dpCodeList?: string[]) => {
|
|
7
|
+
isReady: boolean;
|
|
8
|
+
isSupport: boolean;
|
|
9
|
+
};
|
|
10
|
+
export declare const useSupportCloudTimer: () => boolean;
|
|
11
|
+
export declare const useTimerSupport: () => {
|
|
12
|
+
isSupport: boolean;
|
|
13
|
+
};
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import { useEffect, useState } from 'react';
|
|
2
|
+
import { scheduleDpCodes } from '../config/dpCodes';
|
|
3
|
+
import { useCommonSupport, useSupport } from './useCommonSupport';
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* @description: 判断是否支持倒计时功能
|
|
7
|
+
* @param dpCodeList: 倒计时 dpCode 列表 string[]
|
|
8
|
+
* @return {isReady: boolean, isSupport: boolean}
|
|
9
|
+
*/
|
|
10
|
+
export const useSupportLocalTimer = function () {
|
|
11
|
+
let dpCodeList = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : [];
|
|
12
|
+
const _dpCodeList = [scheduleDpCodes.LOCAL_TIMER, scheduleDpCodes.RTC_TIMER, scheduleDpCodes.STRIP_LOCAL_TIMER];
|
|
13
|
+
const supportIns = useSupport();
|
|
14
|
+
const isGroup = !!(supportIns !== null && supportIns !== void 0 && supportIns.isGroupDevice());
|
|
15
|
+
const support = useCommonSupport(_dpCodeList, dpCodeList);
|
|
16
|
+
return {
|
|
17
|
+
isReady: support.isReady,
|
|
18
|
+
isSupport: support.isSupport && !isGroup
|
|
19
|
+
};
|
|
20
|
+
};
|
|
21
|
+
export const useSupportCloudTimer = () => {
|
|
22
|
+
const support = useSupport();
|
|
23
|
+
const [isSupportCloudTimer, setIsSupportCloudTimer] = useState(false);
|
|
24
|
+
useEffect(() => {
|
|
25
|
+
const isSupportCloudTimer = support.isSupportCloudTimer();
|
|
26
|
+
setIsSupportCloudTimer(isSupportCloudTimer);
|
|
27
|
+
}, [support]);
|
|
28
|
+
return isSupportCloudTimer;
|
|
29
|
+
};
|
|
30
|
+
export const useTimerSupport = () => {
|
|
31
|
+
const {
|
|
32
|
+
isSupport: isSupportLocalTimer
|
|
33
|
+
} = useSupportLocalTimer();
|
|
34
|
+
const isSupportCloudTimer = useSupportCloudTimer();
|
|
35
|
+
return {
|
|
36
|
+
isSupport: isSupportLocalTimer || isSupportCloudTimer
|
|
37
|
+
};
|
|
38
|
+
};
|