@ray-js/lamp-schedule-core 1.0.1-beta-4 → 1.0.1-beta-6

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.
@@ -31,7 +31,7 @@ export function useBaseLightDp(dpCode, defaultDpValue) {
31
31
  if (+dpCode !== +dpCode) {
32
32
  dpId = getDpIdByDpCode(dpCode);
33
33
  }
34
- if (dpData.deviceId === deviceId && dpId in dpData.dps) {
34
+ if (dpId in dpData.dps) {
35
35
  scheduleLogger.debug(`${dpCode} ==> emitter will changed:`, dpData);
36
36
  const _dpValue = dpData.dps[dpId];
37
37
  if (isEqual(preDpValue.current, _dpValue)) {
@@ -105,13 +105,18 @@ export const getDpDataByMesh = function () {
105
105
  if (dpCodes.length >= 5) {
106
106
  scheduleLogger.warn('getDpDataByMesh: 单次查询 dp 数过多,dp 可能响应不及时,请分次查询');
107
107
  }
108
- scheduleLogger.debug('getDpDataByMesh 开始查询DP参数 dpCodes:', dpCodes);
109
108
  const deviceData = devIdOrGroupIdCache.get();
110
109
  const deviceId = deviceData === null || deviceData === void 0 ? void 0 : deviceData.devId;
110
+ const groupId = deviceData === null || deviceData === void 0 ? void 0 : deviceData.groupId;
111
+ if (groupId) {
112
+ scheduleLogger.error('getDpDataByMesh: 群组中不支持查询dp');
113
+ return;
114
+ }
111
115
  if (!deviceId) {
112
116
  scheduleLogger.error('getDpDataByMesh: 未能获取到deviceId');
113
117
  return;
114
118
  }
119
+ scheduleLogger.debug('getDpDataByMesh 开始查询DP参数 dpCodes:', dpCodes);
115
120
  const dpIds = dpCodes.map(item => getDpIdByDpCode(item)).filter(i => !!i).map(String); // 简化字符串转换
116
121
 
117
122
  if (dpIds.length === 0) {
@@ -72,47 +72,47 @@ export const useScheduleInit = props => {
72
72
  return null;
73
73
  }
74
74
  ScheduleLogger.info('useScheduleInit props: ', props);
75
- if (props.devId) {
76
- ScheduleLogger.info('useScheduleInit registerDeviceListListener devId: ', props.devId);
77
- registerDeviceListListener({
78
- deviceIdList: [props.devId],
79
- success: () => {
75
+ // 必须先注册群组,再注册设备, 群组中也存在 devId
76
+ if (props.groupId) {
77
+ ScheduleLogger.info('useScheduleInit registerGroupChange groupId: ', props.groupId);
78
+ registerGroupChange({
79
+ groupIdList: [props.groupId],
80
+ success(res) {
81
+ ScheduleLogger.info('useScheduleInit registerGroupChange success: ', res);
80
82
  // 监听dp值变化 并触发
81
83
 
82
84
  if (_isInit) {
83
85
  ScheduleLogger.warn('useSupport: support is already initialized');
84
86
  return;
85
87
  }
86
- onDpDataChange(res => {
88
+ onGroupDpDataChangeEvent(res => {
87
89
  if (!(res !== null && res !== void 0 && res.dps)) {
88
90
  ScheduleLogger.warn(`useScheduleInit fail ${DP_CHANGE_EVENT_KEY}`, res);
89
91
  return;
90
92
  }
91
93
  ScheduleLogger.info(`useScheduleInit ${DP_CHANGE_EVENT_KEY}`, res);
92
94
  emitter.emit(DP_CHANGE_EVENT_KEY, {
93
- deviceId: res.devId || res.deviceId,
95
+ deviceId: res.devId || res.deviceId || res.groupId,
94
96
  dps: res === null || res === void 0 ? void 0 : res.dps
95
97
  });
96
98
  });
97
99
  },
98
100
  fail(err) {
99
- ScheduleLogger.error('useScheduleInit registerDeviceListListener fail', err);
101
+ ScheduleLogger.error('useScheduleInit registerGroupChange fail', err);
100
102
  }
101
103
  });
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);
104
+ } else if (props.devId) {
105
+ ScheduleLogger.info('useScheduleInit registerDeviceListListener devId: ', props.devId);
106
+ registerDeviceListListener({
107
+ deviceIdList: [props.devId],
108
+ success: () => {
109
109
  // 监听dp值变化 并触发
110
110
 
111
111
  if (_isInit) {
112
112
  ScheduleLogger.warn('useSupport: support is already initialized');
113
113
  return;
114
114
  }
115
- onGroupDpDataChangeEvent(res => {
115
+ onDpDataChange(res => {
116
116
  if (!(res !== null && res !== void 0 && res.dps)) {
117
117
  ScheduleLogger.warn(`useScheduleInit fail ${DP_CHANGE_EVENT_KEY}`, res);
118
118
  return;
@@ -125,7 +125,7 @@ export const useScheduleInit = props => {
125
125
  });
126
126
  },
127
127
  fail(err) {
128
- ScheduleLogger.error('useScheduleInit registerGroupChange fail', err);
128
+ ScheduleLogger.error('useScheduleInit registerDeviceListListener fail', err);
129
129
  }
130
130
  });
131
131
  }
@@ -103,7 +103,13 @@ export class Support {
103
103
  setScheduleCache(DEV_INFO_KEY, res);
104
104
  // 群组中为空
105
105
  groupId && (devIdOrGroupIdCache === null || devIdOrGroupIdCache === void 0 ? void 0 : devIdOrGroupIdCache.set('', groupId));
106
- resolve(true);
106
+ const dpMap = {};
107
+ Object.keys(res.dps).forEach(dpId => {
108
+ const dpCode = getDpCodeByDpId(dpId);
109
+ dpCode && setDpState(dpCode, res.dps[dpId]);
110
+ });
111
+ Object.keys(dpMap).length && initDpState(dpMap);
112
+ resolve(res);
107
113
  },
108
114
  fail: err => {
109
115
  this.groupDevInfo = {};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ray-js/lamp-schedule-core",
3
- "version": "1.0.1-beta-4",
3
+ "version": "1.0.1-beta-6",
4
4
  "description": "照明计划模块核心能力",
5
5
  "main": "./lib/index.js",
6
6
  "files": [