@ray-js/lamp-schedule-core 1.0.5-beta.2 → 1.0.5-beta.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/config/dpCodes.d.ts +13 -0
- package/lib/config/dpCodes.js +29 -0
- package/lib/dpParser/stripLocalTimer.d.ts +39 -8
- package/lib/dpParser/stripLocalTimer.js +262 -94
- package/lib/hooks/useCycleDp.js +1 -1
- package/lib/hooks/useDPByProtocol.d.ts +9 -0
- package/lib/hooks/useRandomDp.js +1 -1
- package/lib/hooks/useRhythmsDp.js +1 -1
- package/lib/hooks/useSleepDp.js +1 -1
- package/lib/hooks/useTimerDp.d.ts +4 -3
- package/lib/hooks/useTimerDp.js +21 -4
- package/lib/hooks/useTimerReportDp.js +1 -0
- package/lib/hooks/useWakeUpDp.js +1 -1
- package/lib/hooks/useWakeupDp.js +1 -1
- package/lib/types/timer.d.ts +0 -31
- package/lib/utils/ScheduleDataSync.js +1 -0
- package/lib/utils/getDPByProtocol.d.ts +18 -0
- package/lib/utils/matterDeviceUtils.d.ts +18 -0
- package/package.json +1 -1
package/lib/config/dpCodes.d.ts
CHANGED
|
@@ -37,6 +37,19 @@ export declare const scheduleDpCodes: {
|
|
|
37
37
|
readonly COLOUR_DATA_RAW: "colour_data_raw";
|
|
38
38
|
/** 亮度调节 Beacon */
|
|
39
39
|
readonly BRIGHT_ADJUST_DATA: "bright_adjust_data";
|
|
40
|
+
/** ------ 风扇灯 Beacon DP -------- */
|
|
41
|
+
/** 风扇模式 Beacon */
|
|
42
|
+
readonly FAN_MODE: "fan_mode";
|
|
43
|
+
/** 风向 Beacon */
|
|
44
|
+
readonly FAN_DIRECTION: "fan_direction";
|
|
45
|
+
/** 摇头 Beacon */
|
|
46
|
+
readonly SHAKE: "shake";
|
|
47
|
+
readonly WHITE_SWITCH: "white_switch";
|
|
48
|
+
readonly COLOUR_SWITCH: "colour_switch";
|
|
49
|
+
readonly FAN_SWITCH: "fan_switch";
|
|
50
|
+
readonly FAN_SPEED: "fan_speed";
|
|
51
|
+
readonly FAN_BEEP: "fan_beep";
|
|
52
|
+
readonly STRIP_SCENE: "strip_scene";
|
|
40
53
|
/** 模式 */
|
|
41
54
|
readonly WORK_MODE: "work_mode";
|
|
42
55
|
};
|
package/lib/config/dpCodes.js
CHANGED
|
@@ -40,6 +40,35 @@ export const scheduleDpCodes = {
|
|
|
40
40
|
COLOUR_DATA_RAW: 'colour_data_raw',
|
|
41
41
|
/** 亮度调节 Beacon */
|
|
42
42
|
BRIGHT_ADJUST_DATA: 'bright_adjust_data',
|
|
43
|
+
/** ------ 风扇灯 Beacon DP -------- */
|
|
44
|
+
/** 风扇模式 Beacon */
|
|
45
|
+
FAN_MODE: 'fan_mode',
|
|
46
|
+
// 枚举值: fresh, nature
|
|
47
|
+
/** 风向 Beacon */
|
|
48
|
+
FAN_DIRECTION: 'fan_direction',
|
|
49
|
+
// 枚举值: forward, reverse
|
|
50
|
+
/** 摇头 Beacon */
|
|
51
|
+
SHAKE: 'shake',
|
|
52
|
+
// boolean
|
|
53
|
+
// 主灯开关
|
|
54
|
+
WHITE_SWITCH: 'white_switch',
|
|
55
|
+
// boolean
|
|
56
|
+
// 氛围灯开关
|
|
57
|
+
COLOUR_SWITCH: 'colour_switch',
|
|
58
|
+
// boolean
|
|
59
|
+
// 风扇开关
|
|
60
|
+
FAN_SWITCH: 'fan_switch',
|
|
61
|
+
// boolean
|
|
62
|
+
// 风扇速度
|
|
63
|
+
FAN_SPEED: 'fan_speed',
|
|
64
|
+
// number 1-100
|
|
65
|
+
// 声音
|
|
66
|
+
FAN_BEEP: 'fan_beep',
|
|
67
|
+
// boolean
|
|
68
|
+
// 情景
|
|
69
|
+
STRIP_SCENE: 'strip_scene',
|
|
70
|
+
// beacon mesh情景功能,支持速度,亮度编辑
|
|
71
|
+
|
|
43
72
|
/** 模式 */
|
|
44
73
|
WORK_MODE: 'work_mode'
|
|
45
74
|
};
|
|
@@ -1,10 +1,41 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
/**
|
|
2
|
+
* 用法
|
|
3
|
+
* const stripLocalTimerTrans = new StripLocalTimerTransformer();
|
|
4
|
+
* // 解析dp
|
|
5
|
+
* const result = stripLocalTimerTrans.parser(dpStr);
|
|
6
|
+
* // 格式化
|
|
7
|
+
* const dpStr = stripLocalTimerTrans.formatter({xxx: xxx})
|
|
8
|
+
* */
|
|
9
|
+
import { Transformer } from '@ray-js/panel-sdk/lib/protocols/lamp/interface';
|
|
10
|
+
export type TStripLocalTimerData = {
|
|
11
|
+
timerId: number;
|
|
12
|
+
time: number;
|
|
13
|
+
loops: string;
|
|
14
|
+
power?: boolean;
|
|
15
|
+
status: boolean;
|
|
16
|
+
brightness?: number;
|
|
17
|
+
temperature?: number;
|
|
18
|
+
hue?: number;
|
|
19
|
+
saturation?: number;
|
|
20
|
+
value?: number;
|
|
21
|
+
mode: number;
|
|
22
|
+
dps: Record<string, any>;
|
|
23
|
+
speed?: number;
|
|
24
|
+
fanMode?: number;
|
|
25
|
+
direction?: number;
|
|
26
|
+
shake?: number;
|
|
27
|
+
sceneId?: number;
|
|
28
|
+
};
|
|
29
|
+
export declare class StripLocalTimerTransformer implements Transformer<TStripLocalTimerData> {
|
|
30
|
+
defaultValue: TStripLocalTimerData;
|
|
31
|
+
uuid: string;
|
|
32
|
+
constructor(uuid?: string, defaultValue?: TStripLocalTimerData);
|
|
33
|
+
equal(source: string, target: string): boolean;
|
|
34
|
+
parser(value: string): TStripLocalTimerData;
|
|
35
|
+
isUndefined(value: any): boolean;
|
|
36
|
+
to16(value: number, length?: number): string;
|
|
37
|
+
binTo16(bin: string, len?: number): string;
|
|
4
38
|
formatter(data: TStripLocalTimerData): string;
|
|
5
39
|
}
|
|
6
|
-
export declare const stripLocalTimerParser:
|
|
7
|
-
|
|
8
|
-
formatter: (data: TStripLocalTimerData) => string;
|
|
9
|
-
};
|
|
10
|
-
export declare const getStripLocalTimerParser: () => StripLocalTimerFormatter;
|
|
40
|
+
export declare const stripLocalTimerParser: StripLocalTimerTransformer;
|
|
41
|
+
export declare const getStripLocalTimerParser: () => StripLocalTimerTransformer;
|
|
@@ -1,107 +1,275 @@
|
|
|
1
1
|
import "core-js/modules/esnext.iterator.constructor.js";
|
|
2
2
|
import "core-js/modules/esnext.iterator.map.js";
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
const
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
3
|
+
import "core-js/modules/esnext.iterator.reduce.js";
|
|
4
|
+
// Beacon 灯带本地定时标准dp解析工具函数
|
|
5
|
+
/**
|
|
6
|
+
* 用法
|
|
7
|
+
* const stripLocalTimerTrans = new StripLocalTimerTransformer();
|
|
8
|
+
* // 解析dp
|
|
9
|
+
* const result = stripLocalTimerTrans.parser(dpStr);
|
|
10
|
+
* // 格式化
|
|
11
|
+
* const dpStr = stripLocalTimerTrans.formatter({xxx: xxx})
|
|
12
|
+
* */
|
|
13
|
+
|
|
14
|
+
import { isNumber } from 'lodash-es';
|
|
15
|
+
import { generateDpStrStep } from '@ray-js/panel-sdk/lib/utils';
|
|
16
|
+
import dayjs from 'dayjs';
|
|
17
|
+
import { scheduleLogger } from '../utils/ScheduleLogger';
|
|
18
|
+
import { scheduleDpCodes } from '../config/dpCodes';
|
|
19
|
+
const getArray = array => Array.isArray(array) ? array : [];
|
|
20
|
+
export class StripLocalTimerTransformer {
|
|
21
|
+
defaultValue = {
|
|
22
|
+
timerId: 0,
|
|
23
|
+
time: 0,
|
|
24
|
+
loops: '0000000',
|
|
25
|
+
power: true,
|
|
26
|
+
// 设备开关 switch_led
|
|
27
|
+
status: true,
|
|
28
|
+
// 使能 0 关闭 1开启 应该对应 status
|
|
29
|
+
brightness: 0,
|
|
30
|
+
temperature: 0,
|
|
31
|
+
sceneId: 0,
|
|
32
|
+
hue: 0,
|
|
33
|
+
saturation: 0,
|
|
34
|
+
value: 0,
|
|
35
|
+
mode: 0,
|
|
36
|
+
dps: {
|
|
37
|
+
switch_led: true
|
|
38
|
+
}
|
|
39
|
+
};
|
|
40
|
+
constructor() {
|
|
41
|
+
let uuid = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 'strip_local_timer';
|
|
42
|
+
let defaultValue = arguments.length > 1 ? arguments[1] : undefined;
|
|
43
|
+
this.uuid = uuid;
|
|
44
|
+
if (defaultValue) {
|
|
45
|
+
this.defaultValue = defaultValue;
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
// 比较两个值是否一致
|
|
50
|
+
equal(source, target) {
|
|
51
|
+
return source === target;
|
|
52
|
+
}
|
|
53
|
+
parser(value) {
|
|
54
|
+
const {
|
|
55
|
+
length
|
|
56
|
+
} = value;
|
|
57
|
+
if (!length) {
|
|
58
|
+
scheduleLogger.warn('数据有问题,无法解析');
|
|
59
|
+
return this.defaultValue;
|
|
60
|
+
}
|
|
61
|
+
const step = generateDpStrStep(value);
|
|
62
|
+
const step2 = () => step().value;
|
|
63
|
+
const opt = Array.from(step2().toString(2).padStart(8, '0')).map(i => Number(i));
|
|
64
|
+
const id = parseInt(opt.slice(0, 3).join('').padStart(8, '0'), 2);
|
|
65
|
+
const status = !!opt[4];
|
|
66
|
+
const week1 = opt.slice(5).join('');
|
|
67
|
+
const opt1 = Array.from(step2().toString(2).padStart(8, '0')).map(i => Number(i));
|
|
68
|
+
const week2 = opt1.slice(0, 4).join('');
|
|
69
|
+
const weeks = (week1 + week2).padStart(8, '0').split('').reverse().map(v => parseInt(v, 10));
|
|
70
|
+
const time1 = parseInt(opt1.slice(4).join('').padStart(8, '0'), 2);
|
|
71
|
+
const time2 = step2();
|
|
72
|
+
const time = time1 + time2;
|
|
73
|
+
const opt2 = Array.from(step2().toString(2).padStart(8, '0')).map(i => Number(i));
|
|
74
|
+
const mode = parseInt(opt2.slice(0, 3).join('').padStart(8, '0'), 2);
|
|
75
|
+
let power = true;
|
|
76
|
+
// mode 1 开关模式
|
|
77
|
+
if (mode === 1) {
|
|
78
|
+
power = +step2() === 1;
|
|
79
|
+
return {
|
|
80
|
+
timerId: id,
|
|
37
81
|
status,
|
|
82
|
+
loops: weeks.join(''),
|
|
38
83
|
time,
|
|
39
|
-
|
|
40
|
-
|
|
84
|
+
mode,
|
|
85
|
+
power,
|
|
86
|
+
dps: {
|
|
87
|
+
[scheduleDpCodes.SWITCH_LED]: power
|
|
88
|
+
}
|
|
41
89
|
};
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
90
|
+
}
|
|
91
|
+
// mode 2 白光模式
|
|
92
|
+
if (mode === 2) {
|
|
93
|
+
const brightness = step2();
|
|
94
|
+
const temperature = step2();
|
|
95
|
+
return {
|
|
96
|
+
timerId: id,
|
|
97
|
+
status,
|
|
98
|
+
loops: weeks.join(''),
|
|
99
|
+
time,
|
|
100
|
+
mode,
|
|
101
|
+
power,
|
|
102
|
+
brightness: brightness * 10,
|
|
103
|
+
temperature: temperature * 10,
|
|
104
|
+
dps: {
|
|
105
|
+
[scheduleDpCodes.SWITCH_LED]: power,
|
|
106
|
+
[scheduleDpCodes.BRIGHTNESS]: brightness * 10,
|
|
107
|
+
[scheduleDpCodes.TEMPERATURE]: temperature * 10
|
|
108
|
+
}
|
|
109
|
+
};
|
|
110
|
+
}
|
|
111
|
+
// mode 3 场景模式
|
|
112
|
+
if (mode === 3) {
|
|
113
|
+
const sceneId = step2();
|
|
114
|
+
return {
|
|
115
|
+
timerId: id,
|
|
116
|
+
status,
|
|
117
|
+
loops: weeks.join(''),
|
|
118
|
+
time,
|
|
119
|
+
mode,
|
|
120
|
+
power,
|
|
121
|
+
sceneId,
|
|
122
|
+
dps: {
|
|
123
|
+
[scheduleDpCodes.SWITCH_LED]: power
|
|
124
|
+
}
|
|
125
|
+
};
|
|
126
|
+
}
|
|
127
|
+
// mode 5 风扇模式
|
|
128
|
+
if (mode === 5) {
|
|
129
|
+
const speed = step2();
|
|
130
|
+
const fanMode = step2();
|
|
131
|
+
const direction = step2();
|
|
132
|
+
const shake = step2();
|
|
133
|
+
return {
|
|
134
|
+
timerId: id,
|
|
135
|
+
status,
|
|
136
|
+
loops: weeks.join(''),
|
|
137
|
+
time,
|
|
138
|
+
mode,
|
|
139
|
+
power,
|
|
140
|
+
speed,
|
|
141
|
+
fanMode,
|
|
142
|
+
direction,
|
|
143
|
+
shake,
|
|
144
|
+
dps: {
|
|
145
|
+
[scheduleDpCodes.FAN_SPEED]: speed,
|
|
146
|
+
[scheduleDpCodes.FAN_MODE]: fanMode,
|
|
147
|
+
[scheduleDpCodes.FAN_DIRECTION]: direction,
|
|
148
|
+
[scheduleDpCodes.SHAKE]: shake
|
|
149
|
+
}
|
|
150
|
+
};
|
|
151
|
+
}
|
|
152
|
+
// mode 4 彩光模式
|
|
153
|
+
const hue1 = parseInt(opt2.slice(4).join('').padStart(8, '0'), 2);
|
|
154
|
+
const opt3 = Array.from(step2().toString(2).padStart(8, '0')).map(i => Number(i));
|
|
155
|
+
const hue2 = parseInt(opt3.slice(0, 2).join('').padStart(8, '0'), 2);
|
|
156
|
+
const hue = +hue1 + +hue2;
|
|
157
|
+
const sat1 = parseInt(opt3.slice(2).join('').padStart(8, '0'), 2);
|
|
158
|
+
const opt4 = Array.from(step2().toString(2).padStart(8, '0')).map(i => Number(i));
|
|
159
|
+
const sat2 = parseInt(opt4.slice(0, 1).join('').padStart(8, '0'), 2);
|
|
160
|
+
const saturation = parseInt((sat1 + sat2).toString().padStart(8, '0'), 2);
|
|
161
|
+
const hueValue = parseInt(opt4.slice(1).join('').padStart(8, '0'), 2);
|
|
162
|
+
return {
|
|
163
|
+
timerId: id,
|
|
164
|
+
status,
|
|
165
|
+
loops: weeks.join(''),
|
|
166
|
+
time,
|
|
167
|
+
mode,
|
|
168
|
+
hue: hue * 10,
|
|
169
|
+
saturation,
|
|
170
|
+
value: hueValue,
|
|
171
|
+
dps: {
|
|
172
|
+
[scheduleDpCodes.SWITCH_LED]: true,
|
|
173
|
+
[scheduleDpCodes.COLOUR_DATA]: {
|
|
174
|
+
hue: Math.round(hue * 10),
|
|
175
|
+
saturation: Math.round(saturation),
|
|
176
|
+
value: Math.round(hueValue)
|
|
177
|
+
}
|
|
60
178
|
}
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
179
|
+
};
|
|
180
|
+
}
|
|
181
|
+
isUndefined(value) {
|
|
182
|
+
return value === undefined || value === null;
|
|
183
|
+
}
|
|
184
|
+
to16(value) {
|
|
185
|
+
let length = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 2;
|
|
186
|
+
let result = Number(value || 0).toString(16);
|
|
187
|
+
if (result.length < length) {
|
|
188
|
+
result = result.padStart(length, '0');
|
|
65
189
|
}
|
|
190
|
+
return result;
|
|
191
|
+
}
|
|
192
|
+
binTo16(bin) {
|
|
193
|
+
let len = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 2;
|
|
194
|
+
const num = parseInt(bin, 2);
|
|
195
|
+
return this.to16(num, len);
|
|
66
196
|
}
|
|
67
197
|
formatter(data) {
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
198
|
+
const {
|
|
199
|
+
timerId,
|
|
200
|
+
status,
|
|
201
|
+
loops,
|
|
202
|
+
time,
|
|
203
|
+
power,
|
|
204
|
+
brightness,
|
|
205
|
+
temperature,
|
|
206
|
+
speed,
|
|
207
|
+
fanMode,
|
|
208
|
+
direction,
|
|
209
|
+
shake,
|
|
210
|
+
hue,
|
|
211
|
+
saturation,
|
|
212
|
+
value,
|
|
213
|
+
dps = {}
|
|
214
|
+
} = data;
|
|
215
|
+
const timeNum = isNumber(time) ? Number(time) : (time === null || time === void 0 ? void 0 : time.split(':').reduce((acc, curr) => acc * 60 + Number(curr), 0)) || 0;
|
|
216
|
+
const now = dayjs();
|
|
217
|
+
const _version = this.to16(0); // 版本号
|
|
218
|
+
const _week = this.to16(now.day()); // 星期
|
|
219
|
+
const mins = now.hour() * 60 + now.minute();
|
|
220
|
+
const _currentTime = this.to16(mins, 4); // 当前时刻
|
|
221
|
+
const _second = this.to16(now.second()); // 当前秒
|
|
222
|
+
const enableBin = parseInt(`${status ? 1 : 0}`, 10).toString(2); // 使能位 开启/关闭
|
|
223
|
+
const idBin = parseInt(`${timerId}`, 10).toString(2).padStart(7, '0');
|
|
224
|
+
const _enableId = this.binTo16(`${enableBin}${idBin}`); // 定时任务ID
|
|
225
|
+
const _weeks = this.binTo16([...getArray(loops.split(''))].reverse().join(''), 2); // 周N
|
|
226
|
+
const _time = this.to16(timeNum, 4); // 时刻设置的定时时间
|
|
227
|
+
let mode = 1;
|
|
228
|
+
if (!this.isUndefined(dps.speed) && !this.isUndefined(dps.fanMode) && !this.isUndefined(dps.direction) && !this.isUndefined(dps.shake)) {
|
|
229
|
+
mode = 5;
|
|
230
|
+
} else if (!this.isUndefined(dps.hue) && !this.isUndefined(dps.saturation) && !this.isUndefined(dps.value)) {
|
|
231
|
+
mode = 4;
|
|
232
|
+
} else if (!this.isUndefined(dps.colour_data)) {
|
|
233
|
+
mode = 3;
|
|
234
|
+
} else if (!this.isUndefined(dps.brightness) && !this.isUndefined(dps.temperature)) {
|
|
235
|
+
mode = 2;
|
|
236
|
+
} else {
|
|
237
|
+
mode = 1;
|
|
238
|
+
}
|
|
239
|
+
const _mode = this.to16(mode); // 控制类型 只支持开关模式
|
|
240
|
+
let _action = ''; // 设备动作 开/关
|
|
241
|
+
// power 设备开关
|
|
242
|
+
if (power) {
|
|
243
|
+
switch (mode) {
|
|
244
|
+
case 1:
|
|
245
|
+
// 开/关
|
|
246
|
+
_action = '01';
|
|
247
|
+
break;
|
|
248
|
+
case 2:
|
|
249
|
+
// 白光模式
|
|
250
|
+
_action = `${this.to16(brightness || 0)}${this.to16(temperature || 0)}`;
|
|
251
|
+
break;
|
|
252
|
+
case 3:
|
|
253
|
+
// 场景
|
|
254
|
+
_action = `${this.to16(timerId)}`;
|
|
255
|
+
break;
|
|
256
|
+
case 4:
|
|
257
|
+
// 彩光模式
|
|
258
|
+
// 未进行过测试,请注意此功能是否正确
|
|
259
|
+
_action = `${this.to16(hue || 0)}${this.to16(saturation || 0)}${this.to16(value || 0)}`;
|
|
260
|
+
break;
|
|
261
|
+
case 5:
|
|
262
|
+
// 风扇
|
|
263
|
+
_action = `${this.to16(speed || 0)}${this.to16(fanMode || 0)}${this.to16(direction || 0)}${this.to16(shake || 0)}`;
|
|
264
|
+
break;
|
|
265
|
+
default:
|
|
266
|
+
_action = '';
|
|
95
267
|
}
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
} catch (error) {
|
|
99
|
-
ScheduleLogger.error('dpParser ===> StripLocalTimerFormatter formatter error:', error);
|
|
100
|
-
return '';
|
|
268
|
+
} else {
|
|
269
|
+
_action = '00';
|
|
101
270
|
}
|
|
271
|
+
return `${_version}${_week}${_currentTime}${_second}${_enableId}${_weeks}${_time}${_mode}${_action}`;
|
|
102
272
|
}
|
|
103
273
|
}
|
|
104
|
-
export const stripLocalTimerParser = new
|
|
105
|
-
export const getStripLocalTimerParser = () =>
|
|
106
|
-
return stripLocalTimerParser;
|
|
107
|
-
};
|
|
274
|
+
export const stripLocalTimerParser = new StripLocalTimerTransformer();
|
|
275
|
+
export const getStripLocalTimerParser = () => new StripLocalTimerTransformer();
|
package/lib/hooks/useCycleDp.js
CHANGED
|
@@ -11,7 +11,7 @@ export function useCycleDp() {
|
|
|
11
11
|
} = useBaseLightDp(dpCode);
|
|
12
12
|
const cycleParser = getCycleParser();
|
|
13
13
|
const _updateDp = useCallback(dpData => {
|
|
14
|
-
scheduleLogger.debug('useCycleDp updateDp', dpData);
|
|
14
|
+
scheduleLogger.debug('=== useCycleDp updateDp dpCode:', dpCode, 'dpData: ', dpData);
|
|
15
15
|
updateDp(cycleParser.formatter(dpData));
|
|
16
16
|
}, [cycleParser]);
|
|
17
17
|
const _dpValue = useMemo(() => {
|
|
@@ -20,5 +20,14 @@ export declare const useDPByProtocol: () => {
|
|
|
20
20
|
readonly COLOUR_DATA: "colour_data";
|
|
21
21
|
readonly COLOUR_DATA_RAW: "colour_data_raw";
|
|
22
22
|
readonly BRIGHT_ADJUST_DATA: "bright_adjust_data";
|
|
23
|
+
readonly FAN_MODE: "fan_mode";
|
|
24
|
+
readonly FAN_DIRECTION: "fan_direction";
|
|
25
|
+
readonly SHAKE: "shake";
|
|
26
|
+
readonly WHITE_SWITCH: "white_switch";
|
|
27
|
+
readonly COLOUR_SWITCH: "colour_switch";
|
|
28
|
+
readonly FAN_SWITCH: "fan_switch";
|
|
29
|
+
readonly FAN_SPEED: "fan_speed";
|
|
30
|
+
readonly FAN_BEEP: "fan_beep";
|
|
31
|
+
readonly STRIP_SCENE: "strip_scene";
|
|
23
32
|
readonly WORK_MODE: "work_mode";
|
|
24
33
|
};
|
package/lib/hooks/useRandomDp.js
CHANGED
|
@@ -11,7 +11,7 @@ export function useRandomDp() {
|
|
|
11
11
|
} = useBaseLightDp(dpCode);
|
|
12
12
|
const randomParser = getRandomParser();
|
|
13
13
|
const _updateDp = useCallback(dpData => {
|
|
14
|
-
scheduleLogger.debug('useRandomDp updateDp', dpData);
|
|
14
|
+
scheduleLogger.debug('=== useRandomDp updateDp dpCode:', dpCode, 'dpData: ', dpData);
|
|
15
15
|
updateDp(randomParser.formatter(dpData));
|
|
16
16
|
}, [randomParser]);
|
|
17
17
|
const _dpValue = useMemo(() => {
|
|
@@ -18,7 +18,7 @@ export function useRhythmsDp() {
|
|
|
18
18
|
return {
|
|
19
19
|
dpValue: _dpValue,
|
|
20
20
|
updateDp: dpData => {
|
|
21
|
-
scheduleLogger.debug('useRhythmsDp updateDp', dpData);
|
|
21
|
+
scheduleLogger.debug('=== useRhythmsDp updateDp dpCode:', dpCode, 'dpData: ', dpData);
|
|
22
22
|
updateDp(rhythmParser.formatter(dpData));
|
|
23
23
|
}
|
|
24
24
|
};
|
package/lib/hooks/useSleepDp.js
CHANGED
|
@@ -16,7 +16,7 @@ export function useSleepDp() {
|
|
|
16
16
|
return {
|
|
17
17
|
dpValue: _dpValue,
|
|
18
18
|
updateDp: dpData => {
|
|
19
|
-
scheduleLogger.debug('useSleepDp updateDp', dpData);
|
|
19
|
+
scheduleLogger.debug('=== useSleepDp updateDp dpCode:', dpCode, 'dpData: ', dpData);
|
|
20
20
|
updateDp(sleepParser.formatter(dpData));
|
|
21
21
|
}
|
|
22
22
|
};
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { TRtcTimer } from '../types';
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
2
|
+
import { TStripLocalTimerData } from '../dpParser/stripLocalTimer';
|
|
3
|
+
export declare function useTimerDp(): {
|
|
4
|
+
dpValue: TRtcTimer | TStripLocalTimerData;
|
|
5
|
+
updateDp: (dps: TRtcTimer | TStripLocalTimerData) => void;
|
|
5
6
|
};
|
package/lib/hooks/useTimerDp.js
CHANGED
|
@@ -3,23 +3,40 @@ import { useMemo } from 'react';
|
|
|
3
3
|
import { useBaseLightDp } from './useBaseLightDp';
|
|
4
4
|
import { scheduleDpCodes } from '../config/dpCodes';
|
|
5
5
|
import { rtcTimerParser } from '../dpParser/rtcTimer';
|
|
6
|
+
import { useSupport } from './useCommonSupport';
|
|
7
|
+
import { stripLocalTimerParser } from '../dpParser/stripLocalTimer';
|
|
8
|
+
import { scheduleLogger } from '../utils/ScheduleLogger';
|
|
9
|
+
|
|
6
10
|
// 本地定时dp下发
|
|
7
11
|
export function useTimerDp() {
|
|
8
|
-
|
|
12
|
+
const support = useSupport();
|
|
13
|
+
const isSupportStripLocalTimer = support.isSupportDp(scheduleDpCodes.STRIP_LOCAL_TIMER);
|
|
14
|
+
const isSupportRtcTimer = support.isSupportDp(scheduleDpCodes.RTC_TIMER);
|
|
15
|
+
const _doCode = isSupportStripLocalTimer ? scheduleDpCodes.STRIP_LOCAL_TIMER : scheduleDpCodes.RTC_TIMER;
|
|
9
16
|
const {
|
|
10
17
|
dpValue,
|
|
11
18
|
updateDp
|
|
12
|
-
} = useBaseLightDp(
|
|
19
|
+
} = useBaseLightDp(_doCode);
|
|
13
20
|
const _dpValue = useMemo(() => {
|
|
14
21
|
if (typeof dpValue === 'string') {
|
|
22
|
+
if (isSupportStripLocalTimer) {
|
|
23
|
+
return stripLocalTimerParser.parser(dpValue);
|
|
24
|
+
}
|
|
15
25
|
return rtcTimerParser.parser(dpValue);
|
|
16
26
|
}
|
|
17
27
|
return dpValue;
|
|
18
28
|
}, [dpValue, rtcTimerParser]);
|
|
19
29
|
return {
|
|
20
30
|
dpValue: _dpValue,
|
|
21
|
-
updateDp:
|
|
22
|
-
|
|
31
|
+
updateDp: timerDp => {
|
|
32
|
+
scheduleLogger.debug('=== useTimerDp updateDp dpCode:', _doCode, 'timerDp: ', timerDp);
|
|
33
|
+
if (isSupportStripLocalTimer) {
|
|
34
|
+
updateDp(stripLocalTimerParser.formatter(timerDp));
|
|
35
|
+
} else if (isSupportRtcTimer) {
|
|
36
|
+
updateDp(rtcTimerParser.formatter(timerDp));
|
|
37
|
+
} else {
|
|
38
|
+
scheduleLogger.error('useTimerDp updateDp', '不支持的定时器类型', _doCode);
|
|
39
|
+
}
|
|
23
40
|
}
|
|
24
41
|
};
|
|
25
42
|
}
|
|
@@ -25,6 +25,7 @@ export function useTimerReportDp() {
|
|
|
25
25
|
isSupport,
|
|
26
26
|
dpValue: _dpValue,
|
|
27
27
|
updateDp: timerReportDp => {
|
|
28
|
+
ScheduleLogger.debug('=== useTimerReportDp updateDp dpCode:', dpCode, 'timerReportDp: ', timerReportDp);
|
|
28
29
|
updateDp(timerReportParser.formatter(timerReportDp));
|
|
29
30
|
}
|
|
30
31
|
};
|
package/lib/hooks/useWakeUpDp.js
CHANGED
|
@@ -16,7 +16,7 @@ export function useWakeUpDp() {
|
|
|
16
16
|
return {
|
|
17
17
|
dpValue: _dpValue,
|
|
18
18
|
updateDp: dpData => {
|
|
19
|
-
scheduleLogger.debug('useWakeUpDp updateDp', dpData);
|
|
19
|
+
scheduleLogger.debug('=== useWakeUpDp updateDp dpCode:', dpCode, 'dpData: ', dpData);
|
|
20
20
|
updateDp(wakeUpParser.formatter(dpData));
|
|
21
21
|
}
|
|
22
22
|
};
|
package/lib/hooks/useWakeupDp.js
CHANGED
|
@@ -16,7 +16,7 @@ export function useWakeUpDp() {
|
|
|
16
16
|
return {
|
|
17
17
|
dpValue: _dpValue,
|
|
18
18
|
updateDp: dpData => {
|
|
19
|
-
scheduleLogger.debug('useWakeUpDp updateDp', dpData);
|
|
19
|
+
scheduleLogger.debug('=== useWakeUpDp updateDp dpCode:', dpCode, 'dpData: ', dpData);
|
|
20
20
|
updateDp(wakeUpParser.formatter(dpData));
|
|
21
21
|
}
|
|
22
22
|
};
|
package/lib/types/timer.d.ts
CHANGED
|
@@ -107,37 +107,6 @@ export type TTimerReport = {
|
|
|
107
107
|
id: string | number;
|
|
108
108
|
status: boolean;
|
|
109
109
|
};
|
|
110
|
-
/** strip_local_timer 相关类型 - Beacon 灯带本地定时 */
|
|
111
|
-
export type TStripLocalTimerDataPower = {
|
|
112
|
-
power: boolean;
|
|
113
|
-
};
|
|
114
|
-
export type TStripLocalTimerDataBright = {
|
|
115
|
-
brightness: number;
|
|
116
|
-
temperature: number;
|
|
117
|
-
};
|
|
118
|
-
export type TStripLocalTimerDataColor = {
|
|
119
|
-
hue: number;
|
|
120
|
-
saturation: number;
|
|
121
|
-
value: number;
|
|
122
|
-
};
|
|
123
|
-
export type TStripLocalTimerDataScene = {
|
|
124
|
-
sceneId: number;
|
|
125
|
-
};
|
|
126
|
-
export type TStripLocalTimerDpData = TStripLocalTimerDataPower | TStripLocalTimerDataBright | TStripLocalTimerDataColor | TStripLocalTimerDataScene;
|
|
127
|
-
export type TStripLocalTimerData = {
|
|
128
|
-
timerId: number;
|
|
129
|
-
status: boolean;
|
|
130
|
-
time: number;
|
|
131
|
-
repeat: string;
|
|
132
|
-
power?: boolean;
|
|
133
|
-
brightness?: number;
|
|
134
|
-
temperature?: number;
|
|
135
|
-
sceneId?: number;
|
|
136
|
-
hue?: number;
|
|
137
|
-
saturation?: number;
|
|
138
|
-
value?: number;
|
|
139
|
-
mode: number;
|
|
140
|
-
};
|
|
141
110
|
/** bright_adjust_data 相关类型 - Beacon 亮度调节 */
|
|
142
111
|
export type TBrightAdjustData = {
|
|
143
112
|
mode: number;
|
|
@@ -20,6 +20,15 @@ export declare const getDPByProtocol: () => {
|
|
|
20
20
|
readonly COLOUR_DATA: "colour_data";
|
|
21
21
|
readonly COLOUR_DATA_RAW: "colour_data_raw";
|
|
22
22
|
readonly BRIGHT_ADJUST_DATA: "bright_adjust_data";
|
|
23
|
+
readonly FAN_MODE: "fan_mode";
|
|
24
|
+
readonly FAN_DIRECTION: "fan_direction";
|
|
25
|
+
readonly SHAKE: "shake";
|
|
26
|
+
readonly WHITE_SWITCH: "white_switch";
|
|
27
|
+
readonly COLOUR_SWITCH: "colour_switch";
|
|
28
|
+
readonly FAN_SWITCH: "fan_switch";
|
|
29
|
+
readonly FAN_SPEED: "fan_speed";
|
|
30
|
+
readonly FAN_BEEP: "fan_beep";
|
|
31
|
+
readonly STRIP_SCENE: "strip_scene";
|
|
23
32
|
readonly WORK_MODE: "work_mode";
|
|
24
33
|
} | {
|
|
25
34
|
SWITCH_LED: "switch";
|
|
@@ -43,5 +52,14 @@ export declare const getDPByProtocol: () => {
|
|
|
43
52
|
COLOUR_DATA: "colour_data";
|
|
44
53
|
COLOUR_DATA_RAW: "colour_data_raw";
|
|
45
54
|
BRIGHT_ADJUST_DATA: "bright_adjust_data";
|
|
55
|
+
FAN_MODE: "fan_mode";
|
|
56
|
+
FAN_DIRECTION: "fan_direction";
|
|
57
|
+
SHAKE: "shake";
|
|
58
|
+
WHITE_SWITCH: "white_switch";
|
|
59
|
+
COLOUR_SWITCH: "colour_switch";
|
|
60
|
+
FAN_SWITCH: "fan_switch";
|
|
61
|
+
FAN_SPEED: "fan_speed";
|
|
62
|
+
FAN_BEEP: "fan_beep";
|
|
63
|
+
STRIP_SCENE: "strip_scene";
|
|
46
64
|
WORK_MODE: "work_mode";
|
|
47
65
|
};
|
|
@@ -35,6 +35,15 @@ export declare const getDPByProtocol: (schema?: {
|
|
|
35
35
|
readonly COLOUR_DATA: "colour_data";
|
|
36
36
|
readonly COLOUR_DATA_RAW: "colour_data_raw";
|
|
37
37
|
readonly BRIGHT_ADJUST_DATA: "bright_adjust_data";
|
|
38
|
+
readonly FAN_MODE: "fan_mode";
|
|
39
|
+
readonly FAN_DIRECTION: "fan_direction";
|
|
40
|
+
readonly SHAKE: "shake";
|
|
41
|
+
readonly WHITE_SWITCH: "white_switch";
|
|
42
|
+
readonly COLOUR_SWITCH: "colour_switch";
|
|
43
|
+
readonly FAN_SWITCH: "fan_switch";
|
|
44
|
+
readonly FAN_SPEED: "fan_speed";
|
|
45
|
+
readonly FAN_BEEP: "fan_beep";
|
|
46
|
+
readonly STRIP_SCENE: "strip_scene";
|
|
38
47
|
readonly WORK_MODE: "work_mode";
|
|
39
48
|
} | {
|
|
40
49
|
SWITCH_LED: "switch";
|
|
@@ -58,5 +67,14 @@ export declare const getDPByProtocol: (schema?: {
|
|
|
58
67
|
COLOUR_DATA: "colour_data";
|
|
59
68
|
COLOUR_DATA_RAW: "colour_data_raw";
|
|
60
69
|
BRIGHT_ADJUST_DATA: "bright_adjust_data";
|
|
70
|
+
FAN_MODE: "fan_mode";
|
|
71
|
+
FAN_DIRECTION: "fan_direction";
|
|
72
|
+
SHAKE: "shake";
|
|
73
|
+
WHITE_SWITCH: "white_switch";
|
|
74
|
+
COLOUR_SWITCH: "colour_switch";
|
|
75
|
+
FAN_SWITCH: "fan_switch";
|
|
76
|
+
FAN_SPEED: "fan_speed";
|
|
77
|
+
FAN_BEEP: "fan_beep";
|
|
78
|
+
STRIP_SCENE: "strip_scene";
|
|
61
79
|
WORK_MODE: "work_mode";
|
|
62
80
|
};
|