@ray-js/lamp-schedule-core 1.0.0-beta-1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +565 -0
- package/lib/config/dpCodes.d.ts +27 -0
- package/lib/config/dpCodes.js +30 -0
- package/lib/config/index.d.ts +2 -0
- package/lib/config/index.js +2 -0
- package/lib/config/rhythms/defaultValue.d.ts +18 -0
- package/lib/config/rhythms/defaultValue.js +72 -0
- package/lib/config/rhythms/index.d.ts +10 -0
- package/lib/config/rhythms/index.js +35 -0
- package/lib/conflict/ConflictResolver.d.ts +2 -0
- package/lib/conflict/ConflictResolver.js +284 -0
- package/lib/conflict/__test__/ConflictResolver.test.d.ts +1 -0
- package/lib/conflict/__test__/ConflictResolver.test.js +183 -0
- package/lib/conflict/__test__/index.test.d.ts +1 -0
- package/lib/conflict/__test__/index.test.js +385 -0
- package/lib/conflict/__test__/scheduleDataManager.test.d.ts +1 -0
- package/lib/conflict/__test__/scheduleDataManager.test.js +170 -0
- package/lib/conflict/__test__/transform.test.d.ts +1 -0
- package/lib/conflict/__test__/transform.test.js +454 -0
- package/lib/conflict/__test__/updateDeviceDp.d.ts +1 -0
- package/lib/conflict/__test__/updateDeviceDp.js +114 -0
- package/lib/conflict/index.d.ts +42 -0
- package/lib/conflict/index.js +103 -0
- package/lib/conflict/scheduleDataManager.d.ts +12 -0
- package/lib/conflict/scheduleDataManager.js +79 -0
- package/lib/conflict/transform.d.ts +71 -0
- package/lib/conflict/transform.js +251 -0
- package/lib/conflict/type.d.ts +55 -0
- package/lib/conflict/type.js +17 -0
- package/lib/conflict/updateDeviceDp.d.ts +1 -0
- package/lib/conflict/updateDeviceDp.js +41 -0
- package/lib/constant/index.d.ts +5 -0
- package/lib/constant/index.js +5 -0
- package/lib/context/index.d.ts +3 -0
- package/lib/context/index.js +3 -0
- package/lib/context/rhythms/actions.d.ts +20 -0
- package/lib/context/rhythms/actions.js +52 -0
- package/lib/context/rhythms/index.d.ts +5 -0
- package/lib/context/rhythms/index.js +51 -0
- package/lib/context/rhythms/reducer.d.ts +24 -0
- package/lib/context/rhythms/reducer.js +38 -0
- package/lib/context/schedule/actions.d.ts +7 -0
- package/lib/context/schedule/actions.js +51 -0
- package/lib/context/schedule/context.d.ts +6 -0
- package/lib/context/schedule/context.js +52 -0
- package/lib/context/schedule/index.d.ts +1 -0
- package/lib/context/schedule/index.js +1 -0
- package/lib/context/schedule/reducer.d.ts +16 -0
- package/lib/context/schedule/reducer.js +104 -0
- package/lib/context/schedule/type.d.ts +41 -0
- package/lib/context/schedule/type.js +11 -0
- package/lib/context/timer/actions.d.ts +8 -0
- package/lib/context/timer/actions.js +52 -0
- package/lib/context/timer/context.d.ts +10 -0
- package/lib/context/timer/context.js +53 -0
- package/lib/context/timer/index.d.ts +1 -0
- package/lib/context/timer/index.js +1 -0
- package/lib/context/timer/reducer.d.ts +15 -0
- package/lib/context/timer/reducer.js +70 -0
- package/lib/context/timer/type.d.ts +46 -0
- package/lib/context/timer/type.js +24 -0
- package/lib/dpParser/README.md +63 -0
- package/lib/dpParser/__test__/cycle.test.d.ts +1 -0
- package/lib/dpParser/__test__/cycle.test.js +258 -0
- package/lib/dpParser/__test__/random.test.d.ts +1 -0
- package/lib/dpParser/__test__/random.test.js +211 -0
- package/lib/dpParser/__test__/rhythms.test.d.ts +1 -0
- package/lib/dpParser/__test__/rhythms.test.js +71 -0
- package/lib/dpParser/__test__/rtcTimer.test.d.ts +1 -0
- package/lib/dpParser/__test__/rtcTimer.test.js +235 -0
- package/lib/dpParser/__test__/sleep.test.d.ts +1 -0
- package/lib/dpParser/__test__/sleep.test.js +71 -0
- package/lib/dpParser/__test__/sleepCommon.test.d.ts +1 -0
- package/lib/dpParser/__test__/sleepCommon.test.js +197 -0
- package/lib/dpParser/__test__/timerReport.test.d.ts +1 -0
- package/lib/dpParser/__test__/timerReport.test.js +100 -0
- package/lib/dpParser/__test__/wakeup.test.d.ts +1 -0
- package/lib/dpParser/__test__/wakeup.test.js +69 -0
- package/lib/dpParser/__test__/wakeupCommon.test.d.ts +1 -0
- package/lib/dpParser/__test__/wakeupCommon.test.js +131 -0
- package/lib/dpParser/cycle/index.d.ts +15 -0
- package/lib/dpParser/cycle/index.js +134 -0
- package/lib/dpParser/index.d.ts +23 -0
- package/lib/dpParser/index.js +43 -0
- package/lib/dpParser/random/index.d.ts +15 -0
- package/lib/dpParser/random/index.js +127 -0
- package/lib/dpParser/rhythms.d.ts +41 -0
- package/lib/dpParser/rhythms.js +116 -0
- package/lib/dpParser/rtcTimer.d.ts +17 -0
- package/lib/dpParser/rtcTimer.js +300 -0
- package/lib/dpParser/sleep/index.d.ts +9 -0
- package/lib/dpParser/sleep/index.js +29 -0
- package/lib/dpParser/sleep/sleepCommon.d.ts +11 -0
- package/lib/dpParser/sleep/sleepCommon.js +117 -0
- package/lib/dpParser/sleep/sleepSigmesh.d.ts +0 -0
- package/lib/dpParser/sleep/sleepSigmesh.js +101 -0
- package/lib/dpParser/timerReport.d.ts +11 -0
- package/lib/dpParser/timerReport.js +43 -0
- package/lib/dpParser/utils.d.ts +27 -0
- package/lib/dpParser/utils.js +53 -0
- package/lib/dpParser/wakeup/index.d.ts +10 -0
- package/lib/dpParser/wakeup/index.js +34 -0
- package/lib/dpParser/wakeup/wakeupCommon.d.ts +11 -0
- package/lib/dpParser/wakeup/wakeupCommon.js +106 -0
- package/lib/dpParser/wakeup/wakeupSigmesh.d.ts +15 -0
- package/lib/dpParser/wakeup/wakeupSigmesh.js +86 -0
- package/lib/hooks/__test__/useCommon.test.d.ts +1 -0
- package/lib/hooks/__test__/useCommon.test.js +72 -0
- package/lib/hooks/__test__/useCountdownDp.test.d.ts +1 -0
- package/lib/hooks/__test__/useCountdownDp.test.js +82 -0
- package/lib/hooks/__test__/useCycleDp.test.d.ts +1 -0
- package/lib/hooks/__test__/useCycleDp.test.js +92 -0
- package/lib/hooks/__test__/useRandomDp.test.d.ts +1 -0
- package/lib/hooks/__test__/useRandomDp.test.js +88 -0
- package/lib/hooks/__test__/useRhythmsDp.test.d.ts +1 -0
- package/lib/hooks/__test__/useRhythmsDp.test.js +81 -0
- package/lib/hooks/__test__/useSleepDp.test.d.ts +1 -0
- package/lib/hooks/__test__/useSleepDp.test.js +127 -0
- package/lib/hooks/__test__/useTimeFlush.test.d.ts +1 -0
- package/lib/hooks/__test__/useTimeFlush.test.js +109 -0
- package/lib/hooks/__test__/useTimerDp.test.d.ts +1 -0
- package/lib/hooks/__test__/useTimerDp.test.js +79 -0
- package/lib/hooks/__test__/useTimerOperate.test.d.ts +1 -0
- package/lib/hooks/__test__/useTimerOperate.test.js +286 -0
- package/lib/hooks/__test__/useTimerOperateCloud.test.d.ts +1 -0
- package/lib/hooks/__test__/useTimerOperateCloud.test.js +190 -0
- package/lib/hooks/__test__/useTimerOperateLocal.test.d.ts +1 -0
- package/lib/hooks/__test__/useTimerOperateLocal.test.js +216 -0
- package/lib/hooks/__test__/useTimerReportDp.test.d.ts +1 -0
- package/lib/hooks/__test__/useTimerReportDp.test.js +93 -0
- package/lib/hooks/__test__/useTimerSupport.test.d.ts +1 -0
- package/lib/hooks/__test__/useTimerSupport.test.js +110 -0
- package/lib/hooks/__test__/useWakeUpDp.test.d.ts +1 -0
- package/lib/hooks/__test__/useWakeUpDp.test.js +129 -0
- package/lib/hooks/useBaseLightDp.d.ts +21 -0
- package/lib/hooks/useBaseLightDp.js +165 -0
- package/lib/hooks/useCommon.d.ts +29 -0
- package/lib/hooks/useCommon.js +59 -0
- package/lib/hooks/useCommonSupport.d.ts +25 -0
- package/lib/hooks/useCommonSupport.js +241 -0
- package/lib/hooks/useCountdownDp.d.ts +13 -0
- package/lib/hooks/useCountdownDp.js +28 -0
- package/lib/hooks/useCountdownSupport.d.ts +9 -0
- package/lib/hooks/useCountdownSupport.js +13 -0
- package/lib/hooks/useCycleDp.d.ts +7 -0
- package/lib/hooks/useCycleDp.js +21 -0
- package/lib/hooks/useCycleSupport.d.ts +12 -0
- package/lib/hooks/useCycleSupport.js +16 -0
- package/lib/hooks/useRandomDp.d.ts +7 -0
- package/lib/hooks/useRandomDp.js +21 -0
- package/lib/hooks/useRandomSupport.d.ts +12 -0
- package/lib/hooks/useRandomSupport.js +16 -0
- package/lib/hooks/useRhythmsDp.d.ts +7 -0
- package/lib/hooks/useRhythmsDp.js +23 -0
- package/lib/hooks/useSleepDp.d.ts +6 -0
- package/lib/hooks/useSleepDp.js +21 -0
- package/lib/hooks/useSleepSupport.d.ts +8 -0
- package/lib/hooks/useSleepSupport.js +13 -0
- package/lib/hooks/useTimeFlush.d.ts +8 -0
- package/lib/hooks/useTimeFlush.js +31 -0
- package/lib/hooks/useTimerDp.d.ts +5 -0
- package/lib/hooks/useTimerDp.js +25 -0
- package/lib/hooks/useTimerFlushList.d.ts +11 -0
- package/lib/hooks/useTimerFlushList.js +53 -0
- package/lib/hooks/useTimerOperate.d.ts +68 -0
- package/lib/hooks/useTimerOperate.js +403 -0
- package/lib/hooks/useTimerOperateCloud.d.ts +31 -0
- package/lib/hooks/useTimerOperateCloud.js +233 -0
- package/lib/hooks/useTimerOperateLocal.d.ts +40 -0
- package/lib/hooks/useTimerOperateLocal.js +310 -0
- package/lib/hooks/useTimerReportDp.d.ts +15 -0
- package/lib/hooks/useTimerReportDp.js +48 -0
- package/lib/hooks/useTimerSupport.d.ts +13 -0
- package/lib/hooks/useTimerSupport.js +38 -0
- package/lib/hooks/useWakeUpDp.d.ts +6 -0
- package/lib/hooks/useWakeUpDp.js +21 -0
- package/lib/hooks/useWakeUpSupport.d.ts +8 -0
- package/lib/hooks/useWakeUpSupport.js +13 -0
- package/lib/hooks/useWakeupDp.d.ts +6 -0
- package/lib/hooks/useWakeupDp.js +21 -0
- package/lib/hooks/useWakeupSupport.d.ts +8 -0
- package/lib/hooks/useWakeupSupport.js +13 -0
- package/lib/i18n/index.d.ts +142 -0
- package/lib/i18n/index.js +7 -0
- package/lib/i18n/rhythms.d.ts +73 -0
- package/lib/i18n/rhythms.js +72 -0
- package/lib/i18n/strings.d.ts +73 -0
- package/lib/i18n/strings.js +6 -0
- package/lib/index.d.ts +51 -0
- package/lib/index.js +64 -0
- package/lib/types/countdown.d.ts +3 -0
- package/lib/types/countdown.js +1 -0
- package/lib/types/cycle.d.ts +22 -0
- package/lib/types/cycle.js +1 -0
- package/lib/types/global.d.ts +9 -0
- package/lib/types/index.d.ts +331 -0
- package/lib/types/index.js +76 -0
- package/lib/types/random.d.ts +20 -0
- package/lib/types/random.js +1 -0
- package/lib/types/rhythms.d.ts +79 -0
- package/lib/types/rhythms.js +15 -0
- package/lib/types/sleep.d.ts +36 -0
- package/lib/types/sleep.js +1 -0
- package/lib/types/timer.d.ts +107 -0
- package/lib/types/timer.js +1 -0
- package/lib/types/wakeup.d.ts +38 -0
- package/lib/types/wakeup.js +1 -0
- package/lib/utils/ScheduleCache.d.ts +19 -0
- package/lib/utils/ScheduleCache.js +39 -0
- package/lib/utils/ScheduleCloudProperty.d.ts +75 -0
- package/lib/utils/ScheduleCloudProperty.js +220 -0
- package/lib/utils/ScheduleDataSync.d.ts +82 -0
- package/lib/utils/ScheduleDataSync.js +127 -0
- package/lib/utils/ScheduleEmit.d.ts +67 -0
- package/lib/utils/ScheduleEmit.js +61 -0
- package/lib/utils/ScheduleLogger.d.ts +19 -0
- package/lib/utils/ScheduleLogger.js +71 -0
- package/lib/utils/ScheduleSupport.d.ts +131 -0
- package/lib/utils/ScheduleSupport.js +373 -0
- package/lib/utils/ScheduleUtils.d.ts +12 -0
- package/lib/utils/ScheduleUtils.js +51 -0
- package/lib/utils/__test__/ScheduleCloudProperty.test.d.ts +1 -0
- package/lib/utils/__test__/ScheduleCloudProperty.test.js +320 -0
- package/lib/utils/__test__/ScheduleSupport.test.d.ts +1 -0
- package/lib/utils/__test__/ScheduleSupport.test.js +211 -0
- package/lib/utils/__test__/ScheduleUtils.test.d.ts +1 -0
- package/lib/utils/__test__/ScheduleUtils.test.js +119 -0
- package/lib/utils/__test__/common.test.d.ts +1 -0
- package/lib/utils/__test__/common.test.js +147 -0
- package/lib/utils/__test__/storage.test.d.ts +1 -0
- package/lib/utils/__test__/storage.test.js +98 -0
- package/lib/utils/__test__/time.test.d.ts +1 -0
- package/lib/utils/__test__/time.test.js +146 -0
- package/lib/utils/common.d.ts +23 -0
- package/lib/utils/common.js +109 -0
- package/lib/utils/dpState.d.ts +5 -0
- package/lib/utils/dpState.js +27 -0
- package/lib/utils/getCachedSystemInfo.d.ts +39 -0
- package/lib/utils/getCachedSystemInfo.js +20 -0
- package/lib/utils/isInIDE.d.ts +1 -0
- package/lib/utils/isInIDE.js +5 -0
- package/lib/utils/storage.d.ts +5 -0
- package/lib/utils/storage.js +32 -0
- package/lib/utils/time.d.ts +40 -0
- package/lib/utils/time.js +84 -0
- package/package.json +78 -0
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
import "core-js/modules/esnext.iterator.map.js";
|
|
2
|
+
/* eslint-disable array-callback-return */
|
|
3
|
+
/* eslint-disable prefer-rest-params */
|
|
4
|
+
/* eslint-disable no-bitwise */
|
|
5
|
+
/* eslint-disable no-param-reassign */
|
|
6
|
+
|
|
7
|
+
// An array of all currently registered event handlers for a type
|
|
8
|
+
|
|
9
|
+
// A map of event types and their corresponding event handlers.
|
|
10
|
+
|
|
11
|
+
/** EMitt: Tiny (~225b) functional event emitter / pubsub.
|
|
12
|
+
* @name emitt
|
|
13
|
+
* @returns {Emitt}
|
|
14
|
+
*/
|
|
15
|
+
export default function emitt(all) {
|
|
16
|
+
all = all || Object.create(null);
|
|
17
|
+
return {
|
|
18
|
+
/**
|
|
19
|
+
* Register an event handler for the given type.
|
|
20
|
+
*
|
|
21
|
+
* @param {String} type Type of event to listen for, or `"*"` for all events
|
|
22
|
+
* @param {Function} handler Function to call in response to given event
|
|
23
|
+
* @memberOf emitt
|
|
24
|
+
*/
|
|
25
|
+
on(type, handler) {
|
|
26
|
+
(all[type] || (all[type] = [])).push(handler);
|
|
27
|
+
},
|
|
28
|
+
/**
|
|
29
|
+
* Remove an event handler for the given type.
|
|
30
|
+
*
|
|
31
|
+
* @param {String} type Type of event to unregister `handler` from, or `"*"`
|
|
32
|
+
* @param {Function} handler Handler function to remove
|
|
33
|
+
* @memberOf emitt
|
|
34
|
+
*/
|
|
35
|
+
off(type, handler) {
|
|
36
|
+
if (all[type]) {
|
|
37
|
+
all[type].splice(all[type].indexOf(handler) >>> 0, 1);
|
|
38
|
+
}
|
|
39
|
+
},
|
|
40
|
+
/**
|
|
41
|
+
* Invoke all handlers for the given type.
|
|
42
|
+
* If present, `"*"` handlers are invoked after type-matched handlers.
|
|
43
|
+
*
|
|
44
|
+
* @param {String} type The event type to invoke
|
|
45
|
+
* @param {any[]} [...event_args] Any values (object is recommended and powerful), passed to each handler
|
|
46
|
+
* @memberOf emitt
|
|
47
|
+
*/
|
|
48
|
+
emit(type) {
|
|
49
|
+
for (var _len = arguments.length, args = new Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) {
|
|
50
|
+
args[_key - 1] = arguments[_key];
|
|
51
|
+
}
|
|
52
|
+
(all[type] || []).map(handler => {
|
|
53
|
+
handler(...args);
|
|
54
|
+
});
|
|
55
|
+
(all['*'] || []).map(handler => {
|
|
56
|
+
handler(type, ...args);
|
|
57
|
+
});
|
|
58
|
+
}
|
|
59
|
+
};
|
|
60
|
+
}
|
|
61
|
+
export const emitter = emitt();
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
declare enum LogLevel {
|
|
2
|
+
DEBUG = "debug",
|
|
3
|
+
INFO = "info",
|
|
4
|
+
WARN = "warn",
|
|
5
|
+
ERROR = "error"
|
|
6
|
+
}
|
|
7
|
+
export declare class ScheduleLogger {
|
|
8
|
+
logLevel: LogLevel;
|
|
9
|
+
logPrefix: string;
|
|
10
|
+
setLogLevel(level: LogLevel): void;
|
|
11
|
+
setLogPrefix(prefix: string): void;
|
|
12
|
+
formatMessage(level: LogLevel, message: any, data?: never[]): any[];
|
|
13
|
+
debug(message: string, ...data: any[]): void;
|
|
14
|
+
info(message: string, ...data: any[]): void;
|
|
15
|
+
warn(message: string, ...data: any[]): void;
|
|
16
|
+
error(message: string, ...data: any[]): void;
|
|
17
|
+
}
|
|
18
|
+
export declare const scheduleLogger: ScheduleLogger;
|
|
19
|
+
export {};
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
/* eslint-disable no-console */
|
|
2
|
+
/* eslint-disable @typescript-eslint/explicit-module-boundary-types */
|
|
3
|
+
|
|
4
|
+
import { LOG_PREFIX } from '../constant';
|
|
5
|
+
var LogLevel = /*#__PURE__*/function (LogLevel) {
|
|
6
|
+
LogLevel["DEBUG"] = "debug";
|
|
7
|
+
LogLevel["INFO"] = "info";
|
|
8
|
+
LogLevel["WARN"] = "warn";
|
|
9
|
+
LogLevel["ERROR"] = "error";
|
|
10
|
+
return LogLevel;
|
|
11
|
+
}(LogLevel || {});
|
|
12
|
+
var ELevelColor = /*#__PURE__*/function (ELevelColor) {
|
|
13
|
+
ELevelColor["DEBUG"] = "#00dcf5";
|
|
14
|
+
ELevelColor["INFO"] = "#00FF00";
|
|
15
|
+
ELevelColor["WARN"] = "#f2a93b";
|
|
16
|
+
ELevelColor["ERROR"] = "#ff0000";
|
|
17
|
+
return ELevelColor;
|
|
18
|
+
}(ELevelColor || {});
|
|
19
|
+
export class ScheduleLogger {
|
|
20
|
+
logLevel = (() => LogLevel.DEBUG)();
|
|
21
|
+
logPrefix = (() => LOG_PREFIX)();
|
|
22
|
+
setLogLevel(level) {
|
|
23
|
+
this.logLevel = level;
|
|
24
|
+
}
|
|
25
|
+
setLogPrefix(prefix) {
|
|
26
|
+
this.logPrefix = prefix;
|
|
27
|
+
}
|
|
28
|
+
formatMessage(level, message) {
|
|
29
|
+
let data = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : [];
|
|
30
|
+
const timestamp = new Date().toLocaleString();
|
|
31
|
+
let _message = message;
|
|
32
|
+
try {
|
|
33
|
+
_message = typeof message === 'string' ? message : JSON.stringify(message);
|
|
34
|
+
} catch (err) {
|
|
35
|
+
console.error(err);
|
|
36
|
+
}
|
|
37
|
+
return [`${timestamp} %c [${level.toUpperCase()}] %c ${this.logPrefix} ${_message}`, `color: ${ELevelColor[level.toUpperCase()]}`, `color: ${ELevelColor[level.toUpperCase()]}`, ...data];
|
|
38
|
+
}
|
|
39
|
+
debug(message) {
|
|
40
|
+
if (this.logLevel === LogLevel.DEBUG) {
|
|
41
|
+
for (var _len = arguments.length, data = new Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) {
|
|
42
|
+
data[_key - 1] = arguments[_key];
|
|
43
|
+
}
|
|
44
|
+
console.log(...this.formatMessage(LogLevel.DEBUG, message, data));
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
info(message) {
|
|
48
|
+
if ([LogLevel.DEBUG, LogLevel.INFO].includes(this.logLevel)) {
|
|
49
|
+
for (var _len2 = arguments.length, data = new Array(_len2 > 1 ? _len2 - 1 : 0), _key2 = 1; _key2 < _len2; _key2++) {
|
|
50
|
+
data[_key2 - 1] = arguments[_key2];
|
|
51
|
+
}
|
|
52
|
+
console.log(...this.formatMessage(LogLevel.INFO, message, data));
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
warn(message) {
|
|
56
|
+
if ([LogLevel.DEBUG, LogLevel.INFO, LogLevel.WARN].includes(this.logLevel)) {
|
|
57
|
+
for (var _len3 = arguments.length, data = new Array(_len3 > 1 ? _len3 - 1 : 0), _key3 = 1; _key3 < _len3; _key3++) {
|
|
58
|
+
data[_key3 - 1] = arguments[_key3];
|
|
59
|
+
}
|
|
60
|
+
console.warn(...this.formatMessage(LogLevel.WARN, message, data));
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
error(message) {
|
|
64
|
+
for (var _len4 = arguments.length, data = new Array(_len4 > 1 ? _len4 - 1 : 0), _key4 = 1; _key4 < _len4; _key4++) {
|
|
65
|
+
data[_key4 - 1] = arguments[_key4];
|
|
66
|
+
}
|
|
67
|
+
console.error(...this.formatMessage(LogLevel.ERROR, message, data));
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
export const scheduleLogger = new ScheduleLogger();
|
|
71
|
+
scheduleLogger.setLogLevel(LogLevel.INFO);
|
|
@@ -0,0 +1,131 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 判断设备对 dp 的支持
|
|
3
|
+
*/
|
|
4
|
+
import { DevInfo, EDeviceType, GroupDevInfo } from '../types';
|
|
5
|
+
type TProps = {
|
|
6
|
+
devId: string;
|
|
7
|
+
groupId?: string;
|
|
8
|
+
panelConfig?: Record<string, any>;
|
|
9
|
+
};
|
|
10
|
+
/**
|
|
11
|
+
* @description.zh 设备能力值标位
|
|
12
|
+
* @description.en Enumeration of device capability bits
|
|
13
|
+
*/
|
|
14
|
+
export declare enum DeviceCapability {
|
|
15
|
+
/** Wi-Fi */
|
|
16
|
+
WIFI = 0,
|
|
17
|
+
/** cable(以太网) */
|
|
18
|
+
CABLE = 1,
|
|
19
|
+
/** gprs(2/3/4G) */
|
|
20
|
+
GPRS = 2,
|
|
21
|
+
/** NB-IOT */
|
|
22
|
+
NBIOT = 3,
|
|
23
|
+
/** 蓝牙BLE */
|
|
24
|
+
BLUETOOTH = 10,
|
|
25
|
+
/** 涂鸦mesh */
|
|
26
|
+
BLEMESH = 11,
|
|
27
|
+
/** zigbee */
|
|
28
|
+
ZIGBEE = 12,
|
|
29
|
+
/** infrared(红外) */
|
|
30
|
+
INFRARED = 13,
|
|
31
|
+
/** subpieces(315,433等) */
|
|
32
|
+
SUBPIECES = 14,
|
|
33
|
+
/** Sigmesh */
|
|
34
|
+
SIGMESH = 15,
|
|
35
|
+
/** MCU */
|
|
36
|
+
MCU = 16,
|
|
37
|
+
/** 涂鸦Sub-G Mesh */
|
|
38
|
+
TYMESH = 17,
|
|
39
|
+
/** Zwave */
|
|
40
|
+
ZWAVE = 18,
|
|
41
|
+
/** 蓝牙mesh */
|
|
42
|
+
PLMESH = 19,
|
|
43
|
+
/** LTE Cat1 */
|
|
44
|
+
CAT1 = 20,
|
|
45
|
+
/** 蓝牙beacon */
|
|
46
|
+
BEACON = 21,
|
|
47
|
+
/** CAT4 */
|
|
48
|
+
CAT4 = 22,
|
|
49
|
+
/** CAT10 */
|
|
50
|
+
CAT10 = 23,
|
|
51
|
+
/** LTE CATM */
|
|
52
|
+
CATM = 24,
|
|
53
|
+
/** tread */
|
|
54
|
+
THREAD = 25
|
|
55
|
+
}
|
|
56
|
+
/**
|
|
57
|
+
* @example
|
|
58
|
+
* // 17 = 10001(2)
|
|
59
|
+
* getBitValue(17, 0)
|
|
60
|
+
* // 1
|
|
61
|
+
* getBitValue(17, 1)
|
|
62
|
+
* // 0
|
|
63
|
+
* @param {Number} idx, idx is reverse, and it begins 0
|
|
64
|
+
* @returns {Number} a num
|
|
65
|
+
*/
|
|
66
|
+
export declare const getBitValue: (num: number, idx: number) => number;
|
|
67
|
+
export type TDeviceInfo = DevInfo & {
|
|
68
|
+
isMatter: boolean;
|
|
69
|
+
isTripartiteMatter: boolean;
|
|
70
|
+
};
|
|
71
|
+
export declare class Support {
|
|
72
|
+
constructor(props: TProps);
|
|
73
|
+
private isInit;
|
|
74
|
+
private isIniting;
|
|
75
|
+
private props;
|
|
76
|
+
private devInfo;
|
|
77
|
+
private groupDevInfo;
|
|
78
|
+
deviceType: EDeviceType;
|
|
79
|
+
private setGroupDevInfo;
|
|
80
|
+
private setDevInfo;
|
|
81
|
+
init: () => Promise<boolean>;
|
|
82
|
+
hasCapability: (bit: DeviceCapability, devInfo?: TDeviceInfo) => boolean;
|
|
83
|
+
getCachedDevInfo: () => TDeviceInfo;
|
|
84
|
+
/**
|
|
85
|
+
* @description 判断是否支持云端定时
|
|
86
|
+
*/
|
|
87
|
+
isSupportCloudTimer: (devInfo?: TDeviceInfo) => boolean;
|
|
88
|
+
private supportDp;
|
|
89
|
+
/**
|
|
90
|
+
* 检查给定的dpCode是否支持。
|
|
91
|
+
*
|
|
92
|
+
* @param {string} dpCode - dp的代码。
|
|
93
|
+
* @param {boolean} [isForce] - 是否强制检查或使用缓存的结果。默认为undefined。
|
|
94
|
+
* @return {boolean} - 如果dpCode支持则返回true,否则返回false。
|
|
95
|
+
*/
|
|
96
|
+
isSupportDp: (dpCode: string, isForce?: boolean, devInfo?: TDeviceInfo) => boolean;
|
|
97
|
+
isGroupDevice(devInfo?: TDeviceInfo): boolean;
|
|
98
|
+
/** 获取 devInfo */
|
|
99
|
+
getDevInfo(): DevInfo;
|
|
100
|
+
getGroupDevInfo(): GroupDevInfo;
|
|
101
|
+
getMergeDevInfo(): DevInfo | GroupDevInfo;
|
|
102
|
+
/**
|
|
103
|
+
* @description 判断是否是 WiFi Device
|
|
104
|
+
*/
|
|
105
|
+
isWifiDevice: (devInfo?: TDeviceInfo) => boolean;
|
|
106
|
+
/**
|
|
107
|
+
* @description 判断是否是Zigbee Device
|
|
108
|
+
*/
|
|
109
|
+
isZigbeeDevice: (devInfo?: TDeviceInfo) => boolean;
|
|
110
|
+
/**
|
|
111
|
+
* @description 判断是否是 SigMesh Device
|
|
112
|
+
*/
|
|
113
|
+
isSigMeshDevice: (devInfo?: TDeviceInfo) => boolean;
|
|
114
|
+
/**
|
|
115
|
+
* 是否是蓝牙设备
|
|
116
|
+
* */
|
|
117
|
+
isBleDevice: (devInfo?: TDeviceInfo) => boolean;
|
|
118
|
+
/**
|
|
119
|
+
* @description 是否是 Matter 设备
|
|
120
|
+
*/
|
|
121
|
+
isMatterDevice(devInfo?: TDeviceInfo): boolean;
|
|
122
|
+
/**
|
|
123
|
+
* @description 是否是 涂鸦 Matter 设备
|
|
124
|
+
*/
|
|
125
|
+
isTuyaMatterDevice(devInfo?: TDeviceInfo): boolean;
|
|
126
|
+
/**
|
|
127
|
+
* @description 是否是 三方 Matter 设备
|
|
128
|
+
*/
|
|
129
|
+
isTripartiteMatter(devInfo?: TDeviceInfo): boolean;
|
|
130
|
+
}
|
|
131
|
+
export {};
|
|
@@ -0,0 +1,373 @@
|
|
|
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.every.js";
|
|
4
|
+
import "core-js/modules/esnext.iterator.find.js";
|
|
5
|
+
import "core-js/modules/esnext.iterator.for-each.js";
|
|
6
|
+
/* eslint-disable no-bitwise */
|
|
7
|
+
/* eslint-disable no-console */
|
|
8
|
+
/**
|
|
9
|
+
* 判断设备对 dp 的支持
|
|
10
|
+
*/
|
|
11
|
+
|
|
12
|
+
import { EDeviceType } from '../types';
|
|
13
|
+
import { LOG_PREFIX } from '../constant';
|
|
14
|
+
import { scheduleLogger as ScheduleLogger } from './ScheduleLogger';
|
|
15
|
+
import { devIdOrGroupIdCache, getScheduleCache, setScheduleCache } from '../utils/ScheduleCache';
|
|
16
|
+
import { initDpState, setDpState } from './dpState';
|
|
17
|
+
import { getDpCodeByDpId } from './ScheduleUtils';
|
|
18
|
+
import { getDeviceInfo, getGroupInfo } from '@ray-js/ray';
|
|
19
|
+
|
|
20
|
+
// 缓存支持能力的值
|
|
21
|
+
const cache = {};
|
|
22
|
+
const DEV_INFO_KEY = 'devInfo';
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* @description.zh 设备能力值标位
|
|
26
|
+
* @description.en Enumeration of device capability bits
|
|
27
|
+
*/
|
|
28
|
+
export let DeviceCapability = /*#__PURE__*/function (DeviceCapability) {
|
|
29
|
+
/** Wi-Fi */
|
|
30
|
+
DeviceCapability[DeviceCapability["WIFI"] = 0] = "WIFI";
|
|
31
|
+
/** cable(以太网) */
|
|
32
|
+
DeviceCapability[DeviceCapability["CABLE"] = 1] = "CABLE";
|
|
33
|
+
/** gprs(2/3/4G) */
|
|
34
|
+
DeviceCapability[DeviceCapability["GPRS"] = 2] = "GPRS";
|
|
35
|
+
/** NB-IOT */
|
|
36
|
+
DeviceCapability[DeviceCapability["NBIOT"] = 3] = "NBIOT";
|
|
37
|
+
/** 蓝牙BLE */
|
|
38
|
+
DeviceCapability[DeviceCapability["BLUETOOTH"] = 10] = "BLUETOOTH";
|
|
39
|
+
/** 涂鸦mesh */
|
|
40
|
+
DeviceCapability[DeviceCapability["BLEMESH"] = 11] = "BLEMESH";
|
|
41
|
+
/** zigbee */
|
|
42
|
+
DeviceCapability[DeviceCapability["ZIGBEE"] = 12] = "ZIGBEE";
|
|
43
|
+
/** infrared(红外) */
|
|
44
|
+
DeviceCapability[DeviceCapability["INFRARED"] = 13] = "INFRARED";
|
|
45
|
+
/** subpieces(315,433等) */
|
|
46
|
+
DeviceCapability[DeviceCapability["SUBPIECES"] = 14] = "SUBPIECES";
|
|
47
|
+
/** Sigmesh */
|
|
48
|
+
DeviceCapability[DeviceCapability["SIGMESH"] = 15] = "SIGMESH";
|
|
49
|
+
/** MCU */
|
|
50
|
+
DeviceCapability[DeviceCapability["MCU"] = 16] = "MCU";
|
|
51
|
+
/** 涂鸦Sub-G Mesh */
|
|
52
|
+
DeviceCapability[DeviceCapability["TYMESH"] = 17] = "TYMESH";
|
|
53
|
+
/** Zwave */
|
|
54
|
+
DeviceCapability[DeviceCapability["ZWAVE"] = 18] = "ZWAVE";
|
|
55
|
+
/** 蓝牙mesh */
|
|
56
|
+
DeviceCapability[DeviceCapability["PLMESH"] = 19] = "PLMESH";
|
|
57
|
+
/** LTE Cat1 */
|
|
58
|
+
DeviceCapability[DeviceCapability["CAT1"] = 20] = "CAT1";
|
|
59
|
+
/** 蓝牙beacon */
|
|
60
|
+
DeviceCapability[DeviceCapability["BEACON"] = 21] = "BEACON";
|
|
61
|
+
/** CAT4 */
|
|
62
|
+
DeviceCapability[DeviceCapability["CAT4"] = 22] = "CAT4";
|
|
63
|
+
/** CAT10 */
|
|
64
|
+
DeviceCapability[DeviceCapability["CAT10"] = 23] = "CAT10";
|
|
65
|
+
/** LTE CATM */
|
|
66
|
+
DeviceCapability[DeviceCapability["CATM"] = 24] = "CATM";
|
|
67
|
+
/** tread */
|
|
68
|
+
DeviceCapability[DeviceCapability["THREAD"] = 25] = "THREAD";
|
|
69
|
+
return DeviceCapability;
|
|
70
|
+
}({});
|
|
71
|
+
|
|
72
|
+
/**
|
|
73
|
+
* @example
|
|
74
|
+
* // 17 = 10001(2)
|
|
75
|
+
* getBitValue(17, 0)
|
|
76
|
+
* // 1
|
|
77
|
+
* getBitValue(17, 1)
|
|
78
|
+
* // 0
|
|
79
|
+
* @param {Number} idx, idx is reverse, and it begins 0
|
|
80
|
+
* @returns {Number} a num
|
|
81
|
+
*/
|
|
82
|
+
export const getBitValue = (num, idx) => (num & 1 << idx) >> idx;
|
|
83
|
+
let _supportProps = null;
|
|
84
|
+
export class Support {
|
|
85
|
+
constructor(props) {
|
|
86
|
+
this.props = _objectSpread(_objectSpread({}, _supportProps || {}), props);
|
|
87
|
+
_supportProps = this.props;
|
|
88
|
+
}
|
|
89
|
+
isInit = false;
|
|
90
|
+
isIniting = false; // 初始化中
|
|
91
|
+
|
|
92
|
+
devInfo = (() => ({}))();
|
|
93
|
+
groupDevInfo = (() => ({}))();
|
|
94
|
+
deviceType = (() => EDeviceType.wifi)();
|
|
95
|
+
setGroupDevInfo = groupId => {
|
|
96
|
+
return new Promise((resolve, reject) => {
|
|
97
|
+
getGroupInfo({
|
|
98
|
+
groupId,
|
|
99
|
+
success: res => {
|
|
100
|
+
this.groupDevInfo = res;
|
|
101
|
+
ScheduleLogger.debug('getGroupInfo groupId: ', groupId);
|
|
102
|
+
ScheduleLogger.debug('getGroupInfo success1: ', res);
|
|
103
|
+
setScheduleCache(DEV_INFO_KEY, res);
|
|
104
|
+
// 群组中为空
|
|
105
|
+
groupId && (devIdOrGroupIdCache === null || devIdOrGroupIdCache === void 0 ? void 0 : devIdOrGroupIdCache.set('', groupId));
|
|
106
|
+
resolve(true);
|
|
107
|
+
},
|
|
108
|
+
fail: err => {
|
|
109
|
+
this.groupDevInfo = {};
|
|
110
|
+
ScheduleLogger.error('getGroupInfo groupId: ', groupId);
|
|
111
|
+
ScheduleLogger.error('getGroupInfo fail: ', err);
|
|
112
|
+
setScheduleCache(DEV_INFO_KEY, {});
|
|
113
|
+
reject();
|
|
114
|
+
}
|
|
115
|
+
});
|
|
116
|
+
});
|
|
117
|
+
};
|
|
118
|
+
setDevInfo = devId => {
|
|
119
|
+
return new Promise((resolve, reject) => {
|
|
120
|
+
getDeviceInfo({
|
|
121
|
+
deviceId: devId,
|
|
122
|
+
success: res => {
|
|
123
|
+
this.devInfo = res;
|
|
124
|
+
ScheduleLogger.debug('getDeviceInfo success devId: ', devId);
|
|
125
|
+
ScheduleLogger.debug('getDeviceInfo success res: ', res);
|
|
126
|
+
setScheduleCache(DEV_INFO_KEY, res);
|
|
127
|
+
const dpMap = {};
|
|
128
|
+
Object.keys(res.dps).forEach(dpId => {
|
|
129
|
+
const dpCode = getDpCodeByDpId(dpId);
|
|
130
|
+
dpCode && setDpState(dpCode, res.dps[dpId]);
|
|
131
|
+
});
|
|
132
|
+
Object.keys(dpMap).length && initDpState(dpMap);
|
|
133
|
+
devId && (devIdOrGroupIdCache === null || devIdOrGroupIdCache === void 0 ? void 0 : devIdOrGroupIdCache.set(devId, ''));
|
|
134
|
+
resolve(res);
|
|
135
|
+
},
|
|
136
|
+
fail: err => {
|
|
137
|
+
this.devInfo = {};
|
|
138
|
+
ScheduleLogger.debug('getDeviceInfo fail: ', {});
|
|
139
|
+
setScheduleCache(DEV_INFO_KEY, {});
|
|
140
|
+
!this.isIniting && ScheduleLogger.error('setDevInfo error', err);
|
|
141
|
+
reject();
|
|
142
|
+
}
|
|
143
|
+
});
|
|
144
|
+
});
|
|
145
|
+
};
|
|
146
|
+
init = () => {
|
|
147
|
+
return new Promise((resolve, reject) => {
|
|
148
|
+
this.isIniting = true;
|
|
149
|
+
if (Object.keys(this.devInfo || {}).length > 0 || Object.keys(this.groupDevInfo || {}).length > 0) {
|
|
150
|
+
this.isInit = true;
|
|
151
|
+
this.isIniting = false;
|
|
152
|
+
resolve(true);
|
|
153
|
+
return;
|
|
154
|
+
}
|
|
155
|
+
const {
|
|
156
|
+
devId,
|
|
157
|
+
groupId
|
|
158
|
+
} = this.props;
|
|
159
|
+
if (groupId) {
|
|
160
|
+
ScheduleLogger.debug('init get groupId info: ', groupId);
|
|
161
|
+
this.setGroupDevInfo(groupId).then(() => {
|
|
162
|
+
this.isInit = true;
|
|
163
|
+
this.isIniting = false;
|
|
164
|
+
resolve(true);
|
|
165
|
+
}).catch(() => {
|
|
166
|
+
this.isIniting = false;
|
|
167
|
+
reject(new Error('get group info fail'));
|
|
168
|
+
});
|
|
169
|
+
return;
|
|
170
|
+
}
|
|
171
|
+
if (devId) {
|
|
172
|
+
ScheduleLogger.debug('init get devId info: ', devId);
|
|
173
|
+
this.setDevInfo(devId).then(() => {
|
|
174
|
+
this.isInit = true;
|
|
175
|
+
this.isIniting = false;
|
|
176
|
+
resolve(true);
|
|
177
|
+
}).catch(() => {
|
|
178
|
+
this.isIniting = false;
|
|
179
|
+
reject(new Error('get dev info fail'));
|
|
180
|
+
});
|
|
181
|
+
return;
|
|
182
|
+
}
|
|
183
|
+
this.isIniting = false;
|
|
184
|
+
reject(new Error(`${LOG_PREFIX} devId and groupId are undefined`));
|
|
185
|
+
});
|
|
186
|
+
};
|
|
187
|
+
hasCapability = (bit, devInfo) => {
|
|
188
|
+
if (devInfo) {
|
|
189
|
+
return (devInfo.capability & 1 << bit) > 0;
|
|
190
|
+
}
|
|
191
|
+
this.devInfo = this.getCachedDevInfo();
|
|
192
|
+
if (!this.devInfo) {
|
|
193
|
+
!this.isIniting && ScheduleLogger.error('hasCapability: ', 'devInfo is undefined');
|
|
194
|
+
!this.isIniting && ScheduleLogger.warn('请提前调用 useScheduleInit');
|
|
195
|
+
return false;
|
|
196
|
+
}
|
|
197
|
+
return (this.devInfo.capability & 1 << bit) > 0;
|
|
198
|
+
};
|
|
199
|
+
getCachedDevInfo = () => {
|
|
200
|
+
return getScheduleCache(DEV_INFO_KEY);
|
|
201
|
+
};
|
|
202
|
+
|
|
203
|
+
/**
|
|
204
|
+
* @description 判断是否支持云端定时
|
|
205
|
+
*/
|
|
206
|
+
isSupportCloudTimer = devInfo => {
|
|
207
|
+
var _this$devInfo2;
|
|
208
|
+
this.devInfo = devInfo !== null && devInfo !== void 0 ? devInfo : this.getCachedDevInfo();
|
|
209
|
+
if (!this.devInfo) {
|
|
210
|
+
return false;
|
|
211
|
+
}
|
|
212
|
+
// 群组设备需要从设备列表里面判断所有设备都支持定时才会显示
|
|
213
|
+
if (this.devInfo.groupId) {
|
|
214
|
+
var _this$devInfo;
|
|
215
|
+
// @ts-ignore
|
|
216
|
+
const deviceList = (_this$devInfo = this.devInfo) === null || _this$devInfo === void 0 ? void 0 : _this$devInfo.deviceList;
|
|
217
|
+
if (!Array.isArray(deviceList) || deviceList.length === 0) return false;
|
|
218
|
+
const isAllDeviceHasTimer = deviceList.every(d => {
|
|
219
|
+
var _d$panelConfig;
|
|
220
|
+
const timer = d === null || d === void 0 || (_d$panelConfig = d.panelConfig) === null || _d$panelConfig === void 0 || (_d$panelConfig = _d$panelConfig.bic) === null || _d$panelConfig === void 0 ? void 0 : _d$panelConfig.find(i => i.code === 'timer');
|
|
221
|
+
if (!timer) {
|
|
222
|
+
!this.isIniting && ScheduleLogger.info('isSupportCloudTimer: ', `${d.devId} 不支持云定时`);
|
|
223
|
+
return false;
|
|
224
|
+
}
|
|
225
|
+
return timer.selected;
|
|
226
|
+
});
|
|
227
|
+
return isAllDeviceHasTimer;
|
|
228
|
+
}
|
|
229
|
+
return ((_this$devInfo2 = this.devInfo) === null || _this$devInfo2 === void 0 || (_this$devInfo2 = _this$devInfo2.panelConfig) === null || _this$devInfo2 === void 0 || (_this$devInfo2 = _this$devInfo2.bic) === null || _this$devInfo2 === void 0 ? void 0 : _this$devInfo2.find(i => i.code === 'timer' && i.selected)) !== undefined;
|
|
230
|
+
};
|
|
231
|
+
supportDp = (dpCode, devInfo) => {
|
|
232
|
+
this.devInfo = devInfo !== null && devInfo !== void 0 ? devInfo : this.getCachedDevInfo();
|
|
233
|
+
if (!this.devInfo) {
|
|
234
|
+
!this.isIniting && ScheduleLogger.warn('supportDp: ', 'devInfo is undefined');
|
|
235
|
+
!this.isIniting && ScheduleLogger.warn('请提前调用 useScheduleInit 的 init 方法');
|
|
236
|
+
return false;
|
|
237
|
+
}
|
|
238
|
+
const {
|
|
239
|
+
schema
|
|
240
|
+
} = this.devInfo;
|
|
241
|
+
if (!schema) {
|
|
242
|
+
!this.isIniting && ScheduleLogger.warn('supportDp: ', 'schema is undefined');
|
|
243
|
+
return false;
|
|
244
|
+
}
|
|
245
|
+
if (Array.isArray(schema)) {
|
|
246
|
+
return schema.findIndex(item => (item === null || item === void 0 ? void 0 : item.code) === dpCode) > -1;
|
|
247
|
+
}
|
|
248
|
+
const dp = schema[dpCode];
|
|
249
|
+
return dp !== undefined;
|
|
250
|
+
};
|
|
251
|
+
|
|
252
|
+
/**
|
|
253
|
+
* 检查给定的dpCode是否支持。
|
|
254
|
+
*
|
|
255
|
+
* @param {string} dpCode - dp的代码。
|
|
256
|
+
* @param {boolean} [isForce] - 是否强制检查或使用缓存的结果。默认为undefined。
|
|
257
|
+
* @return {boolean} - 如果dpCode支持则返回true,否则返回false。
|
|
258
|
+
*/
|
|
259
|
+
isSupportDp = (() => {
|
|
260
|
+
var _this = this;
|
|
261
|
+
return function (dpCode) {
|
|
262
|
+
let isForce = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
|
|
263
|
+
let devInfo = arguments.length > 2 ? arguments[2] : undefined;
|
|
264
|
+
if (!isForce) {
|
|
265
|
+
if (cache[dpCode]) {
|
|
266
|
+
return cache[dpCode];
|
|
267
|
+
}
|
|
268
|
+
}
|
|
269
|
+
if (!_this.isInit) {
|
|
270
|
+
return false;
|
|
271
|
+
}
|
|
272
|
+
// 是否存在相关dp
|
|
273
|
+
const isDpSupport = _this.supportDp(dpCode, devInfo);
|
|
274
|
+
cache[dpCode] = isDpSupport;
|
|
275
|
+
return isDpSupport;
|
|
276
|
+
};
|
|
277
|
+
})();
|
|
278
|
+
isGroupDevice(devInfo) {
|
|
279
|
+
if (devInfo) {
|
|
280
|
+
return !!devInfo.groupId;
|
|
281
|
+
}
|
|
282
|
+
this.devInfo = this.getCachedDevInfo();
|
|
283
|
+
return !!this.devInfo.groupId;
|
|
284
|
+
}
|
|
285
|
+
|
|
286
|
+
/** 获取 devInfo */
|
|
287
|
+
getDevInfo() {
|
|
288
|
+
this.devInfo = this.getCachedDevInfo();
|
|
289
|
+
if (!this.devInfo) {
|
|
290
|
+
!this.isIniting && ScheduleLogger.warn('getDevInfo', 'this.getDevInfo is undefined');
|
|
291
|
+
!this.isIniting && ScheduleLogger.warn('请提前调用 useScheduleInit 的 init 方法');
|
|
292
|
+
return {};
|
|
293
|
+
}
|
|
294
|
+
return this.devInfo;
|
|
295
|
+
}
|
|
296
|
+
|
|
297
|
+
// 获取群组设备信息
|
|
298
|
+
getGroupDevInfo() {
|
|
299
|
+
if (!this.groupDevInfo) {
|
|
300
|
+
!this.isIniting && ScheduleLogger.warn('getGroupDevInfo', 'this.getGroupDevInfo is undefined');
|
|
301
|
+
!this.isIniting && ScheduleLogger.warn('请提前调用 useScheduleInit 的 init 方法');
|
|
302
|
+
}
|
|
303
|
+
return this.groupDevInfo;
|
|
304
|
+
}
|
|
305
|
+
getMergeDevInfo() {
|
|
306
|
+
this.devInfo = this.getCachedDevInfo();
|
|
307
|
+
return _objectSpread(_objectSpread({}, this.devInfo), this.groupDevInfo);
|
|
308
|
+
}
|
|
309
|
+
|
|
310
|
+
/**
|
|
311
|
+
* @description 判断是否是 WiFi Device
|
|
312
|
+
*/
|
|
313
|
+
isWifiDevice = devInfo => {
|
|
314
|
+
return this.hasCapability(DeviceCapability.WIFI, devInfo);
|
|
315
|
+
};
|
|
316
|
+
|
|
317
|
+
/**
|
|
318
|
+
* @description 判断是否是Zigbee Device
|
|
319
|
+
*/
|
|
320
|
+
isZigbeeDevice = devInfo => {
|
|
321
|
+
return this.hasCapability(DeviceCapability.ZIGBEE, devInfo);
|
|
322
|
+
};
|
|
323
|
+
|
|
324
|
+
/**
|
|
325
|
+
* @description 判断是否是 SigMesh Device
|
|
326
|
+
*/
|
|
327
|
+
isSigMeshDevice = devInfo => {
|
|
328
|
+
return this.hasCapability(DeviceCapability.SIGMESH, devInfo);
|
|
329
|
+
};
|
|
330
|
+
|
|
331
|
+
/**
|
|
332
|
+
* 是否是蓝牙设备
|
|
333
|
+
* */
|
|
334
|
+
isBleDevice = devInfo => {
|
|
335
|
+
return this.hasCapability(DeviceCapability.BLUETOOTH, devInfo) || this.hasCapability(DeviceCapability.BLEMESH, devInfo) || this.hasCapability(DeviceCapability.SIGMESH, devInfo);
|
|
336
|
+
};
|
|
337
|
+
|
|
338
|
+
/**
|
|
339
|
+
* @description 是否是 Matter 设备
|
|
340
|
+
*/
|
|
341
|
+
isMatterDevice(devInfo) {
|
|
342
|
+
var _this$devInfo3;
|
|
343
|
+
if (devInfo) {
|
|
344
|
+
return !!devInfo.isMatter;
|
|
345
|
+
}
|
|
346
|
+
this.devInfo = this.getCachedDevInfo();
|
|
347
|
+
return !!((_this$devInfo3 = this.devInfo) !== null && _this$devInfo3 !== void 0 && _this$devInfo3.isMatter);
|
|
348
|
+
}
|
|
349
|
+
|
|
350
|
+
/**
|
|
351
|
+
* @description 是否是 涂鸦 Matter 设备
|
|
352
|
+
*/
|
|
353
|
+
isTuyaMatterDevice(devInfo) {
|
|
354
|
+
var _this$devInfo4, _this$devInfo5;
|
|
355
|
+
if (devInfo) {
|
|
356
|
+
return !!(devInfo !== null && devInfo !== void 0 && devInfo.isMatter && !(devInfo !== null && devInfo !== void 0 && devInfo.isTripartiteMatter));
|
|
357
|
+
}
|
|
358
|
+
this.devInfo = this.getCachedDevInfo();
|
|
359
|
+
return !!((_this$devInfo4 = this.devInfo) !== null && _this$devInfo4 !== void 0 && _this$devInfo4.isMatter && !((_this$devInfo5 = this.devInfo) !== null && _this$devInfo5 !== void 0 && _this$devInfo5.isTripartiteMatter));
|
|
360
|
+
}
|
|
361
|
+
|
|
362
|
+
/**
|
|
363
|
+
* @description 是否是 三方 Matter 设备
|
|
364
|
+
*/
|
|
365
|
+
isTripartiteMatter(devInfo) {
|
|
366
|
+
var _this$devInfo6;
|
|
367
|
+
if (devInfo) {
|
|
368
|
+
return !!devInfo.isTripartiteMatter;
|
|
369
|
+
}
|
|
370
|
+
this.devInfo = this.getCachedDevInfo();
|
|
371
|
+
return !!((_this$devInfo6 = this.devInfo) !== null && _this$devInfo6 !== void 0 && _this$devInfo6.isTripartiteMatter);
|
|
372
|
+
}
|
|
373
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 根据dpId获取dpCode
|
|
3
|
+
* @param dpId dpId
|
|
4
|
+
* @returns dpCode
|
|
5
|
+
*/
|
|
6
|
+
export declare const getDpCodeByDpId: (dpId: number) => string | null;
|
|
7
|
+
/**
|
|
8
|
+
* 根据dpCode获取dpId
|
|
9
|
+
* @param dpCode dpCode
|
|
10
|
+
* @returns dpId
|
|
11
|
+
*/
|
|
12
|
+
export declare const getDpIdByDpCode: (dpCode: string) => number | null;
|