@ray-js/lamp-schedule-core 1.0.1-beta-2 → 1.0.1-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.
|
@@ -4,7 +4,7 @@ import "core-js/modules/esnext.iterator.every.js";
|
|
|
4
4
|
import "core-js/modules/esnext.iterator.for-each.js";
|
|
5
5
|
import "core-js/modules/esnext.iterator.some.js";
|
|
6
6
|
import { useEffect, useMemo, useRef, useState } from 'react';
|
|
7
|
-
import { getDeviceInfo, getGroupDpsInfos, onDpDataChange, registerDeviceListListener } from '@ray-js/ray';
|
|
7
|
+
import { getDeviceInfo, getGroupDpsInfos, onDpDataChange, onGroupDpDataChangeEvent, registerDeviceListListener, registerGroupChange, offDpDataChange, offGroupDpDataChangeEvent } from '@ray-js/ray';
|
|
8
8
|
import { Support } from '../utils/ScheduleSupport';
|
|
9
9
|
import { useTimerContext } from '../context/timer/context';
|
|
10
10
|
import { scheduleLogger, scheduleLogger as ScheduleLogger } from '../utils/ScheduleLogger';
|
|
@@ -68,7 +68,7 @@ export const useScheduleInit = props => {
|
|
|
68
68
|
// eslint-disable-next-line consistent-return
|
|
69
69
|
useEffect(() => {
|
|
70
70
|
if (_isInit) {
|
|
71
|
-
return;
|
|
71
|
+
return null;
|
|
72
72
|
}
|
|
73
73
|
if (props.devId) {
|
|
74
74
|
registerDeviceListListener({
|
|
@@ -94,6 +94,48 @@ export const useScheduleInit = props => {
|
|
|
94
94
|
}
|
|
95
95
|
});
|
|
96
96
|
}
|
|
97
|
+
if (props.groupId) {
|
|
98
|
+
registerGroupChange({
|
|
99
|
+
groupIdList: [props.groupId],
|
|
100
|
+
success: () => {
|
|
101
|
+
// 监听dp值变化 并触发
|
|
102
|
+
|
|
103
|
+
if (_isInit) {
|
|
104
|
+
ScheduleLogger.warn('useSupport: support is already initialized');
|
|
105
|
+
return;
|
|
106
|
+
}
|
|
107
|
+
onGroupDpDataChangeEvent(res => {
|
|
108
|
+
if (!(res !== null && res !== void 0 && res.dps)) {
|
|
109
|
+
ScheduleLogger.warn(`useScheduleInit fail ${DP_CHANGE_EVENT_KEY}`, res);
|
|
110
|
+
return;
|
|
111
|
+
}
|
|
112
|
+
ScheduleLogger.info(`useScheduleInit ${DP_CHANGE_EVENT_KEY}`, res);
|
|
113
|
+
emitter.emit(DP_CHANGE_EVENT_KEY, {
|
|
114
|
+
deviceId: res.devId || res.deviceId,
|
|
115
|
+
dps: res === null || res === void 0 ? void 0 : res.dps
|
|
116
|
+
});
|
|
117
|
+
});
|
|
118
|
+
}
|
|
119
|
+
});
|
|
120
|
+
}
|
|
121
|
+
return () => {
|
|
122
|
+
offDpDataChange({
|
|
123
|
+
success() {
|
|
124
|
+
ScheduleLogger.info('useScheduleInit offDpDataChange success');
|
|
125
|
+
},
|
|
126
|
+
fail(err) {
|
|
127
|
+
ScheduleLogger.error('useScheduleInit offDpDataChange fail', err);
|
|
128
|
+
}
|
|
129
|
+
});
|
|
130
|
+
offGroupDpDataChangeEvent({
|
|
131
|
+
success() {
|
|
132
|
+
ScheduleLogger.info('useScheduleInit offGroupDpDataChangeEvent success');
|
|
133
|
+
},
|
|
134
|
+
fail(err) {
|
|
135
|
+
ScheduleLogger.error('useScheduleInit offGroupDpDataChangeEvent fail', err);
|
|
136
|
+
}
|
|
137
|
+
});
|
|
138
|
+
};
|
|
97
139
|
}, [_isInit, actions]);
|
|
98
140
|
useEffect(() => {
|
|
99
141
|
if (!props.devId && !props.groupId) {
|