diff --git a/src-electron/generator/helper-zcl.js b/src-electron/generator/helper-zcl.js index 26d3906a7f..6ec8a74b5d 100644 --- a/src-electron/generator/helper-zcl.js +++ b/src-electron/generator/helper-zcl.js @@ -731,24 +731,31 @@ function zcl_global_commands(options) { * @param {*} options * @returns Promise of attribute iteration. */ -function zcl_attributes(options) { +async function zcl_attributes(options) { // If used at the toplevel, 'this' is the toplevel context object. // when used at the cluster level, 'this' is a cluster - let promise = templateUtil - .ensureZclPackageIds(this) - .then((packageIds) => { - if ('id' in this) { - // We're functioning inside a nested context with an id, so we will only query for this cluster. - return queryZcl.selectAttributesByClusterIdIncludingGlobal( - this.global.db, - this.id, - packageIds - ) - } else { - return queryZcl.selectAllAttributes(this.global.db, packageIds) - } - }) - .then((atts) => templateUtil.collectBlocks(atts, options, this)) + let packageIds = await templateUtil.ensureZclPackageIds(this) + let attributes = '' + if ('id' in this) { + // We're functioning inside a nested context with an id, so we will only query for this cluster. + attributes = await queryZcl.selectAttributesByClusterIdIncludingGlobal( + this.global.db, + this.id, + packageIds + ) + attributes = await upgrade.computeStorageTemplate( + this.global.db, + this.id, + attributes + ) + } else { + attributes = await queryZcl.selectAllAttributes(this.global.db, packageIds) + } + if ('removeKeys' in options.hash) { + let keys = options.hash.removeKeys.split(',') + keys.forEach((k) => attributes.map((attr) => delete attr[k.trim()])) + } + let promise = templateUtil.collectBlocks(attributes, options, this) return templateUtil.templatePromise(this.global, promise) } diff --git a/src-electron/upgrade/upgrade.js b/src-electron/upgrade/upgrade.js index cfbba41b4b..6590c578e7 100644 --- a/src-electron/upgrade/upgrade.js +++ b/src-electron/upgrade/upgrade.js @@ -62,22 +62,27 @@ async function getForcedExternalStorage(db, attributeId) { async function computeStorageTemplate(db, clusterRef, attributes) { let clusterName let forcedExternal - clusterName = await queryCluster.selectClusterName(db, clusterRef) - return await Promise.all( - await attributes.map(async (attribute) => { - forcedExternal = await getForcedExternalStorage(db, attribute.id) - if ( - forcedExternal.byName && - forcedExternal.byName[clusterName] && - forcedExternal.byName[clusterName].includes(attribute.name) - ) { - attribute.storagePolicy = dbEnum.storagePolicy.attributeAccessInterface - return attribute - } else { - return attribute - } - }) - ) + if (clusterRef == null) { + clusterName = await queryCluster.selectClusterName(db, clusterRef) + return await Promise.all( + await attributes.map(async (attribute) => { + forcedExternal = await getForcedExternalStorage(db, attribute.id) + if ( + forcedExternal.byName && + forcedExternal.byName[clusterName] && + forcedExternal.byName[clusterName].includes(attribute.name) + ) { + attribute.storagePolicy = + dbEnum.storagePolicy.attributeAccessInterface + return attribute + } else { + return attribute + } + }) + ) + } else { + return attributes + } } /**