Skip to content

Commit

Permalink
Updating zcl_attributes_server to replace chip_server_cluster_attributes
Browse files Browse the repository at this point in the history
- Updating zcl_attributes_server block helper such that it can behave like chip_server_cluster_attributes.
- Updating attribute map such that it can be used more widely
- Github: ZAP#898
  • Loading branch information
brdandu committed Mar 3, 2023
1 parent 149559b commit 2d8516b
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 23 deletions.
7 changes: 6 additions & 1 deletion src-electron/db/db-mapping.js
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ exports.map = {
manufacturerCode: x.MANUFACTURER_CODE,
name: x.NAME,
label: x.NAME,
type: x.TYPE,
type: x.TYPE != 'array' ? x.TYPE : x.ARRAY_TYPE,
side: x.SIDE,
define: x.DEFINE,
min: x.MIN,
Expand All @@ -106,15 +106,20 @@ exports.map = {
reportableChange: x.REPORTABLE_CHANGE,
reportableChangeLength: x.REPORTABLE_CHANGE_LENGTH,
isWritable: dbApi.fromDbBool(x.IS_WRITABLE),
isWritableAttribute: dbApi.fromDbBool(x.IS_WRITABLE),
isNullable: dbApi.fromDbBool(x.IS_NULLABLE),
defaultValue: x.DEFAULT_VALUE,
isOptional: dbApi.fromDbBool(x.IS_OPTIONAL),
isReportable:
x.REPORTING_POLICY == dbEnums.reportingPolicy.mandatory ||
x.REPORTING_POLICY == dbEnums.reportingPolicy.suggested,
isReportableAttribute:
x.REPORTING_POLICY == dbEnums.reportingPolicy.mandatory ||
x.REPORTING_POLICY == dbEnums.reportingPolicy.suggested,
reportingPolicy: x.REPORTING_POLICY,
isSceneRequired: dbApi.fromDbBool(x.IS_SCENE_REQUIRED),
entryType: x.ARRAY_TYPE,
isArray: x.ARRAY_TYPE ? 1 : 0,
mustUseTimedWrite: dbApi.fromDbBool(x.MUST_USE_TIMED_WRITE),
}
},
Expand Down
49 changes: 27 additions & 22 deletions src-electron/generator/helper-zcl.js
Original file line number Diff line number Diff line change
Expand Up @@ -730,33 +730,38 @@ function zcl_attributes_client(options) {
* Iterator over the server attributes. If it is used at toplevel, if iterates over all the server attributes
* in the database. If used within zcl_cluster context, it iterates over all the server attributes
* that belong to that cluster.
*
* Available Options:
* - removeKey: Removes one of the keys from the map(for eg keys in db-mapping.js)
* fo eg: (#zcl_attributes_server removeKey='isOptional') will remove 'isOptional'
* from the results
* @param {*} options
* @returns Promise of attribute iteration.
*/
function zcl_attributes_server(options) {
async function zcl_attributes_server(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.selectAttributesByClusterIdAndSideIncludingGlobal(
this.global.db,
this.id,
packageIds,
dbEnum.side.server
)
} else {
return queryZcl.selectAllAttributesBySide(
this.global.db,
dbEnum.side.server,
packageIds
)
}
})
.then((atts) => templateUtil.collectBlocks(atts, options, this))
let packageIds = await templateUtil.ensureZclPackageIds(this)
let serverAttributes = ''
if ('id' in this) {
// We're functioning inside a nested context with an id, so we will only query for this cluster.
serverAttributes =
await queryZcl.selectAttributesByClusterIdAndSideIncludingGlobal(
this.global.db,
this.id,
packageIds,
dbEnum.side.server
)
} else {
serverAttributes = await queryZcl.selectAllAttributesBySide(
this.global.db,
dbEnum.side.server,
packageIds
)
}
if ('removeKey' in options.hash) {
serverAttributes.map((attr) => delete attr[options.hash.removeKey])
}
let promise = templateUtil.collectBlocks(serverAttributes, options, this)
return templateUtil.templatePromise(this.global, promise)
}

Expand Down

0 comments on commit 2d8516b

Please sign in to comment.