@ray-js/lamp-schedule-core 1.0.5-beta.1 → 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.
@@ -19,7 +19,7 @@ export declare const scheduleDpCodes: {
19
19
  readonly CYCLE_TIMING: "cycle_timing";
20
20
  /** 通用本地定时 */
21
21
  readonly LOCAL_TIMER: "local_timer";
22
- /** 灯带本地定时 */
22
+ /** 灯带本地定时 Beacon */
23
23
  readonly STRIP_LOCAL_TIMER: "strip_local_timer";
24
24
  /** 定时同步 一般用于 Beacon */
25
25
  readonly TIMER_SYNC: "timer_sync";
@@ -33,6 +33,23 @@ export declare const scheduleDpCodes: {
33
33
  readonly BRIGHTNESS: "bright_value";
34
34
  /** 彩光 */
35
35
  readonly COLOUR_DATA: "colour_data";
36
+ /** 彩光原始数据 Beacon */
37
+ readonly COLOUR_DATA_RAW: "colour_data_raw";
38
+ /** 亮度调节 Beacon */
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";
36
53
  /** 模式 */
37
54
  readonly WORK_MODE: "work_mode";
38
55
  };
@@ -22,7 +22,7 @@ export const scheduleDpCodes = {
22
22
  [EScheduleType.CYCLE_TIMING]: 'cycle_timing',
23
23
  /** 通用本地定时 */
24
24
  [EScheduleType.LOCAL_TIMER]: 'local_timer',
25
- /** 灯带本地定时 */
25
+ /** 灯带本地定时 Beacon */
26
26
  [EScheduleType.STRIP_LOCAL_TIMER]: 'strip_local_timer',
27
27
  /** 定时同步 一般用于 Beacon */
28
28
  [EScheduleType.TIMER_SYNC]: 'timer_sync',
@@ -36,6 +36,39 @@ export const scheduleDpCodes = {
36
36
  BRIGHTNESS: 'bright_value',
37
37
  /** 彩光 */
38
38
  COLOUR_DATA: 'colour_data',
39
+ /** 彩光原始数据 Beacon */
40
+ COLOUR_DATA_RAW: 'colour_data_raw',
41
+ /** 亮度调节 Beacon */
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
+
39
72
  /** 模式 */
40
73
  WORK_MODE: 'work_mode'
41
74
  };
@@ -0,0 +1,10 @@
1
+ import { TBrightAdjustData } from '../types';
2
+ export declare class BrightAdjustDataFormatter {
3
+ parser(dpValue: string): TBrightAdjustData;
4
+ formatter(data: TBrightAdjustData): string;
5
+ }
6
+ export declare const brightAdjustDataParser: {
7
+ parser: (dpValue: string) => TBrightAdjustData;
8
+ formatter: (data: TBrightAdjustData) => string;
9
+ };
10
+ export declare const getBrightAdjustDataParser: () => BrightAdjustDataFormatter;
@@ -0,0 +1,43 @@
1
+ /* eslint-disable no-console */
2
+
3
+ import { scheduleLogger as ScheduleLogger } from '../utils/ScheduleLogger';
4
+ export class BrightAdjustDataFormatter {
5
+ parser(dpValue) {
6
+ try {
7
+ ScheduleLogger.debug('dpParser ===> BrightAdjustDataFormatter parser dpValue:', dpValue);
8
+ if (!dpValue || dpValue.length < 6) {
9
+ return {
10
+ mode: 0,
11
+ brightness: 0
12
+ };
13
+ }
14
+ const mode = parseInt(dpValue.substring(0, 2), 16);
15
+ const brightness = parseInt(dpValue.substring(2, 6), 16);
16
+ return {
17
+ mode,
18
+ brightness
19
+ };
20
+ } catch (error) {
21
+ ScheduleLogger.error('dpParser ===> BrightAdjustDataFormatter parser error:', error);
22
+ return {
23
+ mode: 0,
24
+ brightness: 0
25
+ };
26
+ }
27
+ }
28
+ formatter(data) {
29
+ try {
30
+ ScheduleLogger.debug('dpParser ===> BrightAdjustDataFormatter formatter data:', data);
31
+ const modeStr = data.mode.toString(16).padStart(2, '0');
32
+ const brightnessStr = data.brightness.toString(16).padStart(4, '0');
33
+ return `${modeStr}${brightnessStr}`;
34
+ } catch (error) {
35
+ ScheduleLogger.error('dpParser ===> BrightAdjustDataFormatter formatter error:', error);
36
+ return '';
37
+ }
38
+ }
39
+ }
40
+ export const brightAdjustDataParser = new BrightAdjustDataFormatter();
41
+ export const getBrightAdjustDataParser = () => {
42
+ return brightAdjustDataParser;
43
+ };
@@ -0,0 +1,14 @@
1
+ import { TColourDataRaw } from '../types';
2
+ export declare class ColourDataRawFormatter {
3
+ parser(dpValue: string): TColourDataRaw;
4
+ formatter(data: {
5
+ hue: number;
6
+ saturation: number;
7
+ value: number;
8
+ } | TColourDataRaw): string;
9
+ }
10
+ export declare const colourDataRawParser: {
11
+ parser: (dpValue: string) => TColourDataRaw;
12
+ formatter: (data: any) => string;
13
+ };
14
+ export declare const getColourDataRawParser: () => ColourDataRawFormatter;
@@ -0,0 +1,56 @@
1
+ /* eslint-disable no-console */
2
+ import { numToHexString } from '@ray-js/panel-sdk/lib/utils';
3
+ import { scheduleLogger as ScheduleLogger } from '../utils/ScheduleLogger';
4
+ const toHex = function (value) {
5
+ let len = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 2;
6
+ return numToHexString(value).padStart(len, '0');
7
+ };
8
+ export class ColourDataRawFormatter {
9
+ parser(dpValue) {
10
+ try {
11
+ ScheduleLogger.debug('dpParser ===> ColourDataRawFormatter parser dpValue:', dpValue);
12
+ if (!dpValue || dpValue.length < 8) {
13
+ return {
14
+ hue: 0,
15
+ saturation: 1000,
16
+ value: 1000
17
+ };
18
+ }
19
+ const hue = parseInt(dpValue.substring(0, 4), 16);
20
+ const saturation = parseInt(dpValue.substring(4, 6), 16) * 10;
21
+ const value = parseInt(dpValue.substring(6, 8), 16) * 10;
22
+ return {
23
+ hue,
24
+ saturation,
25
+ value
26
+ };
27
+ } catch (error) {
28
+ ScheduleLogger.error('dpParser ===> ColourDataRawFormatter parser error:', error);
29
+ return {
30
+ hue: 0,
31
+ saturation: 1000,
32
+ value: 1000
33
+ };
34
+ }
35
+ }
36
+ formatter(data) {
37
+ try {
38
+ ScheduleLogger.debug('dpParser ===> ColourDataRawFormatter formatter data:', data);
39
+ // 兼容两种数据格式: { hue, saturation, value } 或 { h, s, v }
40
+ const h = 'hue' in data ? data.hue : data.h;
41
+ const s = 'saturation' in data ? data.saturation : data.s;
42
+ const v = 'value' in data ? data.value : data.v;
43
+ const hStr = toHex(Math.floor(h), 4);
44
+ const sStr = toHex(Math.floor(s / 10), 2);
45
+ const vStr = toHex(Math.floor(v / 10), 2);
46
+ return `${hStr}${sStr}${vStr}`;
47
+ } catch (error) {
48
+ ScheduleLogger.error('dpParser ===> ColourDataRawFormatter formatter error:', error);
49
+ return '';
50
+ }
51
+ }
52
+ }
53
+ export const colourDataRawParser = new ColourDataRawFormatter();
54
+ export const getColourDataRawParser = () => {
55
+ return colourDataRawParser;
56
+ };
@@ -7,6 +7,9 @@ export { rtcTimerParser, getRtcParser } from './rtcTimer';
7
7
  export { cycleParser, getCycleParser } from './cycle';
8
8
  export { wakeupParserCommon as wakeupParser, getWakeUpParser, WakeUpParser } from './wakeup';
9
9
  export { timerReportParser } from './timerReport';
10
+ export { stripLocalTimerParser, getStripLocalTimerParser } from './stripLocalTimer';
11
+ export { brightAdjustDataParser, getBrightAdjustDataParser } from './brightAdjustData';
12
+ export { colourDataRawParser, getColourDataRawParser } from './colourDataRaw';
10
13
  type DpCode = keyof typeof scheduleDpCodes;
11
14
  /**
12
15
  * 自动匹配 dp 解析函数
@@ -7,6 +7,9 @@ import { getSleepParser } from './sleep';
7
7
  import { rtcTimerParser } from './rtcTimer';
8
8
  import { timerReportParser } from './timerReport';
9
9
  import { getWakeUpParser } from './wakeup';
10
+ import { stripLocalTimerParser } from './stripLocalTimer';
11
+ import { brightAdjustDataParser } from './brightAdjustData';
12
+ import { colourDataRawParser } from './colourDataRaw';
10
13
  export { randomParser, getRandomParser } from './random';
11
14
  export { rhythmParser, getRhythmParser } from './rhythms';
12
15
  export { sleepParserCommon as sleepParser, getSleepParser, SleepParser, sleepParserSigmesh } from './sleep';
@@ -14,6 +17,9 @@ export { rtcTimerParser, getRtcParser } from './rtcTimer';
14
17
  export { cycleParser, getCycleParser } from './cycle';
15
18
  export { wakeupParserCommon as wakeupParser, getWakeUpParser, WakeUpParser } from './wakeup';
16
19
  export { timerReportParser } from './timerReport';
20
+ export { stripLocalTimerParser, getStripLocalTimerParser } from './stripLocalTimer';
21
+ export { brightAdjustDataParser, getBrightAdjustDataParser } from './brightAdjustData';
22
+ export { colourDataRawParser, getColourDataRawParser } from './colourDataRaw';
17
23
  /**
18
24
  * 自动匹配 dp 解析函数
19
25
  *
@@ -37,6 +43,13 @@ export const autoDispatchTransDpFun = dpCode => {
37
43
  return timerReportParser;
38
44
  case scheduleDpCodes.WAKE_UP_MODE:
39
45
  return getWakeUpParser();
46
+ // Beacon 设备专属 dp
47
+ case scheduleDpCodes.STRIP_LOCAL_TIMER:
48
+ return stripLocalTimerParser;
49
+ case scheduleDpCodes.BRIGHT_ADJUST_DATA:
50
+ return brightAdjustDataParser;
51
+ case scheduleDpCodes.COLOUR_DATA_RAW:
52
+ return colourDataRawParser;
40
53
  default:
41
54
  return null;
42
55
  }
@@ -0,0 +1,41 @@
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;
38
+ formatter(data: TStripLocalTimerData): string;
39
+ }
40
+ export declare const stripLocalTimerParser: StripLocalTimerTransformer;
41
+ export declare const getStripLocalTimerParser: () => StripLocalTimerTransformer;
@@ -0,0 +1,275 @@
1
+ import "core-js/modules/esnext.iterator.constructor.js";
2
+ import "core-js/modules/esnext.iterator.map.js";
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,
81
+ status,
82
+ loops: weeks.join(''),
83
+ time,
84
+ mode,
85
+ power,
86
+ dps: {
87
+ [scheduleDpCodes.SWITCH_LED]: power
88
+ }
89
+ };
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
+ }
178
+ }
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');
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);
196
+ }
197
+ formatter(data) {
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 = '';
267
+ }
268
+ } else {
269
+ _action = '00';
270
+ }
271
+ return `${_version}${_week}${_currentTime}${_second}${_enableId}${_weeks}${_time}${_mode}${_action}`;
272
+ }
273
+ }
274
+ export const stripLocalTimerParser = new StripLocalTimerTransformer();
275
+ export const getStripLocalTimerParser = () => new StripLocalTimerTransformer();
@@ -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(() => {
@@ -18,5 +18,16 @@ export declare const useDPByProtocol: () => {
18
18
  readonly TEMPERATURE: "temp_value";
19
19
  readonly BRIGHTNESS: "bright_value";
20
20
  readonly COLOUR_DATA: "colour_data";
21
+ readonly COLOUR_DATA_RAW: "colour_data_raw";
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";
21
32
  readonly WORK_MODE: "work_mode";
22
33
  };
@@ -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
  };
@@ -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
- export declare function useTimerDp(dpCode?: "rtc_timer"): {
3
- dpValue: TRtcTimer;
4
- updateDp: (dps: TRtcTimer) => void;
2
+ import { TStripLocalTimerData } from '../dpParser/stripLocalTimer';
3
+ export declare function useTimerDp(): {
4
+ dpValue: TRtcTimer | TStripLocalTimerData;
5
+ updateDp: (dps: TRtcTimer | TStripLocalTimerData) => void;
5
6
  };
@@ -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
- let dpCode = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : scheduleDpCodes.RTC_TIMER;
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(dpCode);
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: rtcTimerDp => {
22
- updateDp(rtcTimerParser.formatter(rtcTimerDp));
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
  };
@@ -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
  };
@@ -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
  };
@@ -107,3 +107,14 @@ export type TTimerReport = {
107
107
  id: string | number;
108
108
  status: boolean;
109
109
  };
110
+ /** bright_adjust_data 相关类型 - Beacon 亮度调节 */
111
+ export type TBrightAdjustData = {
112
+ mode: number;
113
+ brightness: number;
114
+ };
115
+ /** colour_data_raw 相关类型 - Beacon 彩光原始数据 */
116
+ export type TColourDataRaw = {
117
+ hue: number;
118
+ saturation: number;
119
+ value: number;
120
+ };
@@ -119,6 +119,7 @@ export const navigateToMainApp = (route, params, callback) => {
119
119
  // @ts-ignore
120
120
  events: {
121
121
  [functionalTransDataEventKey](data) {
122
+ scheduleLogger.info('=== get data from main app', data);
122
123
  callback && callback(data);
123
124
  }
124
125
  },
@@ -115,6 +115,10 @@ export declare class Support {
115
115
  * 是否是蓝牙设备
116
116
  * */
117
117
  isBleDevice: (devInfo?: TDeviceInfo) => boolean;
118
+ /**
119
+ * @description 判断是否是 Beacon Device
120
+ */
121
+ isBeaconDevice: (devInfo?: TDeviceInfo) => boolean;
118
122
  /**
119
123
  * @description 是否是 Matter 设备
120
124
  * @param {TDeviceInfo} devInfo - 设备信息
@@ -369,6 +369,13 @@ export class Support {
369
369
  return this.hasCapability(DeviceCapability.BLUETOOTH, devInfo) || this.hasCapability(DeviceCapability.BLEMESH, devInfo) || this.hasCapability(DeviceCapability.SIGMESH, devInfo);
370
370
  };
371
371
 
372
+ /**
373
+ * @description 判断是否是 Beacon Device
374
+ */
375
+ isBeaconDevice = devInfo => {
376
+ return this.hasCapability(DeviceCapability.BEACON, devInfo);
377
+ };
378
+
372
379
  /**
373
380
  * @description 是否是 Matter 设备
374
381
  * @param {TDeviceInfo} devInfo - 设备信息
@@ -18,6 +18,17 @@ export declare const getDPByProtocol: () => {
18
18
  readonly TEMPERATURE: "temp_value";
19
19
  readonly BRIGHTNESS: "bright_value";
20
20
  readonly COLOUR_DATA: "colour_data";
21
+ readonly COLOUR_DATA_RAW: "colour_data_raw";
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";
21
32
  readonly WORK_MODE: "work_mode";
22
33
  } | {
23
34
  SWITCH_LED: "switch";
@@ -39,5 +50,16 @@ export declare const getDPByProtocol: () => {
39
50
  TIMER_REPORT: "timer_report";
40
51
  RTC_TIMER: "rtc_timer";
41
52
  COLOUR_DATA: "colour_data";
53
+ COLOUR_DATA_RAW: "colour_data_raw";
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";
42
64
  WORK_MODE: "work_mode";
43
65
  };
@@ -33,6 +33,17 @@ export declare const getDPByProtocol: (schema?: {
33
33
  readonly TEMPERATURE: "temp_value";
34
34
  readonly BRIGHTNESS: "bright_value";
35
35
  readonly COLOUR_DATA: "colour_data";
36
+ readonly COLOUR_DATA_RAW: "colour_data_raw";
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";
36
47
  readonly WORK_MODE: "work_mode";
37
48
  } | {
38
49
  SWITCH_LED: "switch";
@@ -54,5 +65,16 @@ export declare const getDPByProtocol: (schema?: {
54
65
  TIMER_REPORT: "timer_report";
55
66
  RTC_TIMER: "rtc_timer";
56
67
  COLOUR_DATA: "colour_data";
68
+ COLOUR_DATA_RAW: "colour_data_raw";
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";
57
79
  WORK_MODE: "work_mode";
58
80
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ray-js/lamp-schedule-core",
3
- "version": "1.0.5-beta.1",
3
+ "version": "1.0.5-beta.3",
4
4
  "description": "照明计划模块核心能力",
5
5
  "main": "./lib/index.js",
6
6
  "files": [