Skip to content

Commit

Permalink
handling enums and bitmaps declared as unsigned integers in Unify XML (
Browse files Browse the repository at this point in the history
…#1468)

* handling enums and bitmaps declared as unsigned integers in Unify XML 
* logging warnings for each inconsistency
  • Loading branch information
dhchandw authored Oct 24, 2024
1 parent fbb31a9 commit c9e27b5
Showing 1 changed file with 21 additions and 4 deletions.
25 changes: 21 additions & 4 deletions src-electron/zcl/zcl-loader-dotdot.js
Original file line number Diff line number Diff line change
Expand Up @@ -947,12 +947,19 @@ async function processString(db, filePath, packageId, data) {
* @param {*} dataType
* @returns An Object
*/
function prepareEnumsOrBitmaps(a, dataType) {
function prepareEnumsOrBitmaps(a, dataTypeRef, dataType) {
if (a.type.toLowerCase().includes('uint')) {
let correctedType = dataType == dbEnum.zclType.enum ? 'enum' : 'map'
env.logWarning(
`Warning: ${a.name} is declared incorrectly as ${a.type} in XML. Replace ${a.type} with ${correctedType} type.`
)
a.type = a.type.toLowerCase().replace('uint', correctedType)
}
return {
name: a.name,
type: a.type.toLowerCase(),
cluster_code: a.cluster ? a.cluster : null,
discriminator_ref: dataType
discriminator_ref: dataTypeRef
}
}

Expand All @@ -971,7 +978,13 @@ async function processEnums(db, filePath, packageId, data) {
return queryLoader.insertEnum(
db,
[packageId],
data.map((x) => prepareEnumsOrBitmaps(x, typeMap.get(dbEnum.zclType.enum)))
data.map((x) =>
prepareEnumsOrBitmaps(
x,
typeMap.get(dbEnum.zclType.enum),
dbEnum.zclType.enum
)
)
)
}

Expand Down Expand Up @@ -1024,7 +1037,11 @@ async function processBitmaps(db, filePath, packageId, data) {
db,
[packageId],
data.map((x) =>
prepareEnumsOrBitmaps(x, typeMap.get(dbEnum.zclType.bitmap))
prepareEnumsOrBitmaps(
x,
typeMap.get(dbEnum.zclType.bitmap),
dbEnum.zclType.bitmap
)
)
)
}
Expand Down

0 comments on commit c9e27b5

Please sign in to comment.