Skip to content

Commit

Permalink
only change globals
Browse files Browse the repository at this point in the history
  • Loading branch information
paulr34 committed Oct 11, 2023
1 parent e43997e commit bf2fe5a
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 32 deletions.
39 changes: 23 additions & 16 deletions src-electron/generator/helper-zcl.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}

Expand Down
37 changes: 21 additions & 16 deletions src-electron/upgrade/upgrade.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}

/**
Expand Down

0 comments on commit bf2fe5a

Please sign in to comment.