@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,116 @@
|
|
|
1
|
+
import "core-js/modules/esnext.iterator.map.js";
|
|
2
|
+
import { generateDpStrStep, numToHexString } from '@ray-js/panel-sdk/lib/utils';
|
|
3
|
+
import { padStart } from 'lodash-es';
|
|
4
|
+
import { defaultValue } from '../config/rhythms/defaultValue';
|
|
5
|
+
import { scheduleDpCodes } from '../config/dpCodes';
|
|
6
|
+
import { scheduleLogger as ScheduleLogger } from '../utils/ScheduleLogger';
|
|
7
|
+
import { getSupportIns } from '../hooks/useCommonSupport';
|
|
8
|
+
const {
|
|
9
|
+
RHYTHM_MODE,
|
|
10
|
+
TEMPERATURE
|
|
11
|
+
} = scheduleDpCodes;
|
|
12
|
+
const to16 = num => {
|
|
13
|
+
return numToHexString(num);
|
|
14
|
+
};
|
|
15
|
+
export default class RhythmFormatter {
|
|
16
|
+
constructor() {
|
|
17
|
+
let uuid = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : RHYTHM_MODE;
|
|
18
|
+
let defaultValue = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : null;
|
|
19
|
+
this.defaultValue = {};
|
|
20
|
+
this.uuid = uuid;
|
|
21
|
+
if (defaultValue) {
|
|
22
|
+
this.defaultValue = defaultValue;
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
parser() {
|
|
26
|
+
let dpValue = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : '';
|
|
27
|
+
const support = getSupportIns();
|
|
28
|
+
if (!support || !dpValue || dpValue.length <= 10 || (dpValue.length - 10) % 18 !== 0) {
|
|
29
|
+
return {
|
|
30
|
+
version: 0,
|
|
31
|
+
power: false,
|
|
32
|
+
mode: 0,
|
|
33
|
+
weeks: [1, 1, 1, 1, 1, 1, 1],
|
|
34
|
+
number: 1,
|
|
35
|
+
rhythms: defaultValue
|
|
36
|
+
};
|
|
37
|
+
}
|
|
38
|
+
const step = generateDpStrStep(dpValue);
|
|
39
|
+
const version = step().value;
|
|
40
|
+
const power = !!step().value;
|
|
41
|
+
const mode = step().value;
|
|
42
|
+
const weekNum = step().value;
|
|
43
|
+
const weeks = padStart(Number(weekNum).toString(2), 8, '0').split('').reverse().map(v => parseInt(v, 10));
|
|
44
|
+
const number = step().value;
|
|
45
|
+
const rhythms = [];
|
|
46
|
+
for (let i = 0; i < number; i++) {
|
|
47
|
+
const valid = !!step().value;
|
|
48
|
+
const hour = step().value;
|
|
49
|
+
const minute = step().value;
|
|
50
|
+
const hue1 = step().value;
|
|
51
|
+
const hue2 = step().value;
|
|
52
|
+
const saturation = step().value;
|
|
53
|
+
const v = step().value;
|
|
54
|
+
const brightness = step().value;
|
|
55
|
+
const temperature = step().value;
|
|
56
|
+
rhythms.push({
|
|
57
|
+
power: valid,
|
|
58
|
+
hour,
|
|
59
|
+
minute,
|
|
60
|
+
hue: hue1 * 100 + hue2,
|
|
61
|
+
saturation,
|
|
62
|
+
value: v,
|
|
63
|
+
brightness,
|
|
64
|
+
temperature
|
|
65
|
+
});
|
|
66
|
+
}
|
|
67
|
+
return {
|
|
68
|
+
version,
|
|
69
|
+
power,
|
|
70
|
+
mode,
|
|
71
|
+
weeks,
|
|
72
|
+
number,
|
|
73
|
+
rhythms
|
|
74
|
+
};
|
|
75
|
+
}
|
|
76
|
+
formatter(data) {
|
|
77
|
+
const support = getSupportIns();
|
|
78
|
+
if (!data || !support) {
|
|
79
|
+
ScheduleLogger.error('协议解析 rhythms formatter =====', '数据为空');
|
|
80
|
+
return '';
|
|
81
|
+
}
|
|
82
|
+
const {
|
|
83
|
+
version,
|
|
84
|
+
power,
|
|
85
|
+
mode,
|
|
86
|
+
weeks,
|
|
87
|
+
rhythms
|
|
88
|
+
} = data;
|
|
89
|
+
ScheduleLogger.debug('协议解析 rhythms formatter:', data);
|
|
90
|
+
const weekStr = [...weeks].reverse().join('').padStart(8, '0');
|
|
91
|
+
const number = rhythms.length;
|
|
92
|
+
const weeksValue = parseInt(weekStr, 2);
|
|
93
|
+
const isSupportWhiteTemp = support.isSupportDp(TEMPERATURE);
|
|
94
|
+
return `${to16(version)}${to16(Number(power))}${to16(mode)}${to16(weeksValue)}${to16(number)}${rhythms.map(_ref => {
|
|
95
|
+
let {
|
|
96
|
+
power,
|
|
97
|
+
hour,
|
|
98
|
+
minute,
|
|
99
|
+
hue,
|
|
100
|
+
saturation,
|
|
101
|
+
value: v,
|
|
102
|
+
temperature,
|
|
103
|
+
brightness
|
|
104
|
+
} = _ref;
|
|
105
|
+
const hue1 = Math.floor(hue / 100); // 百分位
|
|
106
|
+
|
|
107
|
+
// 十位与个位
|
|
108
|
+
// 不支持色温时,色温值传100
|
|
109
|
+
return `${to16(Number(power))}${to16(hour)}${to16(minute)}${to16(hue1)}${to16(hue % 100)}${to16(saturation)}${to16(v)}${to16(brightness)}${to16(isSupportWhiteTemp ? temperature : 100)}`;
|
|
110
|
+
}).join('')}`;
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
export const rhythmParser = new RhythmFormatter();
|
|
114
|
+
export const getRhythmParser = () => {
|
|
115
|
+
return rhythmParser;
|
|
116
|
+
};
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { TRtcTimer } from '../types';
|
|
2
|
+
export declare class RtcTimerFormatter {
|
|
3
|
+
defaultValue: TRtcTimer;
|
|
4
|
+
constructor(defaultValue?: null);
|
|
5
|
+
equal(source: any, target: any): boolean;
|
|
6
|
+
parser(val?: string): TRtcTimer;
|
|
7
|
+
to16(value: any, length: any): string;
|
|
8
|
+
formatter(data: TRtcTimer): string;
|
|
9
|
+
}
|
|
10
|
+
export declare const rtcTimerParser: {
|
|
11
|
+
parser: (dpValue: string) => Record<string, any>;
|
|
12
|
+
formatter: (data: TRtcTimer) => string;
|
|
13
|
+
};
|
|
14
|
+
export declare const getRtcParser: () => {
|
|
15
|
+
parser: (dpValue: string) => Record<string, any>;
|
|
16
|
+
formatter: (data: TRtcTimer) => string;
|
|
17
|
+
};
|
|
@@ -0,0 +1,300 @@
|
|
|
1
|
+
import "core-js/modules/esnext.iterator.constructor.js";
|
|
2
|
+
import "core-js/modules/esnext.iterator.for-each.js";
|
|
3
|
+
/* eslint-disable @typescript-eslint/no-unused-vars */
|
|
4
|
+
/* eslint-disable camelcase */
|
|
5
|
+
import { padEnd, padStart } from 'lodash-es';
|
|
6
|
+
import { generateDpStrStep, numToHexString } from '@ray-js/panel-sdk/lib/utils';
|
|
7
|
+
import { scheduleDpCodes } from '../config/dpCodes';
|
|
8
|
+
import { scheduleLogger as ScheduleLogger } from '../utils/ScheduleLogger';
|
|
9
|
+
import { numToBinStrPad8 } from './utils';
|
|
10
|
+
import { getDpCodeByDpId } from '../utils/ScheduleUtils';
|
|
11
|
+
const {
|
|
12
|
+
RTC_TIMER
|
|
13
|
+
} = scheduleDpCodes;
|
|
14
|
+
|
|
15
|
+
// 分钟数转 "HH:mm"
|
|
16
|
+
const minuteToTime = minute => {
|
|
17
|
+
const hour = Math.floor(minute / 60);
|
|
18
|
+
return `${padStart(hour.toString(), 2, '0')}:${padStart((minute % 60).toString(), 2, '0')}`;
|
|
19
|
+
};
|
|
20
|
+
const _defaultValue = {
|
|
21
|
+
timerId: '1',
|
|
22
|
+
status: false,
|
|
23
|
+
loops: '1111111',
|
|
24
|
+
time: '08:30',
|
|
25
|
+
dps: {
|
|
26
|
+
switch_led: false
|
|
27
|
+
}
|
|
28
|
+
};
|
|
29
|
+
var EDpCodes = /*#__PURE__*/function (EDpCodes) {
|
|
30
|
+
EDpCodes["bright_value"] = "bright_value";
|
|
31
|
+
EDpCodes["colour_data"] = "colour_data";
|
|
32
|
+
EDpCodes["temp_value"] = "temp_value";
|
|
33
|
+
EDpCodes["switch_led"] = "switch_led";
|
|
34
|
+
return EDpCodes;
|
|
35
|
+
}(EDpCodes || {});
|
|
36
|
+
export class RtcTimerFormatter {
|
|
37
|
+
constructor() {
|
|
38
|
+
let defaultValue = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : null;
|
|
39
|
+
// @ts-ignore
|
|
40
|
+
this.defaultValue = _defaultValue;
|
|
41
|
+
if (defaultValue) {
|
|
42
|
+
this.defaultValue = defaultValue;
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
equal(source, target) {
|
|
46
|
+
return source === target;
|
|
47
|
+
}
|
|
48
|
+
parser() {
|
|
49
|
+
let val = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : '';
|
|
50
|
+
if (!val) {
|
|
51
|
+
ScheduleLogger.warn('RtcTimerFormatter parser,value is empty, return defaultValue', this.defaultValue);
|
|
52
|
+
return this.defaultValue;
|
|
53
|
+
}
|
|
54
|
+
const {
|
|
55
|
+
length
|
|
56
|
+
} = val;
|
|
57
|
+
const mixLightLen = 26; // 混光长度
|
|
58
|
+
const colourLightLen = 22; // 彩光长度
|
|
59
|
+
const brightLightLen = 18; // 白光长度
|
|
60
|
+
const powerLen = 14; // 纯开关长度
|
|
61
|
+
|
|
62
|
+
// 删除定时
|
|
63
|
+
|
|
64
|
+
if (length !== 4 && length !== powerLen && length !== brightLightLen && length !== colourLightLen && length !== mixLightLen) {
|
|
65
|
+
// 数据位数不定, 可能是14位或18位22位26位, 删除定时指令为4位
|
|
66
|
+
ScheduleLogger.warn('RtcTimerFormatter parser fail:', RTC_TIMER, '=>', val);
|
|
67
|
+
return this.defaultValue;
|
|
68
|
+
}
|
|
69
|
+
const step = generateDpStrStep(val);
|
|
70
|
+
if (length === powerLen || length === brightLightLen || length === colourLightLen || length === mixLightLen) {
|
|
71
|
+
const id = step(2); // // 定时任务ID, ABBBBBBB:A:定时任务开关,0-关闭,1-开启;BBBBBBB:定时ID:1-10,最多支持10条
|
|
72
|
+
const idBinaryStr = numToBinStrPad8(id.value); // 转为二进制的八位 => ABBBBBBB
|
|
73
|
+
const status = idBinaryStr.slice(0, 1) === '1'; // 0-关闭,1-开启
|
|
74
|
+
const timerId = parseInt(idBinaryStr.slice(1), 2); // 定时ID:1-10
|
|
75
|
+
|
|
76
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
77
|
+
step(2).value; // 定时类型, 普通定时选择:0x01
|
|
78
|
+
const repeatInt = step(2).value; // 单次定时任务bit0-bit6全为0,bit0-bit6某位为1时,表示对应周几周期定时 bit0 => 周日
|
|
79
|
+
const loops = padEnd(repeatInt.toString(2).split('').reverse().join(''), 7, '0');
|
|
80
|
+
|
|
81
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
82
|
+
step(2).value; // 时间类型 => 0x00:精确时间 0x01:日出前 0x02:日出后 0x03:日落前 0x04:日落后 0x05:倒计时
|
|
83
|
+
const time = step(4).value; // 时间 => 一天为 24H*60=1440
|
|
84
|
+
|
|
85
|
+
/**
|
|
86
|
+
* A:设备动作
|
|
87
|
+
* A=0x00,关灯,
|
|
88
|
+
A=0x01,开灯,
|
|
89
|
+
A=0x02,白光,
|
|
90
|
+
A=0x03,彩光,
|
|
91
|
+
A=0x04,混光,
|
|
92
|
+
A=0x05,情景,
|
|
93
|
+
A=0x06,节能,
|
|
94
|
+
A=0x07,太阳能
|
|
95
|
+
*/
|
|
96
|
+
step(2).value;
|
|
97
|
+
let dps = {}; // 设备动作
|
|
98
|
+
// 白光模式 dp
|
|
99
|
+
if (length === brightLightLen) {
|
|
100
|
+
const bright_value = step(2).value;
|
|
101
|
+
const temp_value = step(2).value;
|
|
102
|
+
dps = {
|
|
103
|
+
[EDpCodes.bright_value]: bright_value,
|
|
104
|
+
[EDpCodes.temp_value]: temp_value
|
|
105
|
+
};
|
|
106
|
+
} else if (length === colourLightLen) {
|
|
107
|
+
// 彩光模式dp
|
|
108
|
+
const hue = step(4).value;
|
|
109
|
+
const saturation = step(2).value;
|
|
110
|
+
const _value = step(2).value;
|
|
111
|
+
dps = {
|
|
112
|
+
[EDpCodes.colour_data]: {
|
|
113
|
+
hue,
|
|
114
|
+
saturation,
|
|
115
|
+
value: _value
|
|
116
|
+
}
|
|
117
|
+
};
|
|
118
|
+
} else if (length === mixLightLen) {
|
|
119
|
+
// 混光模式
|
|
120
|
+
const hue = step(4).value;
|
|
121
|
+
const saturation = step(2).value;
|
|
122
|
+
const _value = step(2).value;
|
|
123
|
+
const bright_value = step(2).value;
|
|
124
|
+
const temp_value = step(2).value;
|
|
125
|
+
dps = {
|
|
126
|
+
[EDpCodes.colour_data]: {
|
|
127
|
+
hue,
|
|
128
|
+
saturation,
|
|
129
|
+
value: _value
|
|
130
|
+
},
|
|
131
|
+
[EDpCodes.bright_value]: bright_value,
|
|
132
|
+
[EDpCodes.temp_value]: temp_value
|
|
133
|
+
};
|
|
134
|
+
} else {
|
|
135
|
+
// 开关灯模式
|
|
136
|
+
// 开灯
|
|
137
|
+
// 01
|
|
138
|
+
const startDpDataInt = step(2).value;
|
|
139
|
+
const startDpDataHex = this.to16(startDpDataInt, 2);
|
|
140
|
+
const switch_led = startDpDataHex.slice(0, 2) === '01';
|
|
141
|
+
dps = {
|
|
142
|
+
[EDpCodes.switch_led]: switch_led
|
|
143
|
+
};
|
|
144
|
+
}
|
|
145
|
+
return {
|
|
146
|
+
timerId: `${timerId}`,
|
|
147
|
+
status,
|
|
148
|
+
loops,
|
|
149
|
+
time: minuteToTime(time),
|
|
150
|
+
dps
|
|
151
|
+
};
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
// 删除时 dp 数据
|
|
155
|
+
const id = step(2).value;
|
|
156
|
+
const idBinaryStr = numToBinStrPad8(id);
|
|
157
|
+
const status = idBinaryStr.slice(0, 1) === '1';
|
|
158
|
+
const timerId = parseInt(idBinaryStr.slice(1), 2);
|
|
159
|
+
return {
|
|
160
|
+
timerId: `${timerId}`,
|
|
161
|
+
status
|
|
162
|
+
};
|
|
163
|
+
}
|
|
164
|
+
to16(value, length) {
|
|
165
|
+
return numToHexString(value, length);
|
|
166
|
+
}
|
|
167
|
+
formatter(data) {
|
|
168
|
+
if (typeof data === 'string') {
|
|
169
|
+
return data;
|
|
170
|
+
}
|
|
171
|
+
// 自定义格式转为16进制
|
|
172
|
+
const {
|
|
173
|
+
timerId,
|
|
174
|
+
// 定时任务ID
|
|
175
|
+
status,
|
|
176
|
+
// type, // 定时类型,普通定时选择:0x01
|
|
177
|
+
loops,
|
|
178
|
+
// 单次定时任务bit0-bit6全为0,bit0-bit6某位为1时,表示对应周几周期定时,0 => 周日
|
|
179
|
+
// startTimeType, // 定时任务开始时间类型,0x00 => 固定时间
|
|
180
|
+
time,
|
|
181
|
+
dps
|
|
182
|
+
} = data;
|
|
183
|
+
ScheduleLogger.debug('rtcTimer formatter data:', data);
|
|
184
|
+
if (loops) {
|
|
185
|
+
const _dps = {};
|
|
186
|
+
Object.keys(dps).forEach(key => {
|
|
187
|
+
// eslint-disable-next-line no-self-compare
|
|
188
|
+
if (+key === +key) {
|
|
189
|
+
const dpCode = getDpCodeByDpId(key);
|
|
190
|
+
dpCode && (_dps[dpCode] = dps[key]);
|
|
191
|
+
} else {
|
|
192
|
+
_dps[key] = dps[key];
|
|
193
|
+
}
|
|
194
|
+
});
|
|
195
|
+
const statusStr = status ? '1' : '0';
|
|
196
|
+
const timerIdStr = padStart(Number(timerId).toString(2), 7, '0');
|
|
197
|
+
const idStr = this.to16(parseInt(`${statusStr}${timerIdStr}`, 2), 2);
|
|
198
|
+
const typeStr = this.to16('01', 2);
|
|
199
|
+
const repeatStr = this.to16(parseInt(loops.split('').reverse().join(''), 2), 2);
|
|
200
|
+
const startTimeTypeStr = this.to16('00', 2);
|
|
201
|
+
let timeNum = +time;
|
|
202
|
+
if (isNaN(time) && typeof time === 'string') {
|
|
203
|
+
const [min, second] = time === null || time === void 0 ? void 0 : time.split(':');
|
|
204
|
+
timeNum = +min * 60 + Number(second);
|
|
205
|
+
}
|
|
206
|
+
const startTimeStr = this.to16(timeNum, 4);
|
|
207
|
+
let dpDataStr;
|
|
208
|
+
/**
|
|
209
|
+
* ABCDEFG 7字节; A:设备动作;BCDEFG:动作参数;
|
|
210
|
+
* A=0x00,关灯,BCDEFG无效;
|
|
211
|
+
* A=0x01,开灯,BCDEFG无效;
|
|
212
|
+
* A=0x02,白光,B:亮度,1-100,C:色温,0-100,DEFG无效;
|
|
213
|
+
* A=0x03,彩光,BC:色度,0-360,D:饱和度,0-100,E:彩光亮度,0-100,FG无效;
|
|
214
|
+
* A=0x04,混光,RGBCW全亮,BC:色度,0-360,D:饱和度,0-100,E:彩光亮度,1-100,F:白光亮度,1-100,G:色温,0-100;
|
|
215
|
+
* A=0x05,情景,B:场景ID,0-15,CDEFG无效;
|
|
216
|
+
* A=0x06,节能,B:场景ID,0-15,C:节能开关,0-关,1-开,DEFG无效;
|
|
217
|
+
* A=0x07,太阳能,BC:色度,0-360,D:饱和度,0-100,E:彩光亮度,1-100,F:白光亮度,1-100,G:色温,0-100;
|
|
218
|
+
* A=0x08,执行定时前状态,BCDEFG无效;
|
|
219
|
+
*/
|
|
220
|
+
if (_dps[EDpCodes.switch_led] === false) {
|
|
221
|
+
dpDataStr = '00';
|
|
222
|
+
} else if (Object.keys(_dps).includes(EDpCodes.colour_data) && Object.keys(_dps).includes(EDpCodes.temp_value)) {
|
|
223
|
+
const bright_value = _dps[EDpCodes.bright_value];
|
|
224
|
+
const temp_value = _dps[EDpCodes.temp_value];
|
|
225
|
+
const {
|
|
226
|
+
hue,
|
|
227
|
+
saturation,
|
|
228
|
+
value
|
|
229
|
+
} = _dps[EDpCodes.colour_data];
|
|
230
|
+
const hueStr = this.to16(hue, 4);
|
|
231
|
+
const saturationStr = this.to16(saturation, 2);
|
|
232
|
+
const valueStr = this.to16(value, 2);
|
|
233
|
+
const brightStr = this.to16(bright_value, 2);
|
|
234
|
+
const tempStr = this.to16(temp_value, 2);
|
|
235
|
+
dpDataStr = `04${hueStr}${saturationStr}${valueStr}${brightStr}${tempStr}`;
|
|
236
|
+
} else if (Object.keys(_dps).includes(EDpCodes.colour_data)) {
|
|
237
|
+
const {
|
|
238
|
+
hue = 0,
|
|
239
|
+
saturation = 100,
|
|
240
|
+
value = 100
|
|
241
|
+
} = _dps[EDpCodes.colour_data];
|
|
242
|
+
const hueStr = this.to16(hue, 4);
|
|
243
|
+
const saturationStr = this.to16(saturation, 2);
|
|
244
|
+
const valueStr = this.to16(value, 2);
|
|
245
|
+
dpDataStr = `03${hueStr}${saturationStr}${valueStr}`;
|
|
246
|
+
} else if (Object.keys(_dps).includes(EDpCodes.bright_value)) {
|
|
247
|
+
var _dps$EDpCodes$bright_, _dps$EDpCodes$temp_va;
|
|
248
|
+
const bright_value = (_dps$EDpCodes$bright_ = _dps[EDpCodes.bright_value]) !== null && _dps$EDpCodes$bright_ !== void 0 ? _dps$EDpCodes$bright_ : 100;
|
|
249
|
+
const temp_value = (_dps$EDpCodes$temp_va = _dps[EDpCodes.temp_value]) !== null && _dps$EDpCodes$temp_va !== void 0 ? _dps$EDpCodes$temp_va : 0;
|
|
250
|
+
const brightStr = this.to16(bright_value, 2);
|
|
251
|
+
const temperatureStr = this.to16(temp_value, 2);
|
|
252
|
+
dpDataStr = `02${brightStr}${temperatureStr}`;
|
|
253
|
+
} else {
|
|
254
|
+
const powerStr = _dps[EDpCodes.switch_led] ? '01' : '00';
|
|
255
|
+
dpDataStr = `${powerStr}`;
|
|
256
|
+
}
|
|
257
|
+
const _res = `${idStr}${typeStr}${repeatStr}${startTimeTypeStr}${startTimeStr}${dpDataStr}`;
|
|
258
|
+
ScheduleLogger.debug('rtcTimer formatter dpStr1:', dpDataStr);
|
|
259
|
+
ScheduleLogger.debug('rtcTimer formatter dpStr2:', _res);
|
|
260
|
+
return _res;
|
|
261
|
+
}
|
|
262
|
+
const statusStr = status ? '1' : '0';
|
|
263
|
+
const timerIdStr = padStart(Number(timerId).toString(2), 7, '0');
|
|
264
|
+
const idStr = this.to16(parseInt(`${statusStr}${timerIdStr}`, 2), 2);
|
|
265
|
+
const _res = `${idStr}00`;
|
|
266
|
+
ScheduleLogger.debug('rtcTimer remove formatter2 data:', _res);
|
|
267
|
+
return _res;
|
|
268
|
+
}
|
|
269
|
+
}
|
|
270
|
+
export const rtcTimerParser = new RtcTimerFormatter();
|
|
271
|
+
export const getRtcParser = () => {
|
|
272
|
+
return rtcTimerParser;
|
|
273
|
+
};
|
|
274
|
+
|
|
275
|
+
// if (isInIDEFun()) {
|
|
276
|
+
// const dps = {
|
|
277
|
+
// // switch_led: true,
|
|
278
|
+
// bright_value: 96,
|
|
279
|
+
// temp_value: 95,
|
|
280
|
+
// colour_data: {
|
|
281
|
+
// hue: 338,
|
|
282
|
+
// saturation: 0,
|
|
283
|
+
// value: 100,
|
|
284
|
+
// },
|
|
285
|
+
// };
|
|
286
|
+
// const demoData = {
|
|
287
|
+
// ..._defaultValue,
|
|
288
|
+
// dps,
|
|
289
|
+
// };
|
|
290
|
+
|
|
291
|
+
// const newRtcStr = rtcTimerParser.formatter(demoData);
|
|
292
|
+
|
|
293
|
+
// const newRtcData = rtcTimerParser.parser(newRtcStr);
|
|
294
|
+
|
|
295
|
+
// if (!isEqual(demoData, newRtcData)) {
|
|
296
|
+
// console.warn(demoData, 'rtcTimerParser demoData');
|
|
297
|
+
// console.warn(newRtcData, 'rtcTimerParser newRtcData');
|
|
298
|
+
// throw new Error('rtcTimerParser parser demo err!!!');
|
|
299
|
+
// }
|
|
300
|
+
// }
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { Support } from '../../utils/ScheduleSupport';
|
|
2
|
+
export { sleepParser as sleepParserCommon, Sleep as SleepCommon } from './sleepCommon';
|
|
3
|
+
import { TSleepDataSigmesh, TSleepData } from '../../types';
|
|
4
|
+
export declare class SleepParser {
|
|
5
|
+
support: Support;
|
|
6
|
+
parser(dpStr: string): TSleepData | TSleepDataSigmesh;
|
|
7
|
+
formatter(dpData: TSleepDataSigmesh | TSleepData): string;
|
|
8
|
+
}
|
|
9
|
+
export declare const getSleepParser: () => SleepParser;
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
export { sleepParser as sleepParserCommon, Sleep as SleepCommon } from './sleepCommon';
|
|
2
|
+
import { sleepParser as sleepParserCommon } from './sleepCommon';
|
|
3
|
+
export class SleepParser {
|
|
4
|
+
parser(dpStr) {
|
|
5
|
+
// FIXME: 暂时不支持 Sigmesh 设备
|
|
6
|
+
// const support = getSupportIns();
|
|
7
|
+
// const isSigmesh = support.isSigMeshDevice();
|
|
8
|
+
// if (isSigmesh) {
|
|
9
|
+
// return sleepParserSigmesh.parser(dpStr) as TSleepDataSigmesh;
|
|
10
|
+
// }
|
|
11
|
+
return sleepParserCommon.parser(dpStr);
|
|
12
|
+
}
|
|
13
|
+
formatter(dpData) {
|
|
14
|
+
// FIXME: 暂时不支持 Sigmesh 设备
|
|
15
|
+
// const support = getSupportIns();
|
|
16
|
+
// const isSigmesh = support.isSigMeshDevice();
|
|
17
|
+
// if (isSigmesh) {
|
|
18
|
+
// return sleepParserSigmesh.formatter(dpData as TSleepDataSigmesh);
|
|
19
|
+
// }
|
|
20
|
+
return sleepParserCommon.formatter(dpData);
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
let sleepParser = null;
|
|
24
|
+
export const getSleepParser = () => {
|
|
25
|
+
if (!sleepParser) {
|
|
26
|
+
sleepParser = new SleepParser();
|
|
27
|
+
}
|
|
28
|
+
return sleepParser;
|
|
29
|
+
};
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { TSleepData, TSleepNode } from '../../types';
|
|
2
|
+
export declare class Sleep {
|
|
3
|
+
defaultValue: TSleepData;
|
|
4
|
+
parser(dpStr: string): TSleepData | {
|
|
5
|
+
version: any;
|
|
6
|
+
length: 4;
|
|
7
|
+
nodes: TSleepNode[];
|
|
8
|
+
};
|
|
9
|
+
formatter(data: TSleepData): string;
|
|
10
|
+
}
|
|
11
|
+
export declare const sleepParser: Sleep;
|
|
@@ -0,0 +1,117 @@
|
|
|
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 Sleep {
|
|
14
|
+
defaultValue = {
|
|
15
|
+
version: 0,
|
|
16
|
+
length: 0,
|
|
17
|
+
nodes: []
|
|
18
|
+
};
|
|
19
|
+
parser(dpStr) {
|
|
20
|
+
scheduleLogger.debug('Sleep parser dpStr: ', dpStr);
|
|
21
|
+
if (!dpStr) {
|
|
22
|
+
return this.defaultValue;
|
|
23
|
+
}
|
|
24
|
+
const dpLength = dpStr.length;
|
|
25
|
+
if (!dpLength || (dpLength - 4) % 22 !== 0) {
|
|
26
|
+
scheduleLogger.error('数据有问题,无法解析');
|
|
27
|
+
return this.defaultValue;
|
|
28
|
+
}
|
|
29
|
+
const step = generateDpStrStep(dpStr);
|
|
30
|
+
const version = step(2).value;
|
|
31
|
+
let length = step(2).value;
|
|
32
|
+
length = Math.min(length, 4);
|
|
33
|
+
const nodes = [];
|
|
34
|
+
// 解析循环节点
|
|
35
|
+
for (let i = 0; i < length; 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 temperatureStep = step(2);
|
|
50
|
+
const temperature = temperatureStep.value;
|
|
51
|
+
nodes.push({
|
|
52
|
+
onOff,
|
|
53
|
+
loops,
|
|
54
|
+
step: stepNum,
|
|
55
|
+
hour,
|
|
56
|
+
minute,
|
|
57
|
+
hue: Math.round(hundreds * 100 + tensOnes),
|
|
58
|
+
// 0-360
|
|
59
|
+
saturation,
|
|
60
|
+
value: val,
|
|
61
|
+
brightness,
|
|
62
|
+
temperature,
|
|
63
|
+
index: i
|
|
64
|
+
});
|
|
65
|
+
if (temperatureStep.done) {
|
|
66
|
+
break;
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
return {
|
|
70
|
+
version,
|
|
71
|
+
length,
|
|
72
|
+
nodes
|
|
73
|
+
};
|
|
74
|
+
}
|
|
75
|
+
formatter(data) {
|
|
76
|
+
var _data$nodes, _data$nodes2;
|
|
77
|
+
const result = [numToHexString(data.version), numToHexString((_data$nodes = data.nodes) === null || _data$nodes === void 0 ? void 0 : _data$nodes.length)];
|
|
78
|
+
scheduleLogger.debug('sleep formatter data', data);
|
|
79
|
+
data === null || data === void 0 || (_data$nodes2 = data.nodes) === null || _data$nodes2 === void 0 || _data$nodes2.forEach(node => {
|
|
80
|
+
// 拆分色相值为百位和十个位
|
|
81
|
+
const hueHundreds = Math.floor(node.hue / 100);
|
|
82
|
+
const hueTensOnes = node.hue % 100;
|
|
83
|
+
const {
|
|
84
|
+
saturation,
|
|
85
|
+
value,
|
|
86
|
+
brightness,
|
|
87
|
+
temperature
|
|
88
|
+
} = node;
|
|
89
|
+
let saturation1 = node.saturation;
|
|
90
|
+
let value1 = node.value;
|
|
91
|
+
let brightness1 = node.brightness;
|
|
92
|
+
let temperature1 = node.temperature;
|
|
93
|
+
if (saturation === 0 && value === 0 && brightness === 0 && temperature === 0) {
|
|
94
|
+
saturation1 = defaultColor.saturation;
|
|
95
|
+
value1 = defaultColor.value;
|
|
96
|
+
brightness1 = defaultColor.brightness;
|
|
97
|
+
temperature1 = defaultColor.temperature;
|
|
98
|
+
}
|
|
99
|
+
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));
|
|
100
|
+
});
|
|
101
|
+
return result.join('');
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
export const sleepParser = new Sleep();
|
|
105
|
+
|
|
106
|
+
// if (isInIDEFun()) {
|
|
107
|
+
// // 使用示例
|
|
108
|
+
// const dpStr = '00 01 01 42 01 0b 15 00 00 00 00 00'.replaceAll(' ', '');
|
|
109
|
+
// const result = sleepParser.parser(dpStr);
|
|
110
|
+
// const formatted = sleepParser.formatter(result);
|
|
111
|
+
// console.log(result, 'resultresult');
|
|
112
|
+
// console.log(formatted, 'formattedformatted');
|
|
113
|
+
// console.log(dpStr, 'dpStrdpStr');
|
|
114
|
+
// if (formatted !== dpStr) {
|
|
115
|
+
// throw new Error('sleep dp format error');
|
|
116
|
+
// }
|
|
117
|
+
// }
|
|
File without changes
|