@ray-js/lamp-schedule-core 1.0.1-beta-2 → 1.0.1-beta-4
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,9 +68,12 @@ export const useScheduleInit = props => {
|
|
|
68
68
|
// eslint-disable-next-line consistent-return
|
|
69
69
|
useEffect(() => {
|
|
70
70
|
if (_isInit) {
|
|
71
|
-
|
|
71
|
+
ScheduleLogger.info('useScheduleInit is already initialized');
|
|
72
|
+
return null;
|
|
72
73
|
}
|
|
74
|
+
ScheduleLogger.info('useScheduleInit props: ', props);
|
|
73
75
|
if (props.devId) {
|
|
76
|
+
ScheduleLogger.info('useScheduleInit registerDeviceListListener devId: ', props.devId);
|
|
74
77
|
registerDeviceListListener({
|
|
75
78
|
deviceIdList: [props.devId],
|
|
76
79
|
success: () => {
|
|
@@ -91,9 +94,59 @@ export const useScheduleInit = props => {
|
|
|
91
94
|
dps: res === null || res === void 0 ? void 0 : res.dps
|
|
92
95
|
});
|
|
93
96
|
});
|
|
97
|
+
},
|
|
98
|
+
fail(err) {
|
|
99
|
+
ScheduleLogger.error('useScheduleInit registerDeviceListListener fail', err);
|
|
100
|
+
}
|
|
101
|
+
});
|
|
102
|
+
}
|
|
103
|
+
if (props.groupId) {
|
|
104
|
+
ScheduleLogger.info('useScheduleInit registerGroupChange groupId: ', props.groupId);
|
|
105
|
+
registerGroupChange({
|
|
106
|
+
groupIdList: [props.groupId],
|
|
107
|
+
success(res) {
|
|
108
|
+
ScheduleLogger.info('useScheduleInit registerGroupChange success: ', res);
|
|
109
|
+
// 监听dp值变化 并触发
|
|
110
|
+
|
|
111
|
+
if (_isInit) {
|
|
112
|
+
ScheduleLogger.warn('useSupport: support is already initialized');
|
|
113
|
+
return;
|
|
114
|
+
}
|
|
115
|
+
onGroupDpDataChangeEvent(res => {
|
|
116
|
+
if (!(res !== null && res !== void 0 && res.dps)) {
|
|
117
|
+
ScheduleLogger.warn(`useScheduleInit fail ${DP_CHANGE_EVENT_KEY}`, res);
|
|
118
|
+
return;
|
|
119
|
+
}
|
|
120
|
+
ScheduleLogger.info(`useScheduleInit ${DP_CHANGE_EVENT_KEY}`, res);
|
|
121
|
+
emitter.emit(DP_CHANGE_EVENT_KEY, {
|
|
122
|
+
deviceId: res.devId || res.deviceId,
|
|
123
|
+
dps: res === null || res === void 0 ? void 0 : res.dps
|
|
124
|
+
});
|
|
125
|
+
});
|
|
126
|
+
},
|
|
127
|
+
fail(err) {
|
|
128
|
+
ScheduleLogger.error('useScheduleInit registerGroupChange fail', err);
|
|
94
129
|
}
|
|
95
130
|
});
|
|
96
131
|
}
|
|
132
|
+
return () => {
|
|
133
|
+
offDpDataChange({
|
|
134
|
+
success() {
|
|
135
|
+
ScheduleLogger.info('useScheduleInit offDpDataChange success');
|
|
136
|
+
},
|
|
137
|
+
fail(err) {
|
|
138
|
+
ScheduleLogger.error('useScheduleInit offDpDataChange fail', err);
|
|
139
|
+
}
|
|
140
|
+
});
|
|
141
|
+
offGroupDpDataChangeEvent({
|
|
142
|
+
success() {
|
|
143
|
+
ScheduleLogger.info('useScheduleInit offGroupDpDataChangeEvent success');
|
|
144
|
+
},
|
|
145
|
+
fail(err) {
|
|
146
|
+
ScheduleLogger.error('useScheduleInit offGroupDpDataChangeEvent fail', err);
|
|
147
|
+
}
|
|
148
|
+
});
|
|
149
|
+
};
|
|
97
150
|
}, [_isInit, actions]);
|
|
98
151
|
useEffect(() => {
|
|
99
152
|
if (!props.devId && !props.groupId) {
|