@ray-js/lamp-schedule-core 1.0.2-beta-3 → 1.0.2-beta-5
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 +11 -0
- package/lib/config/dpCodes.js +12 -1
- package/lib/conflict/transform.d.ts +2 -2
- package/lib/conflict/transform.js +12 -11
- package/lib/dpParser/__test__/rhythms.test.js +2 -2
- package/lib/dpParser/rhythms.js +5 -3
- package/lib/hooks/useDPByProtocol.d.ts +22 -0
- package/lib/hooks/useDPByProtocol.js +27 -0
- package/lib/hooks/useDevInfo.d.ts +10 -0
- package/lib/hooks/useDevInfo.js +58 -0
- package/lib/hooks/useLampRoad.d.ts +18 -0
- package/lib/hooks/useLampRoad.js +91 -0
- package/lib/utils/ScheduleSupport.d.ts +4 -1
- package/lib/utils/ScheduleSupport.js +12 -2
- package/lib/utils/getCachedLaunchOptions.d.ts +7 -0
- package/lib/utils/getCachedLaunchOptions.js +14 -0
- package/lib/utils/getDPByProtocol.d.ts +43 -0
- package/lib/utils/getDPByProtocol.js +6 -0
- package/lib/utils/matterDeviceUtils.d.ts +58 -0
- package/lib/utils/matterDeviceUtils.js +34 -0
- package/package.json +1 -1
package/lib/config/dpCodes.d.ts
CHANGED
|
@@ -1,4 +1,9 @@
|
|
|
1
1
|
export declare const scheduleDpCodes: {
|
|
2
|
+
/** matter 设备 dp */
|
|
3
|
+
readonly SWITCH_LED_MATTER: "switch";
|
|
4
|
+
readonly HS_COLOR_SET_MATTER: "hs_color_set";
|
|
5
|
+
readonly TEMPERATURE_MATTER: "color_temp_control";
|
|
6
|
+
readonly BRIGHTNESS_MATTER: "brightness_control";
|
|
2
7
|
readonly SWITCH_LED: "switch_led";
|
|
3
8
|
/** 倒计时 */
|
|
4
9
|
readonly COUNTDOWN: "countdown";
|
|
@@ -24,4 +29,10 @@ export declare const scheduleDpCodes: {
|
|
|
24
29
|
readonly RTC_TIMER: "rtc_timer";
|
|
25
30
|
/** 色温 */
|
|
26
31
|
readonly TEMPERATURE: "temp_value";
|
|
32
|
+
/** 亮度 */
|
|
33
|
+
readonly BRIGHTNESS: "bright_value";
|
|
34
|
+
/** 彩光 */
|
|
35
|
+
readonly COLOUR_DATA: "colour_data";
|
|
36
|
+
/** 模式 */
|
|
37
|
+
readonly WORK_MODE: "work_mode";
|
|
27
38
|
};
|
package/lib/config/dpCodes.js
CHANGED
|
@@ -2,6 +2,11 @@ import { EScheduleType } from '../types';
|
|
|
2
2
|
|
|
3
3
|
// 整体计划模块的 dp 映射表
|
|
4
4
|
export const scheduleDpCodes = {
|
|
5
|
+
/** matter 设备 dp */
|
|
6
|
+
SWITCH_LED_MATTER: 'switch',
|
|
7
|
+
HS_COLOR_SET_MATTER: 'hs_color_set',
|
|
8
|
+
TEMPERATURE_MATTER: 'color_temp_control',
|
|
9
|
+
BRIGHTNESS_MATTER: 'brightness_control',
|
|
5
10
|
[EScheduleType.SWITCH_LED]: 'switch_led',
|
|
6
11
|
/** 倒计时 */
|
|
7
12
|
[EScheduleType.COUNTDOWN]: 'countdown',
|
|
@@ -26,5 +31,11 @@ export const scheduleDpCodes = {
|
|
|
26
31
|
/** Rtc定时 */
|
|
27
32
|
[EScheduleType.RTC_TIMER]: 'rtc_timer',
|
|
28
33
|
/** 色温 */
|
|
29
|
-
TEMPERATURE: 'temp_value'
|
|
34
|
+
TEMPERATURE: 'temp_value',
|
|
35
|
+
/** 亮度 */
|
|
36
|
+
BRIGHTNESS: 'bright_value',
|
|
37
|
+
/** 彩光 */
|
|
38
|
+
COLOUR_DATA: 'colour_data',
|
|
39
|
+
/** 模式 */
|
|
40
|
+
WORK_MODE: 'work_mode'
|
|
30
41
|
};
|
|
@@ -21,14 +21,14 @@ export declare const timerListToScheduleList: <T extends TTimerDataUpdate>(data:
|
|
|
21
21
|
*/
|
|
22
22
|
export declare const wakeUpNodeToSchedule: <T extends TWakeUpNode>(data: T) => Schedule;
|
|
23
23
|
/**
|
|
24
|
-
* @description:
|
|
24
|
+
* @description: 唤醒定时转换为适合冲突判断的日程列表
|
|
25
25
|
* @param {TWakeUpNode[]} data
|
|
26
26
|
* @return Schedule[]
|
|
27
27
|
*/
|
|
28
28
|
export declare const wakeUpDataToScheduleList: <T extends TWakeUpNode>(data: T[]) => Schedule[];
|
|
29
29
|
/**
|
|
30
30
|
* TSleepNode => Schedule
|
|
31
|
-
*
|
|
31
|
+
* 入睡数据转换成适合冲突判断的日程对象
|
|
32
32
|
* @param data TSleepNode
|
|
33
33
|
* @returns Schedule
|
|
34
34
|
*/
|
|
@@ -2,6 +2,7 @@ import "core-js/modules/esnext.iterator.constructor.js";
|
|
|
2
2
|
import "core-js/modules/esnext.iterator.for-each.js";
|
|
3
3
|
import "core-js/modules/esnext.iterator.map.js";
|
|
4
4
|
import dayjs from 'dayjs';
|
|
5
|
+
import { cloneDeep } from 'lodash-es';
|
|
5
6
|
import { objectToId } from '../utils/objectToId';
|
|
6
7
|
import { getBackwardOffsetTimeByHourMins, getPreOffsetTimeByHourMins, getTimerStrByMinutes } from '../utils/time';
|
|
7
8
|
import { EScheduleFunctionType } from '../types';
|
|
@@ -72,7 +73,7 @@ export const wakeUpNodeToSchedule = data => {
|
|
|
72
73
|
};
|
|
73
74
|
|
|
74
75
|
/**
|
|
75
|
-
* @description:
|
|
76
|
+
* @description: 唤醒定时转换为适合冲突判断的日程列表
|
|
76
77
|
* @param {TWakeUpNode[]} data
|
|
77
78
|
* @return Schedule[]
|
|
78
79
|
*/
|
|
@@ -84,13 +85,13 @@ export const wakeUpDataToScheduleList = data => {
|
|
|
84
85
|
|
|
85
86
|
/**
|
|
86
87
|
* TSleepNode => Schedule
|
|
87
|
-
*
|
|
88
|
+
* 入睡数据转换成适合冲突判断的日程对象
|
|
88
89
|
* @param data TSleepNode
|
|
89
90
|
* @returns Schedule
|
|
90
91
|
*/
|
|
91
92
|
export const sleepNodeToSchedule = data => {
|
|
92
93
|
const startTime = getPreOffsetTimeByHourMins(data.hour, data.minute, data.step * 5);
|
|
93
|
-
scheduleLogger.debug('sleepNodeToSchedule:', data);
|
|
94
|
+
scheduleLogger.debug('sleepNodeToSchedule:', data, startTime);
|
|
94
95
|
const _data = {
|
|
95
96
|
status: data.onOff,
|
|
96
97
|
weeks: data.loops.split('').map(item => Number(item)),
|
|
@@ -228,28 +229,28 @@ export const transScheduleListToConflictList = foldScheduleList => {
|
|
|
228
229
|
let arr = [];
|
|
229
230
|
try {
|
|
230
231
|
foldScheduleList.forEach(item => {
|
|
232
|
+
// 深度复制定时数据,防止后续数据结构影响
|
|
233
|
+
const clonedDetail = cloneDeep(item.detail);
|
|
231
234
|
if (item.type === EScheduleFunctionType.RANDOM) {
|
|
232
|
-
const list = randomDataToScheduleList(Array.isArray(
|
|
235
|
+
const list = randomDataToScheduleList(Array.isArray(clonedDetail) ? clonedDetail : [clonedDetail]);
|
|
233
236
|
arr = arr.concat(list);
|
|
234
237
|
} else if (item.type === EScheduleFunctionType.CYCLE) {
|
|
235
238
|
const list = cycleDataToScheduleList(Array.isArray(item.detail) ? item.detail : [item.detail]);
|
|
236
239
|
arr = arr.concat(list);
|
|
237
240
|
} else if (item.type === EScheduleFunctionType.TIMER) {
|
|
238
|
-
const list = timerListToScheduleList(Array.isArray(
|
|
241
|
+
const list = timerListToScheduleList(Array.isArray(clonedDetail) ? clonedDetail : [clonedDetail]);
|
|
239
242
|
arr = arr.concat(list);
|
|
240
243
|
} else if (item.type === EScheduleFunctionType.WAKEUP) {
|
|
241
|
-
const list = wakeUpDataToScheduleList(Array.isArray(
|
|
244
|
+
const list = wakeUpDataToScheduleList(Array.isArray(clonedDetail) ? clonedDetail : [clonedDetail]);
|
|
242
245
|
arr = arr.concat(list);
|
|
243
246
|
} else if (item.type === EScheduleFunctionType.SLEEP) {
|
|
244
|
-
const list = sleepDataToScheduleList(Array.isArray(
|
|
247
|
+
const list = sleepDataToScheduleList(Array.isArray(clonedDetail) ? clonedDetail : [clonedDetail]);
|
|
245
248
|
arr = arr.concat(list);
|
|
246
249
|
} else if (item.type === EScheduleFunctionType.RHYTHM) {
|
|
247
|
-
|
|
248
|
-
const list = rhythmToSchedule(Array.isArray(item.detail) ? item === null || item === void 0 || (_item$detail = item.detail) === null || _item$detail === void 0 ? void 0 : _item$detail[0] : item.detail);
|
|
250
|
+
const list = rhythmToSchedule(Array.isArray(clonedDetail) ? clonedDetail === null || clonedDetail === void 0 ? void 0 : clonedDetail[0] : clonedDetail);
|
|
249
251
|
arr = arr.concat(list);
|
|
250
252
|
} else if (item.type === EScheduleFunctionType.COUNTDOWN) {
|
|
251
|
-
|
|
252
|
-
const list = countdownToSchedule(Array.isArray(item.detail) ? item === null || item === void 0 || (_item$detail2 = item.detail) === null || _item$detail2 === void 0 ? void 0 : _item$detail2[0] : item.detail);
|
|
253
|
+
const list = countdownToSchedule(Array.isArray(clonedDetail) ? clonedDetail === null || clonedDetail === void 0 ? void 0 : clonedDetail[0] : clonedDetail);
|
|
253
254
|
arr = arr.concat(list);
|
|
254
255
|
} else {
|
|
255
256
|
scheduleLogger.error('getScheduleListByType', item, '未匹配到类型');
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import "core-js/modules/esnext.iterator.constructor.js";
|
|
2
2
|
import "core-js/modules/esnext.iterator.for-each.js";
|
|
3
3
|
import { rhythmParser } from '../rhythms';
|
|
4
|
-
import {
|
|
4
|
+
import { getDPByProtocol } from '../../utils/getDPByProtocol';
|
|
5
5
|
jest.mock('../../utils/ScheduleLogger', () => {
|
|
6
6
|
const logger = {
|
|
7
7
|
debug: jest.fn(),
|
|
@@ -27,7 +27,7 @@ describe('RhythmParser', () => {
|
|
|
27
27
|
return {
|
|
28
28
|
isSigMeshDevice: jest.fn().mockReturnValue(false),
|
|
29
29
|
isSupportDp: jest.fn().mockImplementation(dp => {
|
|
30
|
-
if (dp ===
|
|
30
|
+
if (dp === getDPByProtocol().TEMPERATURE) {
|
|
31
31
|
return isSupportTemp;
|
|
32
32
|
}
|
|
33
33
|
return true;
|
package/lib/dpParser/rhythms.js
CHANGED
|
@@ -5,9 +5,9 @@ import { defaultValue } from '../config/rhythms/defaultValue';
|
|
|
5
5
|
import { scheduleDpCodes } from '../config/dpCodes';
|
|
6
6
|
import { scheduleLogger as ScheduleLogger } from '../utils/ScheduleLogger';
|
|
7
7
|
import { getSupportIns } from '../hooks/useCommonSupport';
|
|
8
|
+
import { getDPByProtocol } from '../utils/getDPByProtocol';
|
|
8
9
|
const {
|
|
9
|
-
RHYTHM_MODE
|
|
10
|
-
TEMPERATURE
|
|
10
|
+
RHYTHM_MODE
|
|
11
11
|
} = scheduleDpCodes;
|
|
12
12
|
const to16 = num => {
|
|
13
13
|
return numToHexString(num);
|
|
@@ -95,7 +95,9 @@ export default class RhythmFormatter {
|
|
|
95
95
|
const weekStr = [...weeks].reverse().join('').padStart(8, '0');
|
|
96
96
|
const number = rhythms.length;
|
|
97
97
|
const weeksValue = parseInt(weekStr, 2);
|
|
98
|
-
|
|
98
|
+
// 兼容 matter 设备,需要获取 dpCodes 来判断是否支持色温
|
|
99
|
+
const dpCodes = getDPByProtocol();
|
|
100
|
+
const isSupportWhiteTemp = support.isSupportDp(dpCodes.TEMPERATURE);
|
|
99
101
|
return `${to16(version)}${to16(Number(power))}${to16(mode)}${to16(weeksValue)}${to16(number)}${rhythms.map(_ref => {
|
|
100
102
|
let {
|
|
101
103
|
power,
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
export declare const useDPByProtocol: () => {
|
|
2
|
+
readonly SWITCH_LED_MATTER: "switch";
|
|
3
|
+
readonly HS_COLOR_SET_MATTER: "hs_color_set";
|
|
4
|
+
readonly TEMPERATURE_MATTER: "color_temp_control";
|
|
5
|
+
readonly BRIGHTNESS_MATTER: "brightness_control";
|
|
6
|
+
readonly SWITCH_LED: "switch_led";
|
|
7
|
+
readonly COUNTDOWN: "countdown";
|
|
8
|
+
readonly RANDOM_TIMING: "random_timing";
|
|
9
|
+
readonly RHYTHM_MODE: "rhythm_mode";
|
|
10
|
+
readonly SLEEP_MODE: "sleep_mode";
|
|
11
|
+
readonly WAKE_UP_MODE: "wakeup_mode";
|
|
12
|
+
readonly CYCLE_TIMING: "cycle_timing";
|
|
13
|
+
readonly LOCAL_TIMER: "local_timer";
|
|
14
|
+
readonly STRIP_LOCAL_TIMER: "strip_local_timer";
|
|
15
|
+
readonly TIMER_SYNC: "timer_sync";
|
|
16
|
+
readonly TIMER_REPORT: "timer_report";
|
|
17
|
+
readonly RTC_TIMER: "rtc_timer";
|
|
18
|
+
readonly TEMPERATURE: "temp_value";
|
|
19
|
+
readonly BRIGHTNESS: "bright_value";
|
|
20
|
+
readonly COLOUR_DATA: "colour_data";
|
|
21
|
+
readonly WORK_MODE: "work_mode";
|
|
22
|
+
};
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import _objectSpread from "@babel/runtime/helpers/esm/objectSpread2";
|
|
2
|
+
import { scheduleDpCodes } from '../config/dpCodes';
|
|
3
|
+
import { getCachedDevIdOrGroupIdOptions } from '../utils/getCachedLaunchOptions';
|
|
4
|
+
import { isMatterDevice } from '../utils/matterDeviceUtils';
|
|
5
|
+
import useDevInfo from './useDevInfo';
|
|
6
|
+
import { EScheduleType } from '../types';
|
|
7
|
+
import { useEffect, useState } from 'react';
|
|
8
|
+
export const useDPByProtocol = () => {
|
|
9
|
+
var _devInfo$schema;
|
|
10
|
+
const {
|
|
11
|
+
devId,
|
|
12
|
+
groupId
|
|
13
|
+
} = getCachedDevIdOrGroupIdOptions();
|
|
14
|
+
const devInfo = useDevInfo(devId, groupId);
|
|
15
|
+
const [dpCodes, setDpCodes] = useState(scheduleDpCodes);
|
|
16
|
+
useEffect(() => {
|
|
17
|
+
if (isMatterDevice(devInfo === null || devInfo === void 0 ? void 0 : devInfo.schema)) {
|
|
18
|
+
const newScheduleDpCodes = _objectSpread(_objectSpread({}, scheduleDpCodes), {}, {
|
|
19
|
+
[scheduleDpCodes[EScheduleType.SWITCH_LED]]: scheduleDpCodes.SWITCH_LED_MATTER,
|
|
20
|
+
TEMPERATURE: scheduleDpCodes.TEMPERATURE_MATTER,
|
|
21
|
+
BRIGHTNESS: scheduleDpCodes.BRIGHTNESS_MATTER
|
|
22
|
+
});
|
|
23
|
+
setDpCodes(newScheduleDpCodes);
|
|
24
|
+
}
|
|
25
|
+
}, [devInfo === null || devInfo === void 0 || (_devInfo$schema = devInfo.schema) === null || _devInfo$schema === void 0 ? void 0 : _devInfo$schema.length]);
|
|
26
|
+
return dpCodes;
|
|
27
|
+
};
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { GroupDevInfo } from '../types';
|
|
2
|
+
import { TDeviceInfo } from '../utils/ScheduleSupport';
|
|
3
|
+
/**
|
|
4
|
+
* 获取设备或群组信息
|
|
5
|
+
* @param devId 设备ID
|
|
6
|
+
* @param groupId 群组ID
|
|
7
|
+
* @returns TDeviceInfo | GroupDevInfo | null
|
|
8
|
+
*/
|
|
9
|
+
declare const useDevInfo: (devId: any, groupId: any) => TDeviceInfo | GroupDevInfo | null;
|
|
10
|
+
export default useDevInfo;
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import { getDeviceInfo, getGroupInfo } from '@ray-js/ray';
|
|
2
|
+
import { useEffect, useRef, useState } from 'react';
|
|
3
|
+
import { scheduleLogger } from '../utils/ScheduleLogger';
|
|
4
|
+
import { getCachedDevIdOrGroupIdOptions } from '../utils/getCachedLaunchOptions';
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* 获取设备或群组信息
|
|
8
|
+
* @param devId 设备ID
|
|
9
|
+
* @param groupId 群组ID
|
|
10
|
+
* @returns TDeviceInfo | GroupDevInfo | null
|
|
11
|
+
*/
|
|
12
|
+
const useDevInfo = (devId, groupId) => {
|
|
13
|
+
const isInit = useRef(false);
|
|
14
|
+
const [devInfo, setDevInfo] = useState(null);
|
|
15
|
+
const {
|
|
16
|
+
groupId: cachedGroupId,
|
|
17
|
+
devId: cachedDevId
|
|
18
|
+
} = getCachedDevIdOrGroupIdOptions();
|
|
19
|
+
const _devId = devId || cachedDevId;
|
|
20
|
+
const _groupId = groupId || cachedGroupId;
|
|
21
|
+
useEffect(() => {
|
|
22
|
+
if (isInit.current) {
|
|
23
|
+
return;
|
|
24
|
+
}
|
|
25
|
+
if (_groupId) {
|
|
26
|
+
getGroupInfo({
|
|
27
|
+
groupId: _groupId,
|
|
28
|
+
success: res => {
|
|
29
|
+
var _res$deviceList;
|
|
30
|
+
const deviceSchema = (_res$deviceList = res.deviceList) === null || _res$deviceList === void 0 || (_res$deviceList = _res$deviceList[0]) === null || _res$deviceList === void 0 ? void 0 : _res$deviceList.schema;
|
|
31
|
+
// 融合 deviceSchema 和 groupSchema 数据,优先使用 groupSchema
|
|
32
|
+
res.schema = [...(res.schema || []), ...(deviceSchema || [])];
|
|
33
|
+
isInit.current = true;
|
|
34
|
+
setDevInfo(res);
|
|
35
|
+
},
|
|
36
|
+
fail: err => {
|
|
37
|
+
scheduleLogger.error('getGroupInfo fail: ', err);
|
|
38
|
+
setDevInfo(null);
|
|
39
|
+
}
|
|
40
|
+
});
|
|
41
|
+
}
|
|
42
|
+
if (_devId) {
|
|
43
|
+
getDeviceInfo({
|
|
44
|
+
deviceId: _devId,
|
|
45
|
+
success: res => {
|
|
46
|
+
setDevInfo(res);
|
|
47
|
+
isInit.current = true;
|
|
48
|
+
},
|
|
49
|
+
fail: err => {
|
|
50
|
+
setDevInfo(null);
|
|
51
|
+
scheduleLogger.error('getDeviceInfo fail: ', err);
|
|
52
|
+
}
|
|
53
|
+
});
|
|
54
|
+
}
|
|
55
|
+
}, [_groupId, _devId]);
|
|
56
|
+
return devInfo;
|
|
57
|
+
};
|
|
58
|
+
export default useDevInfo;
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
type dpCode = string;
|
|
2
|
+
export declare enum Road {
|
|
3
|
+
road1 = "road1",
|
|
4
|
+
road2 = "road2",
|
|
5
|
+
road3 = "road3",
|
|
6
|
+
road4 = "road4",
|
|
7
|
+
road5 = "road5",
|
|
8
|
+
none = 0
|
|
9
|
+
}
|
|
10
|
+
type Params = {
|
|
11
|
+
[Road.road1]: dpCode[][];
|
|
12
|
+
[Road.road2]: dpCode[][];
|
|
13
|
+
[Road.road3]: dpCode[][];
|
|
14
|
+
[Road.road4]: dpCode[][];
|
|
15
|
+
[Road.road5]: dpCode[][];
|
|
16
|
+
};
|
|
17
|
+
export declare const useLampRoad: (devId: string, groupId: string, _params?: Params) => Road;
|
|
18
|
+
export default useLampRoad;
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
import "core-js/modules/esnext.iterator.constructor.js";
|
|
2
|
+
import "core-js/modules/esnext.iterator.every.js";
|
|
3
|
+
import "core-js/modules/esnext.iterator.find.js";
|
|
4
|
+
import "core-js/modules/esnext.iterator.map.js";
|
|
5
|
+
import "core-js/modules/esnext.iterator.some.js";
|
|
6
|
+
// 判断照明灯是几路
|
|
7
|
+
import { useMemo } from 'react';
|
|
8
|
+
import { scheduleDpCodes } from 'src/config/dpCodes';
|
|
9
|
+
import useDevInfo from './useDevInfo';
|
|
10
|
+
export let Road = /*#__PURE__*/function (Road) {
|
|
11
|
+
Road["road1"] = "road1";
|
|
12
|
+
Road["road2"] = "road2";
|
|
13
|
+
Road["road3"] = "road3";
|
|
14
|
+
Road["road4"] = "road4";
|
|
15
|
+
Road["road5"] = "road5";
|
|
16
|
+
Road[Road["none"] = null] = "none";
|
|
17
|
+
return Road;
|
|
18
|
+
}({});
|
|
19
|
+
/**
|
|
20
|
+
* 检查设备是否支持指定的 DP 码组合
|
|
21
|
+
* @param dpCodeList 设备支持的 DP 码列表
|
|
22
|
+
* @param requiredDps 需要的 DP 码组合(任一组合满足即可)
|
|
23
|
+
* @returns 是否支持
|
|
24
|
+
*/
|
|
25
|
+
const checkDpsSupported = (dpCodeList, requiredDps) => {
|
|
26
|
+
return requiredDps.some(dps => dps.every(dp => dpCodeList.includes(dp)));
|
|
27
|
+
};
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* 检测设备支持的照明路数
|
|
31
|
+
* @param dpCodeList 设备支持的 DP 码列表
|
|
32
|
+
* @param config 路数配置
|
|
33
|
+
* @returns 检测到的路数
|
|
34
|
+
*/
|
|
35
|
+
const detectLampRoad = (dpCodeList, config) => {
|
|
36
|
+
const roadConfigs = [{
|
|
37
|
+
road: Road.road5,
|
|
38
|
+
requiredDps: config[Road.road5]
|
|
39
|
+
}, {
|
|
40
|
+
road: Road.road4,
|
|
41
|
+
requiredDps: config[Road.road4]
|
|
42
|
+
}, {
|
|
43
|
+
road: Road.road3,
|
|
44
|
+
requiredDps: config[Road.road3]
|
|
45
|
+
}, {
|
|
46
|
+
road: Road.road2,
|
|
47
|
+
requiredDps: config[Road.road2]
|
|
48
|
+
}, {
|
|
49
|
+
road: Road.road1,
|
|
50
|
+
requiredDps: config[Road.road1]
|
|
51
|
+
}];
|
|
52
|
+
const supportedRoad = roadConfigs.find(_ref => {
|
|
53
|
+
let {
|
|
54
|
+
requiredDps
|
|
55
|
+
} = _ref;
|
|
56
|
+
return checkDpsSupported(dpCodeList, requiredDps);
|
|
57
|
+
});
|
|
58
|
+
return (supportedRoad === null || supportedRoad === void 0 ? void 0 : supportedRoad.road) || Road.none;
|
|
59
|
+
};
|
|
60
|
+
|
|
61
|
+
/**
|
|
62
|
+
* 获取默认路数配置
|
|
63
|
+
* @returns 默认配置
|
|
64
|
+
*/
|
|
65
|
+
const getDefaultRoadConfig = () => ({
|
|
66
|
+
[Road.road1]: [[scheduleDpCodes.BRIGHTNESS], [scheduleDpCodes.BRIGHTNESS_MATTER]],
|
|
67
|
+
[Road.road2]: [[scheduleDpCodes.BRIGHTNESS, scheduleDpCodes.TEMPERATURE], [scheduleDpCodes.BRIGHTNESS_MATTER, scheduleDpCodes.TEMPERATURE_MATTER]],
|
|
68
|
+
[Road.road3]: [[scheduleDpCodes.COLOUR_DATA], [scheduleDpCodes.HS_COLOR_SET_MATTER, scheduleDpCodes.BRIGHTNESS_MATTER]],
|
|
69
|
+
[Road.road4]: [[scheduleDpCodes.COLOUR_DATA, scheduleDpCodes.BRIGHTNESS], [scheduleDpCodes.HS_COLOR_SET_MATTER, scheduleDpCodes.BRIGHTNESS_MATTER, scheduleDpCodes.BRIGHTNESS]],
|
|
70
|
+
[Road.road5]: [[scheduleDpCodes.COLOUR_DATA, scheduleDpCodes.BRIGHTNESS, scheduleDpCodes.TEMPERATURE], [scheduleDpCodes.HS_COLOR_SET_MATTER, scheduleDpCodes.BRIGHTNESS_MATTER, scheduleDpCodes.TEMPERATURE_MATTER]]
|
|
71
|
+
});
|
|
72
|
+
let _lampRoad = Road.none;
|
|
73
|
+
export const useLampRoad = (devId, groupId, _params) => {
|
|
74
|
+
var _devInfo$schema;
|
|
75
|
+
const devInfo = useDevInfo(devId, groupId);
|
|
76
|
+
const dpSchemaDpCodeList = (devInfo === null || devInfo === void 0 || (_devInfo$schema = devInfo.schema) === null || _devInfo$schema === void 0 ? void 0 : _devInfo$schema.map(item => item.code)) || [];
|
|
77
|
+
const params = _params || getDefaultRoadConfig();
|
|
78
|
+
const lampRoad = useMemo(() => {
|
|
79
|
+
if (_lampRoad !== Road.none) {
|
|
80
|
+
return _lampRoad;
|
|
81
|
+
}
|
|
82
|
+
if (!dpSchemaDpCodeList.length) {
|
|
83
|
+
return Road.none;
|
|
84
|
+
}
|
|
85
|
+
const lampRoadResult = detectLampRoad(dpSchemaDpCodeList, params);
|
|
86
|
+
_lampRoad = lampRoadResult;
|
|
87
|
+
return lampRoadResult;
|
|
88
|
+
}, [dpSchemaDpCodeList === null || dpSchemaDpCodeList === void 0 ? void 0 : dpSchemaDpCodeList.length, params]);
|
|
89
|
+
return lampRoad;
|
|
90
|
+
};
|
|
91
|
+
export default useLampRoad;
|
|
@@ -117,8 +117,11 @@ export declare class Support {
|
|
|
117
117
|
isBleDevice: (devInfo?: TDeviceInfo) => boolean;
|
|
118
118
|
/**
|
|
119
119
|
* @description 是否是 Matter 设备
|
|
120
|
+
* @param {TDeviceInfo} devInfo - 设备信息
|
|
121
|
+
* @param {boolean} isMatter - 是否是 Matter 设备, 如果传入则直接返回, 之前 app 返回数据有问题
|
|
122
|
+
* @returns {boolean} - 是否是 Matter 设备
|
|
120
123
|
*/
|
|
121
|
-
isMatterDevice(devInfo?: TDeviceInfo): boolean;
|
|
124
|
+
isMatterDevice(devInfo?: TDeviceInfo, isMatter?: boolean): boolean;
|
|
122
125
|
/**
|
|
123
126
|
* @description 是否是 涂鸦 Matter 设备
|
|
124
127
|
*/
|
|
@@ -97,6 +97,7 @@ export class Support {
|
|
|
97
97
|
getGroupInfo({
|
|
98
98
|
groupId,
|
|
99
99
|
success: res => {
|
|
100
|
+
var _res$deviceList;
|
|
100
101
|
this.groupDevInfo = res;
|
|
101
102
|
ScheduleLogger.debug('getGroupInfo groupId: ', groupId);
|
|
102
103
|
ScheduleLogger.debug('getGroupInfo success1: ', res);
|
|
@@ -109,7 +110,10 @@ export class Support {
|
|
|
109
110
|
dpCode && setDpState(dpCode, res.dps[dpId]);
|
|
110
111
|
});
|
|
111
112
|
Object.keys(dpMap).length && initDpState(dpMap);
|
|
112
|
-
|
|
113
|
+
const deviceSchema = (_res$deviceList = res.deviceList) === null || _res$deviceList === void 0 || (_res$deviceList = _res$deviceList[0]) === null || _res$deviceList === void 0 ? void 0 : _res$deviceList.schema;
|
|
114
|
+
// 融合 deviceSchema 和 groupSchema 数据,优先使用 groupSchema
|
|
115
|
+
res.schema = [...(res.schema || []), ...(deviceSchema || [])];
|
|
116
|
+
resolve(true);
|
|
113
117
|
},
|
|
114
118
|
fail: err => {
|
|
115
119
|
this.groupDevInfo = {};
|
|
@@ -343,9 +347,15 @@ export class Support {
|
|
|
343
347
|
|
|
344
348
|
/**
|
|
345
349
|
* @description 是否是 Matter 设备
|
|
350
|
+
* @param {TDeviceInfo} devInfo - 设备信息
|
|
351
|
+
* @param {boolean} isMatter - 是否是 Matter 设备, 如果传入则直接返回, 之前 app 返回数据有问题
|
|
352
|
+
* @returns {boolean} - 是否是 Matter 设备
|
|
346
353
|
*/
|
|
347
|
-
isMatterDevice(devInfo) {
|
|
354
|
+
isMatterDevice(devInfo, isMatter) {
|
|
348
355
|
var _this$devInfo3;
|
|
356
|
+
if (isMatter !== undefined) {
|
|
357
|
+
return isMatter;
|
|
358
|
+
}
|
|
349
359
|
if (devInfo) {
|
|
350
360
|
return !!devInfo.isMatter;
|
|
351
361
|
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import _objectSpread from "@babel/runtime/helpers/esm/objectSpread2";
|
|
2
|
+
import { getLaunchOptionsSync } from '@ray-js/ray';
|
|
3
|
+
let _launchOptions = null;
|
|
4
|
+
export const getCachedDevIdOrGroupIdOptions = () => {
|
|
5
|
+
var _launchOptions$query;
|
|
6
|
+
if (_launchOptions && Object.keys(_launchOptions).length > 0) {
|
|
7
|
+
return _launchOptions;
|
|
8
|
+
}
|
|
9
|
+
const launchOptions = getLaunchOptionsSync();
|
|
10
|
+
_launchOptions = _objectSpread(_objectSpread({}, (launchOptions === null || launchOptions === void 0 ? void 0 : launchOptions.query) || {}), {}, {
|
|
11
|
+
devId: (launchOptions === null || launchOptions === void 0 || (_launchOptions$query = launchOptions.query) === null || _launchOptions$query === void 0 ? void 0 : _launchOptions$query.deviceId) || ''
|
|
12
|
+
});
|
|
13
|
+
return _launchOptions;
|
|
14
|
+
};
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
export declare const getDPByProtocol: () => {
|
|
2
|
+
readonly SWITCH_LED_MATTER: "switch";
|
|
3
|
+
readonly HS_COLOR_SET_MATTER: "hs_color_set";
|
|
4
|
+
readonly TEMPERATURE_MATTER: "color_temp_control";
|
|
5
|
+
readonly BRIGHTNESS_MATTER: "brightness_control";
|
|
6
|
+
readonly SWITCH_LED: "switch_led";
|
|
7
|
+
readonly COUNTDOWN: "countdown";
|
|
8
|
+
readonly RANDOM_TIMING: "random_timing";
|
|
9
|
+
readonly RHYTHM_MODE: "rhythm_mode";
|
|
10
|
+
readonly SLEEP_MODE: "sleep_mode";
|
|
11
|
+
readonly WAKE_UP_MODE: "wakeup_mode";
|
|
12
|
+
readonly CYCLE_TIMING: "cycle_timing";
|
|
13
|
+
readonly LOCAL_TIMER: "local_timer";
|
|
14
|
+
readonly STRIP_LOCAL_TIMER: "strip_local_timer";
|
|
15
|
+
readonly TIMER_SYNC: "timer_sync";
|
|
16
|
+
readonly TIMER_REPORT: "timer_report";
|
|
17
|
+
readonly RTC_TIMER: "rtc_timer";
|
|
18
|
+
readonly TEMPERATURE: "temp_value";
|
|
19
|
+
readonly BRIGHTNESS: "bright_value";
|
|
20
|
+
readonly COLOUR_DATA: "colour_data";
|
|
21
|
+
readonly WORK_MODE: "work_mode";
|
|
22
|
+
} | {
|
|
23
|
+
SWITCH_LED: "switch";
|
|
24
|
+
TEMPERATURE: "color_temp_control";
|
|
25
|
+
BRIGHTNESS: "brightness_control";
|
|
26
|
+
SWITCH_LED_MATTER: "switch";
|
|
27
|
+
HS_COLOR_SET_MATTER: "hs_color_set";
|
|
28
|
+
TEMPERATURE_MATTER: "color_temp_control";
|
|
29
|
+
BRIGHTNESS_MATTER: "brightness_control";
|
|
30
|
+
COUNTDOWN: "countdown";
|
|
31
|
+
RANDOM_TIMING: "random_timing";
|
|
32
|
+
RHYTHM_MODE: "rhythm_mode";
|
|
33
|
+
SLEEP_MODE: "sleep_mode";
|
|
34
|
+
WAKE_UP_MODE: "wakeup_mode";
|
|
35
|
+
CYCLE_TIMING: "cycle_timing";
|
|
36
|
+
LOCAL_TIMER: "local_timer";
|
|
37
|
+
STRIP_LOCAL_TIMER: "strip_local_timer";
|
|
38
|
+
TIMER_SYNC: "timer_sync";
|
|
39
|
+
TIMER_REPORT: "timer_report";
|
|
40
|
+
RTC_TIMER: "rtc_timer";
|
|
41
|
+
COLOUR_DATA: "colour_data";
|
|
42
|
+
WORK_MODE: "work_mode";
|
|
43
|
+
};
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { getScheduleCache } from '../utils/ScheduleCache';
|
|
2
|
+
import { getDPByProtocol as getDPByProtocolUtil } from './matterDeviceUtils';
|
|
3
|
+
export const getDPByProtocol = () => {
|
|
4
|
+
const devInfo = getScheduleCache('devInfo');
|
|
5
|
+
return getDPByProtocolUtil(devInfo === null || devInfo === void 0 ? void 0 : devInfo.schema);
|
|
6
|
+
};
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 检查设备是否支持 Matter 协议
|
|
3
|
+
* @param schema 设备 schema 数组
|
|
4
|
+
* @returns 是否为 Matter 设备
|
|
5
|
+
*/
|
|
6
|
+
export declare const isMatterDevice: (schema?: {
|
|
7
|
+
code: string;
|
|
8
|
+
}[]) => boolean;
|
|
9
|
+
/**
|
|
10
|
+
* 获取根据协议类型调整的 DP 码配置
|
|
11
|
+
* @param schema 设备 schema 数组
|
|
12
|
+
* @returns 调整后的 DP 码配置
|
|
13
|
+
*/
|
|
14
|
+
export declare const getDPByProtocol: (schema?: {
|
|
15
|
+
code: string;
|
|
16
|
+
}[]) => {
|
|
17
|
+
readonly SWITCH_LED_MATTER: "switch";
|
|
18
|
+
readonly HS_COLOR_SET_MATTER: "hs_color_set";
|
|
19
|
+
readonly TEMPERATURE_MATTER: "color_temp_control";
|
|
20
|
+
readonly BRIGHTNESS_MATTER: "brightness_control";
|
|
21
|
+
readonly SWITCH_LED: "switch_led";
|
|
22
|
+
readonly COUNTDOWN: "countdown";
|
|
23
|
+
readonly RANDOM_TIMING: "random_timing";
|
|
24
|
+
readonly RHYTHM_MODE: "rhythm_mode";
|
|
25
|
+
readonly SLEEP_MODE: "sleep_mode";
|
|
26
|
+
readonly WAKE_UP_MODE: "wakeup_mode";
|
|
27
|
+
readonly CYCLE_TIMING: "cycle_timing";
|
|
28
|
+
readonly LOCAL_TIMER: "local_timer";
|
|
29
|
+
readonly STRIP_LOCAL_TIMER: "strip_local_timer";
|
|
30
|
+
readonly TIMER_SYNC: "timer_sync";
|
|
31
|
+
readonly TIMER_REPORT: "timer_report";
|
|
32
|
+
readonly RTC_TIMER: "rtc_timer";
|
|
33
|
+
readonly TEMPERATURE: "temp_value";
|
|
34
|
+
readonly BRIGHTNESS: "bright_value";
|
|
35
|
+
readonly COLOUR_DATA: "colour_data";
|
|
36
|
+
readonly WORK_MODE: "work_mode";
|
|
37
|
+
} | {
|
|
38
|
+
SWITCH_LED: "switch";
|
|
39
|
+
TEMPERATURE: "color_temp_control";
|
|
40
|
+
BRIGHTNESS: "brightness_control";
|
|
41
|
+
SWITCH_LED_MATTER: "switch";
|
|
42
|
+
HS_COLOR_SET_MATTER: "hs_color_set";
|
|
43
|
+
TEMPERATURE_MATTER: "color_temp_control";
|
|
44
|
+
BRIGHTNESS_MATTER: "brightness_control";
|
|
45
|
+
COUNTDOWN: "countdown";
|
|
46
|
+
RANDOM_TIMING: "random_timing";
|
|
47
|
+
RHYTHM_MODE: "rhythm_mode";
|
|
48
|
+
SLEEP_MODE: "sleep_mode";
|
|
49
|
+
WAKE_UP_MODE: "wakeup_mode";
|
|
50
|
+
CYCLE_TIMING: "cycle_timing";
|
|
51
|
+
LOCAL_TIMER: "local_timer";
|
|
52
|
+
STRIP_LOCAL_TIMER: "strip_local_timer";
|
|
53
|
+
TIMER_SYNC: "timer_sync";
|
|
54
|
+
TIMER_REPORT: "timer_report";
|
|
55
|
+
RTC_TIMER: "rtc_timer";
|
|
56
|
+
COLOUR_DATA: "colour_data";
|
|
57
|
+
WORK_MODE: "work_mode";
|
|
58
|
+
};
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import _objectSpread from "@babel/runtime/helpers/esm/objectSpread2";
|
|
2
|
+
import "core-js/modules/esnext.iterator.constructor.js";
|
|
3
|
+
import "core-js/modules/esnext.iterator.some.js";
|
|
4
|
+
import { scheduleDpCodes } from '../config/dpCodes';
|
|
5
|
+
import { EScheduleType } from '../types';
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* 检查设备是否支持 Matter 协议
|
|
9
|
+
* @param schema 设备 schema 数组
|
|
10
|
+
* @returns 是否为 Matter 设备
|
|
11
|
+
*/
|
|
12
|
+
export const isMatterDevice = schema => {
|
|
13
|
+
if (!schema || !Array.isArray(schema)) {
|
|
14
|
+
return false;
|
|
15
|
+
}
|
|
16
|
+
const matterDpCodeList = [scheduleDpCodes.SWITCH_LED_MATTER, scheduleDpCodes.HS_COLOR_SET_MATTER, scheduleDpCodes.TEMPERATURE_MATTER, scheduleDpCodes.BRIGHTNESS_MATTER];
|
|
17
|
+
return schema.some(item => matterDpCodeList.includes(item.code));
|
|
18
|
+
};
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* 获取根据协议类型调整的 DP 码配置
|
|
22
|
+
* @param schema 设备 schema 数组
|
|
23
|
+
* @returns 调整后的 DP 码配置
|
|
24
|
+
*/
|
|
25
|
+
export const getDPByProtocol = schema => {
|
|
26
|
+
if (isMatterDevice(schema)) {
|
|
27
|
+
return _objectSpread(_objectSpread({}, scheduleDpCodes), {}, {
|
|
28
|
+
[EScheduleType.SWITCH_LED]: scheduleDpCodes.SWITCH_LED_MATTER,
|
|
29
|
+
TEMPERATURE: scheduleDpCodes.TEMPERATURE_MATTER,
|
|
30
|
+
BRIGHTNESS: scheduleDpCodes.BRIGHTNESS_MATTER
|
|
31
|
+
});
|
|
32
|
+
}
|
|
33
|
+
return scheduleDpCodes;
|
|
34
|
+
};
|