@ray-js/lamp-schedule-core 1.0.5-beta.1 → 1.0.5-beta.2

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,10 @@ 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";
36
40
  /** 模式 */
37
41
  readonly WORK_MODE: "work_mode";
38
42
  };
@@ -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,10 @@ 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',
39
43
  /** 模式 */
40
44
  WORK_MODE: 'work_mode'
41
45
  };
@@ -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,10 @@
1
+ import { TStripLocalTimerData } from '../types';
2
+ export declare class StripLocalTimerFormatter {
3
+ parser(dpValue: string): Partial<TStripLocalTimerData>;
4
+ formatter(data: TStripLocalTimerData): string;
5
+ }
6
+ export declare const stripLocalTimerParser: {
7
+ parser: (dpValue: string) => Partial<TStripLocalTimerData>;
8
+ formatter: (data: TStripLocalTimerData) => string;
9
+ };
10
+ export declare const getStripLocalTimerParser: () => StripLocalTimerFormatter;
@@ -0,0 +1,107 @@
1
+ import "core-js/modules/esnext.iterator.constructor.js";
2
+ import "core-js/modules/esnext.iterator.map.js";
3
+ /* eslint-disable no-console */
4
+ import padStart from 'lodash/padStart';
5
+ import { generateDpStrStep, numToHexString } from '@ray-js/panel-sdk/lib/utils';
6
+ import { scheduleLogger as ScheduleLogger } from '../utils/ScheduleLogger';
7
+ const toHex = function (value) {
8
+ let len = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 2;
9
+ return numToHexString(value).padStart(len, '0');
10
+ };
11
+ export class StripLocalTimerFormatter {
12
+ parser(dpValue) {
13
+ try {
14
+ ScheduleLogger.debug('dpParser ===> StripLocalTimerFormatter parser dpValue:', dpValue);
15
+ if (!dpValue) {
16
+ return {};
17
+ }
18
+ const step = generateDpStrStep(dpValue);
19
+ const step2 = () => step(2).value;
20
+ const step4 = () => step(4).value;
21
+ step2();
22
+ step2();
23
+ step4();
24
+ step2();
25
+ const opt = Array.from(step2().toString(2).padStart(8, '0')).map(i => Number(i));
26
+ const timerId = parseInt(opt.slice(0, 4).join(''), 2);
27
+ const time1 = opt.slice(4).join('');
28
+ const opt1 = Array.from(step2().toString(2).padStart(8, '0')).map(i => Number(i));
29
+ const time2 = parseInt(opt1.slice(0, 4).join('').padStart(8, '0'), 2);
30
+ const time = parseInt(time1 + time2, 2);
31
+ const opt2 = Array.from(step2().toString(2).padStart(8, '0')).map(i => Number(i));
32
+ const status = !!opt2[0];
33
+ const repeat = opt2.slice(1, 8).join('');
34
+ const mode = step2();
35
+ const result = {
36
+ timerId,
37
+ status,
38
+ time,
39
+ repeat,
40
+ mode
41
+ };
42
+ if (mode === 1) {
43
+ const lampPower = step2() === 1;
44
+ result.power = lampPower;
45
+ } else if (mode === 2) {
46
+ const brightness = step2();
47
+ const temperature = step2();
48
+ result.brightness = brightness;
49
+ result.temperature = temperature;
50
+ } else if (mode === 3) {
51
+ const sceneId = step2();
52
+ result.sceneId = sceneId;
53
+ } else if (mode === 4) {
54
+ const hue = step4();
55
+ const saturation = step2();
56
+ const value = step2();
57
+ result.hue = hue;
58
+ result.saturation = saturation;
59
+ result.value = value;
60
+ }
61
+ return result;
62
+ } catch (error) {
63
+ ScheduleLogger.error('dpParser ===> StripLocalTimerFormatter parser error:', error);
64
+ return {};
65
+ }
66
+ }
67
+ formatter(data) {
68
+ try {
69
+ ScheduleLogger.debug('dpParser ===> StripLocalTimerFormatter formatter data:', data);
70
+ const now = new Date();
71
+ const dayStr = toHex(now.getDay(), 2);
72
+ const minuteStr = toHex(now.getMinutes() + now.getHours() * 60, 4);
73
+ const secondStr = toHex(now.getSeconds(), 2);
74
+ const statusStr = data.status ? '1' : '0';
75
+ const timerIdStr = padStart(data.timerId.toString(2), 7, '0');
76
+ const idStr = toHex(parseInt(`${statusStr}${timerIdStr}`, 2), 2);
77
+ const repeatStr = toHex(parseInt(data.repeat.split('').reverse().join(''), 2), 2);
78
+ const startTimeStr = toHex(data.time, 4);
79
+ let dpDataStr = '';
80
+ if (data.power !== undefined) {
81
+ const powerStr = data.power ? '01' : '00';
82
+ dpDataStr = `01${powerStr}`;
83
+ } else if (data.hue !== undefined) {
84
+ const hueStr = toHex(data.hue, 4);
85
+ const saturationStr = toHex(data.saturation || 0);
86
+ const valueStr = toHex(data.value || 0);
87
+ dpDataStr = `04${hueStr}${saturationStr}${valueStr}`;
88
+ } else if (data.sceneId !== undefined) {
89
+ const sceneStr = toHex(data.sceneId);
90
+ dpDataStr = `03${sceneStr}`;
91
+ } else if (data.brightness !== undefined) {
92
+ const brightStr = toHex(data.brightness);
93
+ const temperatureStr = toHex(data.temperature || 0);
94
+ dpDataStr = `02${brightStr}${temperatureStr}`;
95
+ }
96
+ const modeStr = dpDataStr.substring(0, 2);
97
+ return `${'00'}${dayStr}${minuteStr}${secondStr}${idStr}${repeatStr}${startTimeStr}${modeStr}${dpDataStr}`;
98
+ } catch (error) {
99
+ ScheduleLogger.error('dpParser ===> StripLocalTimerFormatter formatter error:', error);
100
+ return '';
101
+ }
102
+ }
103
+ }
104
+ export const stripLocalTimerParser = new StripLocalTimerFormatter();
105
+ export const getStripLocalTimerParser = () => {
106
+ return stripLocalTimerParser;
107
+ };
@@ -18,5 +18,7 @@ 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";
21
23
  readonly WORK_MODE: "work_mode";
