@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,101 @@
|
|
|
1
|
+
// /* eslint-disable no-console */
|
|
2
|
+
// import { generateDpStrStep, numToHexString } from '@ray-js/panel-sdk/lib/utils';
|
|
3
|
+
// import { padEnd } from 'lodash-es';
|
|
4
|
+
|
|
5
|
+
// import { TSleepDataSigmesh, TSleepNodeSigmesh } from '../../types';
|
|
6
|
+
// import { isInIDEFun } from '../../utils/isInIDE';
|
|
7
|
+
|
|
8
|
+
// export class SleepSigmesh {
|
|
9
|
+
// defaultValue: TSleepDataSigmesh = {
|
|
10
|
+
// version: 0,
|
|
11
|
+
// dataMode: '01',
|
|
12
|
+
// length: 0,
|
|
13
|
+
// nodes: [],
|
|
14
|
+
// };
|
|
15
|
+
|
|
16
|
+
// parser(dpStr: string) {
|
|
17
|
+
// if (!dpStr) {
|
|
18
|
+
// return this.defaultValue;
|
|
19
|
+
// }
|
|
20
|
+
// if (dpStr.slice(6).length % 8 !== 0) {
|
|
21
|
+
// return this.defaultValue;
|
|
22
|
+
// }
|
|
23
|
+
// const step = generateDpStrStep(dpStr);
|
|
24
|
+
|
|
25
|
+
// const version = step(2).value; // 版本号
|
|
26
|
+
// const dataMode = step(2).value; // 参数模式 0x01:仅含BT 0x02:仅含HSV 0x03:含HSVBT
|
|
27
|
+
// const length = step(2).value; // 任务节点数 0x01:1 个节点 0x02:2 个节点 0x03:3 个节点 0x04:4 个节点
|
|
28
|
+
// const nodes: TSleepNodeSigmesh[] = [];
|
|
29
|
+
|
|
30
|
+
// // 解析循环节点数据
|
|
31
|
+
// for (let i = 0; i < length; i++) {
|
|
32
|
+
// const onOff = !!step(2).value;
|
|
33
|
+
// const loopNum = step(2).value;
|
|
34
|
+
// const loops = padEnd(loopNum?.toString(2)?.split('').reverse().join(''), 7, '0');
|
|
35
|
+
// const stepGrad = step(2).value;
|
|
36
|
+
// const hour = step(2).value;
|
|
37
|
+
// const minute = step(2).value;
|
|
38
|
+
// const brightness = step(2).value;
|
|
39
|
+
// const temperature = step(2).value;
|
|
40
|
+
// const duration = step(2).value;
|
|
41
|
+
|
|
42
|
+
// const node = {
|
|
43
|
+
// onOff, // 任务开关
|
|
44
|
+
// loops, // 日期设定
|
|
45
|
+
// step: stepGrad, // 渐变步进值
|
|
46
|
+
// hour, // 起始小时
|
|
47
|
+
// minute, // 起始分钟
|
|
48
|
+
// brightness, // 亮度百分比
|
|
49
|
+
// temperature, // 色温百分比
|
|
50
|
+
// duration, // 持续时间 0 - 24, 对应 0-120 => 5分钟一个步进
|
|
51
|
+
// index: i,
|
|
52
|
+
// };
|
|
53
|
+
// nodes.push(node);
|
|
54
|
+
// }
|
|
55
|
+
|
|
56
|
+
// return {
|
|
57
|
+
// version,
|
|
58
|
+
// dataMode,
|
|
59
|
+
// length,
|
|
60
|
+
// nodes,
|
|
61
|
+
// };
|
|
62
|
+
// }
|
|
63
|
+
|
|
64
|
+
// formatter(data: TSleepDataSigmesh) {
|
|
65
|
+
// const result = [
|
|
66
|
+
// numToHexString(data.version),
|
|
67
|
+
// numToHexString(data.dataMode === '01' ? 1 : data.dataMode === '02' ? 2 : 3),
|
|
68
|
+
// numToHexString(data.length),
|
|
69
|
+
// ];
|
|
70
|
+
|
|
71
|
+
// data.nodes.forEach(node => {
|
|
72
|
+
// result.push(
|
|
73
|
+
// numToHexString(node.onOff ? 1 : 0),
|
|
74
|
+
// numToHexString(parseInt(node?.loops?.split('')?.reverse()?.join(''), 2)),
|
|
75
|
+
// numToHexString(node.step),
|
|
76
|
+
// numToHexString(node.hour),
|
|
77
|
+
// numToHexString(node.minute),
|
|
78
|
+
// numToHexString(node.brightness),
|
|
79
|
+
// numToHexString(node.temperature)
|
|
80
|
+
// );
|
|
81
|
+
// });
|
|
82
|
+
|
|
83
|
+
// return result.join('');
|
|
84
|
+
// }
|
|
85
|
+
// }
|
|
86
|
+
|
|
87
|
+
// export const sleepParserSigmesh: {
|
|
88
|
+
// parser: (dpValue: string) => TSleepDataSigmesh;
|
|
89
|
+
// formatter: (dpData: TSleepDataSigmesh) => string;
|
|
90
|
+
// } = new SleepSigmesh();
|
|
91
|
+
|
|
92
|
+
// // 使用示例
|
|
93
|
+
// // if (isInIDEFun()) {
|
|
94
|
+
// // const dpStr = '01020301020304050607080102030405060708';
|
|
95
|
+
// // const result = sleepParserSigmesh.parser(dpStr);
|
|
96
|
+
// // const formatted = sleepParserSigmesh.formatter(result);
|
|
97
|
+
// // console.warn(formatted, 'formattedformatted1');
|
|
98
|
+
// // if (dpStr !== formatted) {
|
|
99
|
+
// // throw new Error('sleepParserSigmesh dp 转换失败, 请检查');
|
|
100
|
+
// // }
|
|
101
|
+
// // }
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { TTimerReport } from '../types';
|
|
2
|
+
export declare class TimerReportFormatter {
|
|
3
|
+
defaultValue: TTimerReport[];
|
|
4
|
+
constructor();
|
|
5
|
+
parser(val?: string): TTimerReport[];
|
|
6
|
+
formatter(tasks: TTimerReport[]): string;
|
|
7
|
+
}
|
|
8
|
+
export declare const timerReportParser: {
|
|
9
|
+
parser: (dpValue: string) => Record<string, any>;
|
|
10
|
+
formatter: (data: Record<string, any>) => string;
|
|
11
|
+
};
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import "core-js/modules/esnext.iterator.constructor.js";
|
|
2
|
+
import "core-js/modules/esnext.iterator.for-each.js";
|
|
3
|
+
import "core-js/modules/esnext.iterator.map.js";
|
|
4
|
+
import _padStart from 'lodash/padStart';
|
|
5
|
+
// 补充工具函数
|
|
6
|
+
const numToHexString = function () {
|
|
7
|
+
let value = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 0;
|
|
8
|
+
let digit = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 2;
|
|
9
|
+
const hex = value.toString(16);
|
|
10
|
+
return hex.padStart(digit, '0');
|
|
11
|
+
};
|
|
12
|
+
export class TimerReportFormatter {
|
|
13
|
+
constructor() {
|
|
14
|
+
this.defaultValue = [];
|
|
15
|
+
}
|
|
16
|
+
parser() {
|
|
17
|
+
let val = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : '';
|
|
18
|
+
if (val) {
|
|
19
|
+
const arr = [];
|
|
20
|
+
const strArr = val.match(/[a-z0-9]{2}/g);
|
|
21
|
+
strArr.forEach(item => {
|
|
22
|
+
const binaryStr = _padStart(parseInt(item, 16).toString(2), 8, '0');
|
|
23
|
+
arr.push({
|
|
24
|
+
status: binaryStr.slice(0, 1) === '1',
|
|
25
|
+
id: parseInt(binaryStr.slice(4), 2)
|
|
26
|
+
});
|
|
27
|
+
});
|
|
28
|
+
return arr;
|
|
29
|
+
}
|
|
30
|
+
return this.defaultValue;
|
|
31
|
+
}
|
|
32
|
+
formatter(tasks) {
|
|
33
|
+
return tasks.map(task => {
|
|
34
|
+
// 组装ABBBBBBB
|
|
35
|
+
const binStr = (task.status ? '1' : '0') +
|
|
36
|
+
// A位
|
|
37
|
+
(+task.id).toString(2).padStart(7, '0'); // BBBBBBB
|
|
38
|
+
const hexStr = numToHexString(parseInt(binStr, 2));
|
|
39
|
+
return hexStr;
|
|
40
|
+
}).join('');
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
export const timerReportParser = new TimerReportFormatter();
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 10进制数转16进制字符串
|
|
3
|
+
* @param value 10进制数
|
|
4
|
+
* @returns 16进制字符串
|
|
5
|
+
*/
|
|
6
|
+
export declare const numToHexPad2: (value?: number) => string;
|
|
7
|
+
/**
|
|
8
|
+
* 10进制数转16进制字符串 转换出的字符长度为4
|
|
9
|
+
* @param value 10进制数
|
|
10
|
+
* @returns 16进制字符串
|
|
11
|
+
*/
|
|
12
|
+
export declare const numToHexPad4: (value?: number) => string;
|
|
13
|
+
/**
|
|
14
|
+
* 10进制转2进制字符串
|
|
15
|
+
* @param decimal 10进制数
|
|
16
|
+
* @param bitLen 转换出的2进制字符串长度
|
|
17
|
+
* @returns 2进制字符串
|
|
18
|
+
*/
|
|
19
|
+
export declare const numToBinStrPad: (decimal: number, bitLen: number) => string;
|
|
20
|
+
/** 10进制转2进制字符串 长度为8 位 */
|
|
21
|
+
export declare const numToBinStrPad8: (decimal: number) => string;
|
|
22
|
+
/** 10进制转2进制字符串 长度为16位 */
|
|
23
|
+
export declare const numToBinStrPad16: (decimal: number) => string;
|
|
24
|
+
/** 转化为number */
|
|
25
|
+
export declare const toNum: (n: number | string) => number;
|
|
26
|
+
/** 16进制字符串转10进制数字 */
|
|
27
|
+
export declare const hexToNum: (str?: string) => number;
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import { numToHexString } from '@ray-js/panel-sdk/lib/utils';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* 10进制数转16进制字符串
|
|
5
|
+
* @param value 10进制数
|
|
6
|
+
* @returns 16进制字符串
|
|
7
|
+
*/
|
|
8
|
+
export const numToHexPad2 = function () {
|
|
9
|
+
let value = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 0;
|
|
10
|
+
return numToHexString(value || 0, 2);
|
|
11
|
+
};
|
|
12
|
+
/**
|
|
13
|
+
* 10进制数转16进制字符串 转换出的字符长度为4
|
|
14
|
+
* @param value 10进制数
|
|
15
|
+
* @returns 16进制字符串
|
|
16
|
+
*/
|
|
17
|
+
export const numToHexPad4 = function () {
|
|
18
|
+
let value = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 0;
|
|
19
|
+
return numToHexString(value || 0, 4);
|
|
20
|
+
};
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* 10进制转2进制字符串
|
|
24
|
+
* @param decimal 10进制数
|
|
25
|
+
* @param bitLen 转换出的2进制字符串长度
|
|
26
|
+
* @returns 2进制字符串
|
|
27
|
+
*/
|
|
28
|
+
export const numToBinStrPad = (decimal, bitLen) => {
|
|
29
|
+
if (decimal === 0) return '0'.padStart(bitLen, '0');
|
|
30
|
+
const binary = parseInt(`${decimal}`, 10).toString(2);
|
|
31
|
+
return binary.padStart(bitLen, '0');
|
|
32
|
+
};
|
|
33
|
+
|
|
34
|
+
/** 10进制转2进制字符串 长度为8 位 */
|
|
35
|
+
export const numToBinStrPad8 = decimal => {
|
|
36
|
+
return numToBinStrPad(decimal, 8);
|
|
37
|
+
};
|
|
38
|
+
|
|
39
|
+
/** 10进制转2进制字符串 长度为16位 */
|
|
40
|
+
export const numToBinStrPad16 = decimal => {
|
|
41
|
+
return numToBinStrPad(decimal, 16);
|
|
42
|
+
};
|
|
43
|
+
|
|
44
|
+
/** 转化为number */
|
|
45
|
+
export const toNum = n => {
|
|
46
|
+
return +n || 0;
|
|
47
|
+
};
|
|
48
|
+
|
|
49
|
+
/** 16进制字符串转10进制数字 */
|
|
50
|
+
export const hexToNum = function () {
|
|
51
|
+
let str = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : '';
|
|
52
|
+
return parseInt(str, 16) || 0;
|
|
53
|
+
};
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { Support } from '../../utils/ScheduleSupport';
|
|
2
|
+
export { wakeupParser as wakeupParserCommon, WakeUp as WakeUpCommon } from './wakeupCommon';
|
|
3
|
+
export { wakeupParserSigmesh, WakeUpSigmesh } from './wakeupSigmesh';
|
|
4
|
+
import { TWakeUpDataSigmesh, TWakeUpData } from '../../types';
|
|
5
|
+
export declare class WakeUpParser {
|
|
6
|
+
support: Support;
|
|
7
|
+
parser(dpStr: string): TWakeUpData | TWakeUpDataSigmesh;
|
|
8
|
+
formatter(dpData: TWakeUpDataSigmesh | TWakeUpData): string;
|
|
9
|
+
}
|
|
10
|
+
export declare const getWakeUpParser: () => WakeUpParser;
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
// import { getSupportIns } from '../../hooks/useCommonSupport';
|
|
2
|
+
|
|
3
|
+
export { wakeupParser as wakeupParserCommon, WakeUp as WakeUpCommon } from './wakeupCommon';
|
|
4
|
+
export { wakeupParserSigmesh, WakeUpSigmesh } from './wakeupSigmesh';
|
|
5
|
+
import { wakeupParser as wakeupParserCommon } from './wakeupCommon';
|
|
6
|
+
// import { wakeupParserSigmesh } from './wakeupSigmesh';
|
|
7
|
+
|
|
8
|
+
export class WakeUpParser {
|
|
9
|
+
parser(dpStr) {
|
|
10
|
+
// FIXME: 暂时不支持 Sigmesh 设备
|
|
11
|
+
// const support = getSupportIns();
|
|
12
|
+
// const isSigmesh = support.isSigMeshDevice();
|
|
13
|
+
// if (isSigmesh) {
|
|
14
|
+
// return wakeupParserSigmesh.parser(dpStr) as TWakeUpDataSigmesh;
|
|
15
|
+
// }
|
|
16
|
+
return wakeupParserCommon.parser(dpStr);
|
|
17
|
+
}
|
|
18
|
+
formatter(dpData) {
|
|
19
|
+
// FIXME: 暂时不支持 Sigmesh 设备
|
|
20
|
+
// const support = getSupportIns();
|
|
21
|
+
// const isSigmesh = support.isSigMeshDevice();
|
|
22
|
+
// if (isSigmesh) {
|
|
23
|
+
// return wakeupParserSigmesh.formatter(dpData as TWakeUpDataSigmesh);
|
|
24
|
+
// }
|
|
25
|
+
return wakeupParserCommon.formatter(dpData);
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
let wakeupParser = null;
|
|
29
|
+
export const getWakeUpParser = () => {
|
|
30
|
+
if (!wakeupParser) {
|
|
31
|
+
wakeupParser = new WakeUpParser();
|
|
32
|
+
}
|
|
33
|
+
return wakeupParser;
|
|
34
|
+
};
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { TWakeUpData, TWakeUpNode } from '../../types';
|
|
2
|
+
export declare class WakeUp {
|
|
3
|
+
defaultValue: TWakeUpData;
|
|
4
|
+
parser(dpStr: string): TWakeUpData | {
|
|
5
|
+
version: any;
|
|
6
|
+
number: 4;
|
|
7
|
+
nodes: TWakeUpNode[];
|
|
8
|
+
};
|
|
9
|
+
formatter(data: TWakeUpData): string;
|
|
10
|
+
}
|
|
11
|
+
export declare const wakeupParser: WakeUp;
|
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
import "core-js/modules/esnext.iterator.constructor.js";
|
|
2
|
+
import "core-js/modules/esnext.iterator.for-each.js";
|
|
3
|
+
import { generateDpStrStep, numToHexString } from '@ray-js/panel-sdk/lib/utils';
|
|
4
|
+
import { padEnd } from 'lodash-es';
|
|
5
|
+
import { scheduleLogger } from '../../utils/ScheduleLogger';
|
|
6
|
+
const defaultColor = {
|
|
7
|
+
hue: 0,
|
|
8
|
+
saturation: 0,
|
|
9
|
+
value: 0,
|
|
10
|
+
brightness: 0,
|
|
11
|
+
temperature: 0
|
|
12
|
+
};
|
|
13
|
+
export class WakeUp {
|
|
14
|
+
defaultValue = {
|
|
15
|
+
version: 0,
|
|
16
|
+
number: 0,
|
|
17
|
+
nodes: []
|
|
18
|
+
};
|
|
19
|
+
parser(dpStr) {
|
|
20
|
+
var _dpStr$slice;
|
|
21
|
+
scheduleLogger.debug('WakeUp parser dpStr: ', dpStr);
|
|
22
|
+
if (!dpStr) {
|
|
23
|
+
return this.defaultValue;
|
|
24
|
+
}
|
|
25
|
+
const step = generateDpStrStep(dpStr);
|
|
26
|
+
const version = step(2).value;
|
|
27
|
+
let number = step(2).value;
|
|
28
|
+
const nodeLen = (_dpStr$slice = dpStr.slice(4)) === null || _dpStr$slice === void 0 ? void 0 : _dpStr$slice.length;
|
|
29
|
+
if (nodeLen % 24 !== 0) {
|
|
30
|
+
scheduleLogger.error('wakeup dpStr error nodeLen:', nodeLen);
|
|
31
|
+
}
|
|
32
|
+
const nodes = [];
|
|
33
|
+
number = Math.min(number, 4);
|
|
34
|
+
// 解析循环节点
|
|
35
|
+
for (let i = 0; i < number; i++) {
|
|
36
|
+
const onOff = !!step(2).value;
|
|
37
|
+
const repeatInt = step(2).value; // 单次定时任务bit0-bit6全为0,bit0-bit6某位为1时,表示对应周几周期定时 bit0 => 周日
|
|
38
|
+
const loops = padEnd(repeatInt.toString(2).split('').reverse().join(''), 7, '0');
|
|
39
|
+
const stepNum = step(2).value;
|
|
40
|
+
const hour = step(2).value;
|
|
41
|
+
const minute = step(2).value;
|
|
42
|
+
|
|
43
|
+
// 解析色相值(组合百位和十个位)
|
|
44
|
+
const hundreds = step(2).value;
|
|
45
|
+
const tensOnes = step(2).value;
|
|
46
|
+
const saturation = step(2).value;
|
|
47
|
+
const val = step(2).value;
|
|
48
|
+
const brightness = step(2).value;
|
|
49
|
+
const temperature = step(2).value;
|
|
50
|
+
const durationStep = step(2);
|
|
51
|
+
const duration = durationStep.value;
|
|
52
|
+
nodes.push({
|
|
53
|
+
onOff,
|
|
54
|
+
loops,
|
|
55
|
+
step: stepNum,
|
|
56
|
+
hour,
|
|
57
|
+
minute,
|
|
58
|
+
hue: Math.round(hundreds * 100 + tensOnes),
|
|
59
|
+
// 0-360
|
|
60
|
+
saturation,
|
|
61
|
+
value: val,
|
|
62
|
+
brightness,
|
|
63
|
+
temperature,
|
|
64
|
+
duration,
|
|
65
|
+
index: i
|
|
66
|
+
});
|
|
67
|
+
if (durationStep.done) {
|
|
68
|
+
break;
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
return {
|
|
72
|
+
version,
|
|
73
|
+
number,
|
|
74
|
+
nodes
|
|
75
|
+
};
|
|
76
|
+
}
|
|
77
|
+
formatter(data) {
|
|
78
|
+
var _data$nodes, _data$nodes2;
|
|
79
|
+
const result = [numToHexString(data.version), numToHexString((_data$nodes = data.nodes) === null || _data$nodes === void 0 ? void 0 : _data$nodes.length)];
|
|
80
|
+
scheduleLogger.debug('wakeup formatter data', data);
|
|
81
|
+
data === null || data === void 0 || (_data$nodes2 = data.nodes) === null || _data$nodes2 === void 0 || _data$nodes2.forEach(node => {
|
|
82
|
+
// 拆分色相值为百位和十个位
|
|
83
|
+
const hueHundreds = Math.floor(node.hue / 100);
|
|
84
|
+
const hueTensOnes = node.hue % 100;
|
|
85
|
+
const {
|
|
86
|
+
saturation,
|
|
87
|
+
value,
|
|
88
|
+
brightness,
|
|
89
|
+
temperature
|
|
90
|
+
} = node;
|
|
91
|
+
let saturation1 = node.saturation;
|
|
92
|
+
let value1 = node.value;
|
|
93
|
+
let brightness1 = node.brightness;
|
|
94
|
+
let temperature1 = node.temperature;
|
|
95
|
+
if (saturation === 0 && value === 0 && brightness === 0 && temperature === 0) {
|
|
96
|
+
saturation1 = defaultColor.saturation;
|
|
97
|
+
value1 = defaultColor.value;
|
|
98
|
+
brightness1 = defaultColor.brightness;
|
|
99
|
+
temperature1 = defaultColor.temperature;
|
|
100
|
+
}
|
|
101
|
+
result.push(numToHexString(node.onOff ? 1 : 0), numToHexString(parseInt(node.loops.split('').reverse().join(''), 2), 2), numToHexString(node.step), numToHexString(node.hour), numToHexString(node.minute), numToHexString(hueHundreds), numToHexString(hueTensOnes), numToHexString(saturation1), numToHexString(value1), numToHexString(brightness1), numToHexString(temperature1), numToHexString(node.duration));
|
|
102
|
+
});
|
|
103
|
+
return result.join('');
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
export const wakeupParser = new WakeUp();
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { TWakeUpDataSigmesh, TWakeUpNodeSigmesh } from '../../types';
|
|
2
|
+
export declare class WakeUpSigmesh {
|
|
3
|
+
defaultValue: TWakeUpDataSigmesh;
|
|
4
|
+
parser(dpStr: string): {
|
|
5
|
+
version: any;
|
|
6
|
+
dataMode: any;
|
|
7
|
+
length: any;
|
|
8
|
+
nodes: TWakeUpNodeSigmesh[];
|
|
9
|
+
};
|
|
10
|
+
formatter(data: TWakeUpDataSigmesh): string;
|
|
11
|
+
}
|
|
12
|
+
export declare const wakeupParserSigmesh: {
|
|
13
|
+
parser: (dpValue: string) => TWakeUpDataSigmesh;
|
|
14
|
+
formatter: (dpData: TWakeUpDataSigmesh) => string;
|
|
15
|
+
};
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
import "core-js/modules/esnext.iterator.constructor.js";
|
|
2
|
+
import "core-js/modules/esnext.iterator.for-each.js";
|
|
3
|
+
/* eslint-disable no-console */
|
|
4
|
+
import { generateDpStrStep, numToHexString } from '@ray-js/panel-sdk/lib/utils';
|
|
5
|
+
import { padEnd } from 'lodash-es';
|
|
6
|
+
export class WakeUpSigmesh {
|
|
7
|
+
defaultValue = {
|
|
8
|
+
version: 0,
|
|
9
|
+
dataMode: '01',
|
|
10
|
+
length: 0,
|
|
11
|
+
nodes: []
|
|
12
|
+
};
|
|
13
|
+
parser(dpStr) {
|
|
14
|
+
if (!dpStr) {
|
|
15
|
+
return this.defaultValue;
|
|
16
|
+
}
|
|
17
|
+
if (dpStr.slice(6).length % 8 !== 0) {
|
|
18
|
+
return this.defaultValue;
|
|
19
|
+
}
|
|
20
|
+
const step = generateDpStrStep(dpStr);
|
|
21
|
+
const version = step(2).value; // 版本号
|
|
22
|
+
const dataMode = step(2).value; // 参数模式 0x01:仅含BT 0x02:仅含HSV 0x03:含HSVBT
|
|
23
|
+
const length = step(2).value; // 任务节点数 0x01:1 个节点 0x02:2 个节点 0x03:3 个节点 0x04:4 个节点
|
|
24
|
+
const nodes = [];
|
|
25
|
+
|
|
26
|
+
// 解析循环节点数据
|
|
27
|
+
for (let i = 0; i < length; i++) {
|
|
28
|
+
var _loopNum$toString;
|
|
29
|
+
const onOff = !!step(2).value;
|
|
30
|
+
const loopNum = step(2).value;
|
|
31
|
+
const loops = padEnd(loopNum === null || loopNum === void 0 || (_loopNum$toString = loopNum.toString(2)) === null || _loopNum$toString === void 0 ? void 0 : _loopNum$toString.split('').reverse().join(''), 7, '0');
|
|
32
|
+
const stepGrad = step(2).value;
|
|
33
|
+
const hour = step(2).value;
|
|
34
|
+
const minute = step(2).value;
|
|
35
|
+
const brightness = step(2).value;
|
|
36
|
+
const temperature = step(2).value;
|
|
37
|
+
const duration = step(2).value;
|
|
38
|
+
const node = {
|
|
39
|
+
onOff,
|
|
40
|
+
// 任务开关
|
|
41
|
+
loops,
|
|
42
|
+
// 日期设定
|
|
43
|
+
step: stepGrad,
|
|
44
|
+
// 渐变步进值
|
|
45
|
+
hour,
|
|
46
|
+
// 起始小时
|
|
47
|
+
minute,
|
|
48
|
+
// 起始分钟
|
|
49
|
+
brightness,
|
|
50
|
+
// 亮度百分比
|
|
51
|
+
temperature,
|
|
52
|
+
// 色温百分比
|
|
53
|
+
duration,
|
|
54
|
+
// 持续时间 0 - 24, 对应 0-120 => 5分钟一个步进
|
|
55
|
+
index: i
|
|
56
|
+
};
|
|
57
|
+
nodes.push(node);
|
|
58
|
+
}
|
|
59
|
+
return {
|
|
60
|
+
version,
|
|
61
|
+
dataMode,
|
|
62
|
+
length,
|
|
63
|
+
nodes
|
|
64
|
+
};
|
|
65
|
+
}
|
|
66
|
+
formatter(data) {
|
|
67
|
+
const result = [numToHexString(data.version), numToHexString(data.dataMode === '01' ? 1 : data.dataMode === '02' ? 2 : 3), numToHexString(data.length)];
|
|
68
|
+
data.nodes.forEach(node => {
|
|
69
|
+
var _node$loops;
|
|
70
|
+
result.push(numToHexString(node.onOff ? 1 : 0), numToHexString(parseInt(node === null || node === void 0 || (_node$loops = node.loops) === null || _node$loops === void 0 || (_node$loops = _node$loops.split('')) === null || _node$loops === void 0 || (_node$loops = _node$loops.reverse()) === null || _node$loops === void 0 ? void 0 : _node$loops.join(''), 2)), numToHexString(node.step), numToHexString(node.hour), numToHexString(node.minute), numToHexString(node.brightness), numToHexString(node.temperature), numToHexString(node.duration));
|
|
71
|
+
});
|
|
72
|
+
return result.join('');
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
export const wakeupParserSigmesh = new WakeUpSigmesh();
|
|
76
|
+
|
|
77
|
+
// 使用示例
|
|
78
|
+
// if (isInIDEFun()) {
|
|
79
|
+
// const dpStr = '01020301020304050607080102030405060708';
|
|
80
|
+
// const result = wakeupParserSigmesh.parser(dpStr);
|
|
81
|
+
// const formatted = wakeupParserSigmesh.formatter(result);
|
|
82
|
+
// console.warn(formatted, 'formattedformatted1');
|
|
83
|
+
// if (dpStr !== formatted) {
|
|
84
|
+
// throw new Error('wakeupParserSigmesh dp 转换失败, 请检查');
|
|
85
|
+
// }
|
|
86
|
+
// }
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
import { renderHook } from '@testing-library/react-hooks';
|
|
2
|
+
import { hideMenuButton } from '@ray-js/ray';
|
|
3
|
+
import { useHourType, useSafeArea, useLanguage, useIsIOS, useHideMenu } from '../useCommon';
|
|
4
|
+
|
|
5
|
+
// Mock @ray-js/ray
|
|
6
|
+
jest.mock('@ray-js/ray', () => ({
|
|
7
|
+
getStorage: jest.fn(),
|
|
8
|
+
setStorage: jest.fn(),
|
|
9
|
+
hideMenuButton: jest.fn(),
|
|
10
|
+
showMenuButton: jest.fn()
|
|
11
|
+
}));
|
|
12
|
+
|
|
13
|
+
// Mock window.localStorage
|
|
14
|
+
const localStorageMock = (() => {
|
|
15
|
+
let store = {};
|
|
16
|
+
return {
|
|
17
|
+
getItem: jest.fn(key => store[key] || null),
|
|
18
|
+
setItem: jest.fn((key, value) => {
|
|
19
|
+
store[key] = value;
|
|
20
|
+
}),
|
|
21
|
+
clear: jest.fn(() => {
|
|
22
|
+
store = {};
|
|
23
|
+
})
|
|
24
|
+
};
|
|
25
|
+
})();
|
|
26
|
+
Object.defineProperty(window, 'localStorage', {
|
|
27
|
+
value: localStorageMock
|
|
28
|
+
});
|
|
29
|
+
describe('useCommon Hooks', () => {
|
|
30
|
+
beforeEach(() => {
|
|
31
|
+
jest.clearAllMocks();
|
|
32
|
+
localStorageMock.clear();
|
|
33
|
+
});
|
|
34
|
+
describe('useHourType', () => {
|
|
35
|
+
it('should return correct hour type', () => {
|
|
36
|
+
const {
|
|
37
|
+
result
|
|
38
|
+
} = renderHook(() => useHourType());
|
|
39
|
+
expect(result.current).toHaveProperty('is12Hour');
|
|
40
|
+
});
|
|
41
|
+
});
|
|
42
|
+
describe('useSafeArea', () => {
|
|
43
|
+
it('should return safe area height', () => {
|
|
44
|
+
const {
|
|
45
|
+
result
|
|
46
|
+
} = renderHook(() => useSafeArea());
|
|
47
|
+
expect(typeof result.current).toBe('number');
|
|
48
|
+
});
|
|
49
|
+
});
|
|
50
|
+
describe('useLanguage', () => {
|
|
51
|
+
it('should return language', () => {
|
|
52
|
+
const {
|
|
53
|
+
result
|
|
54
|
+
} = renderHook(() => useLanguage());
|
|
55
|
+
expect(typeof result.current).toBe('string');
|
|
56
|
+
});
|
|
57
|
+
});
|
|
58
|
+
describe('useIsIOS', () => {
|
|
59
|
+
it('should return boolean indicating if device is iOS', () => {
|
|
60
|
+
const {
|
|
61
|
+
result
|
|
62
|
+
} = renderHook(() => useIsIOS());
|
|
63
|
+
expect(typeof result.current).toBe('boolean');
|
|
64
|
+
});
|
|
65
|
+
});
|
|
66
|
+
describe('useHideMenu', () => {
|
|
67
|
+
it('should hide menu button when isHide is true', () => {
|
|
68
|
+
renderHook(() => useHideMenu());
|
|
69
|
+
expect(hideMenuButton).toHaveBeenCalled();
|
|
70
|
+
});
|
|
71
|
+
});
|
|
72
|
+
});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
import { renderHook, act } from '@testing-library/react-hooks';
|
|
2
|
+
import { useCountdownDp, useCountdownDpPull } from '../useCountdownDp';
|
|
3
|
+
import { useBaseLightDp, useFetchDpDataByMesh } from '../useBaseLightDp';
|
|
4
|
+
import { scheduleDpCodes } from '../../config/dpCodes';
|
|
5
|
+
// Mock dependencies
|
|
6
|
+
jest.mock('../useBaseLightDp');
|
|
7
|
+
describe('useCountdownDp', () => {
|
|
8
|
+
const mockDpValue = 3600; // 1小时倒计时
|
|
9
|
+
|
|
10
|
+
beforeEach(() => {
|
|
11
|
+
jest.clearAllMocks();
|
|
12
|
+
useBaseLightDp.mockReturnValue({
|
|
13
|
+
dpValue: mockDpValue,
|
|
14
|
+
updateDp: jest.fn()
|
|
15
|
+
});
|
|
16
|
+
});
|
|
17
|
+
it('should return correct initial values', () => {
|
|
18
|
+
const {
|
|
19
|
+
result
|
|
20
|
+
} = renderHook(() => useCountdownDp());
|
|
21
|
+
expect(result.current.dpValue).toBe(mockDpValue);
|
|
22
|
+
expect(typeof result.current.updateDp).toBe('function');
|
|
23
|
+
});
|
|
24
|
+
it('should call updateDp with new value', () => {
|
|
25
|
+
const mockUpdateDp = jest.fn();
|
|
26
|
+
useBaseLightDp.mockReturnValue({
|
|
27
|
+
dpValue: mockDpValue,
|
|
28
|
+
updateDp: mockUpdateDp
|
|
29
|
+
});
|
|
30
|
+
const {
|
|
31
|
+
result
|
|
32
|
+
} = renderHook(() => useCountdownDp());
|
|
33
|
+
const newValue = 7200; // 2小时倒计时
|
|
34
|
+
|
|
35
|
+
act(() => {
|
|
36
|
+
result.current.updateDp(newValue);
|
|
37
|
+
});
|
|
38
|
+
expect(mockUpdateDp).toHaveBeenCalledWith(newValue);
|
|
39
|
+
});
|
|
40
|
+
it('should use correct dpCode', () => {
|
|
41
|
+
renderHook(() => useCountdownDp());
|
|
42
|
+
expect(useBaseLightDp).toHaveBeenCalledWith(scheduleDpCodes.COUNTDOWN);
|
|
43
|
+
});
|
|
44
|
+
it('should handle custom dpCode', () => {
|
|
45
|
+
const customDpCode = scheduleDpCodes.COUNTDOWN;
|
|
46
|
+
renderHook(() => useCountdownDp(customDpCode));
|
|
47
|
+
expect(useBaseLightDp).toHaveBeenCalledWith(customDpCode);
|
|
48
|
+
});
|
|
49
|
+
});
|
|
50
|
+
describe('useCountdownDpPull', () => {
|
|
51
|
+
const mockRefresh = jest.fn();
|
|
52
|
+
beforeEach(() => {
|
|
53
|
+
jest.clearAllMocks();
|
|
54
|
+
useFetchDpDataByMesh.mockReturnValue({
|
|
55
|
+
refresh: mockRefresh
|
|
56
|
+
});
|
|
57
|
+
});
|
|
58
|
+
it('should return refresh function', () => {
|
|
59
|
+
const {
|
|
60
|
+
result
|
|
61
|
+
} = renderHook(() => useCountdownDpPull());
|
|
62
|
+
expect(typeof result.current.refresh).toBe('function');
|
|
63
|
+
});
|
|
64
|
+
it('should call refresh when refresh function is called', () => {
|
|
65
|
+
const {
|
|
66
|
+
result
|
|
67
|
+
} = renderHook(() => useCountdownDpPull());
|
|
68
|
+
act(() => {
|
|
69
|
+
result.current.refresh();
|
|
70
|
+
});
|
|
71
|
+
expect(mockRefresh).toHaveBeenCalled();
|
|
72
|
+
});
|
|
73
|
+
it('should use correct dpCode', () => {
|
|
74
|
+
renderHook(() => useCountdownDpPull());
|
|
75
|
+
expect(useFetchDpDataByMesh).toHaveBeenCalledWith([scheduleDpCodes.COUNTDOWN]);
|
|
76
|
+
});
|
|
77
|
+
it('should handle custom dpCode', () => {
|
|
78
|
+
const customDpCode = scheduleDpCodes.COUNTDOWN;
|
|
79
|
+
renderHook(() => useCountdownDpPull(customDpCode));
|
|
80
|
+
expect(useFetchDpDataByMesh).toHaveBeenCalledWith([customDpCode]);
|
|
81
|
+
});
|
|
82
|
+
});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|