22
24
  };
@@ -107,3 +107,45 @@ 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
+ /** bright_adjust_data 相关类型 - Beacon 亮度调节 */
142
+ export type TBrightAdjustData = {
143
+ mode: number;
144
+ brightness: number;
145
+ };
146
+ /** colour_data_raw 相关类型 - Beacon 彩光原始数据 */
147
+ export type TColourDataRaw = {
148
+ hue: number;
149
+ saturation: number;
150
+ value: number;
151
+ };
@@ -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,8 @@ 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";
21
23
  readonly WORK_MODE: "work_mode";
22
24
  } | {
23
25
  SWITCH_LED: "switch";
@@ -39,5 +41,7 @@ export declare const getDPByProtocol: () => {
39
41
  TIMER_REPORT: "timer_report";
40
42
  RTC_TIMER: "rtc_timer";
41
43
  COLOUR_DATA: "colour_data";
44
+ COLOUR_DATA_RAW: "colour_data_raw";
45
+ BRIGHT_ADJUST_DATA: "bright_adjust_data";
42
46
  WORK_MODE: "work_mode";
43
47
  };
@@ -33,6 +33,8 @@ 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";
36
38
  readonly WORK_MODE: "work_mode";
37
39
  } | {
38
40
  SWITCH_LED: "switch";
@@ -54,5 +56,7 @@ export declare const getDPByProtocol: (schema?: {
54
56
  TIMER_REPORT: "timer_report";
55
57
  RTC_TIMER: "rtc_timer";
56
58
  COLOUR_DATA: "colour_data";
59
+ COLOUR_DATA_RAW: "colour_data_raw";
60
+ BRIGHT_ADJUST_DATA: "bright_adjust_data";
57
61
  WORK_MODE: "work_mode";
58
62
  };
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.2",
4
4
  "description": "照明计划模块核心能力",
5
5
  "main": "./lib/index.js",
6
6
  "files": [