@@ -1012,7 +1012,11 @@ function prepareDataType(a, dataType, typeMap) {
1012
1012
id : parseInt ( a . $ . id ) ,
1013
1013
description : a . $ . description ? a . $ . description : a . $ . name ,
1014
1014
discriminator_ref : dataType ? dataType : dataTypeRef ,
1015
- cluster_code : a . cluster ? a . cluster : null ,
1015
+ cluster_code : a . cluster
1016
+ ? a . cluster
1017
+ : a . $ . cluster_code
1018
+ ? [ { $ : { code : a . $ . cluster_code [ 0 ] } } ]
1019
+ : null , // else case: Treating features in a cluster as a bitmap
1016
1020
}
1017
1021
}
1018
1022
@@ -1274,7 +1278,11 @@ function prepareEnumOrBitmap(db, packageId, a, dataType, typeMap) {
1274
1278
return {
1275
1279
name : a . $ . name ,
1276
1280
type : a . $ . type . toLowerCase ( ) ,
1277
- cluster_code : a . cluster ? a . cluster : null ,
1281
+ cluster_code : a . cluster
1282
+ ? a . cluster
1283
+ : a . $ . cluster_code
1284
+ ? [ { $ : { code : a . $ . cluster_code [ 0 ] } } ]
1285
+ : null , // else case: Treating features in a cluster as a bitmap
1278
1286
discriminator_ref : dataType ,
1279
1287
}
1280
1288
}
@@ -1420,21 +1428,40 @@ async function processBitmapFields(
1420
1428
env . logDebug ( `${ filePath } , ${ packageId } : ${ data . length } Bitmap Fields.` )
1421
1429
let bitmapFields = [ ]
1422
1430
let lastFieldId = - 1
1423
- data . forEach ( ( bm ) => {
1424
- if ( 'field' in bm ) {
1425
- bm . field . forEach ( ( item ) => {
1426
- let defaultFieldId = lastFieldId + 1
1427
- lastFieldId = item . $ . fieldId ? parseInt ( item . $ . fieldId ) : defaultFieldId
1428
- bitmapFields . push ( {
1429
- bitmapName : bm . $ . name ,
1430
- bitmapClusterCode : bm . cluster ? bm . cluster : null ,
1431
- name : item . $ . name ,
1432
- mask : parseInt ( item . $ . mask ) ,
1433
- fieldIdentifier : lastFieldId ,
1431
+ if ( ! ( 'features' in data ) ) {
1432
+ data . forEach ( ( bm ) => {
1433
+ if ( 'field' in bm ) {
1434
+ bm . field . forEach ( ( item ) => {
1435
+ let defaultFieldId = lastFieldId + 1
1436
+ lastFieldId = item . $ . fieldId
1437
+ ? parseInt ( item . $ . fieldId )
1438
+ : defaultFieldId
1439
+ bitmapFields . push ( {
1440
+ bitmapName : bm . $ . name ,
1441
+ bitmapClusterCode : bm . cluster ? bm . cluster : null ,
1442
+ name : item . $ . name ,
1443
+ mask : parseInt ( item . $ . mask ) ,
1444
+ fieldIdentifier : lastFieldId ,
1445
+ } )
1434
1446
} )
1447
+ }
1448
+ } )
1449
+ // Treating features in a cluster as a bitmap
1450
+ } else if (
1451
+ 'features' in data &&
1452
+ data . features . length == 1 &&
1453
+ 'feature' in data . features [ 0 ]
1454
+ ) {
1455
+ data . features [ 0 ] . feature . forEach ( ( item ) => {
1456
+ bitmapFields . push ( {
1457
+ bitmapName : 'Feature' ,
1458
+ bitmapClusterCode : [ { $ : { code : data . code [ 0 ] } } ] ,
1459
+ name : item . $ . name ,
1460
+ mask : 1 << item . $ . bit ,
1461
+ fieldIdentifier : item . $ . bit ,
1435
1462
} )
1436
- }
1437
- } )
1463
+ } )
1464
+ }
1438
1465
return queryLoader . insertBitmapFields (
1439
1466
db ,
1440
1467
packageId ,
@@ -1577,7 +1604,7 @@ function prepareDeviceType(deviceType) {
1577
1604
if ( 'features' in include ) {
1578
1605
include . features [ 0 ] . feature . forEach ( ( f ) => {
1579
1606
// Only adding madatory features for now
1580
- if ( f . mandatoryConform [ 0 ] === '' ) {
1607
+ if ( f . mandatoryConform && f . mandatoryConform [ 0 ] === '' ) {
1581
1608
features . push ( f . $ . name )
1582
1609
}
1583
1610
} )
@@ -1637,6 +1664,7 @@ async function processParsedZclData(
1637
1664
let packageId = argument . packageId
1638
1665
previouslyKnownPackages . add ( packageId )
1639
1666
let knownPackages = Array . from ( previouslyKnownPackages )
1667
+ let featureClusters = [ ]
1640
1668
1641
1669
if ( ! ( 'result' in argument ) ) {
1642
1670
return [ ]
@@ -1685,6 +1713,7 @@ async function processParsedZclData(
1685
1713
)
1686
1714
}
1687
1715
if ( 'cluster' in toplevel ) {
1716
+ featureClusters = toplevel . cluster . filter ( ( c ) => 'features' in c )
1688
1717
batch2 . push (
1689
1718
processClusters ( db , filePath , packageId , toplevel . cluster , context )
1690
1719
)
@@ -1717,6 +1746,31 @@ async function processParsedZclData(
1717
1746
)
1718
1747
)
1719
1748
}
1749
+
1750
+ // Treating features in a cluster as a bitmap
1751
+ if ( featureClusters . length > 0 ) {
1752
+ featureClusters . forEach ( ( fc ) => {
1753
+ batch3 . push (
1754
+ processDataType (
1755
+ db ,
1756
+ filePath ,
1757
+ packageId ,
1758
+ knownPackages ,
1759
+ [
1760
+ {
1761
+ $ : {
1762
+ name : 'Feature' ,
1763
+ type : 'BITMAP32' ,
1764
+ cluster_code : [ fc . code [ 0 ] ] ,
1765
+ } ,
1766
+ } ,
1767
+ ] ,
1768
+ dbEnum . zclType . bitmap
1769
+ )
1770
+ )
1771
+ } )
1772
+ }
1773
+
1720
1774
if ( dbEnum . zclType . enum in toplevel ) {
1721
1775
batch3 . push (
1722
1776
processDataType (
@@ -1785,6 +1839,22 @@ async function processParsedZclData(
1785
1839
processBitmap ( db , filePath , packageId , knownPackages , toplevel . bitmap )
1786
1840
)
1787
1841
}
1842
+ // Treating features in a cluster as a bitmap
1843
+ if ( featureClusters . length > 0 ) {
1844
+ featureClusters . forEach ( ( fc ) => {
1845
+ Batch5 . push (
1846
+ processBitmap ( db , filePath , packageId , knownPackages , [
1847
+ {
1848
+ $ : {
1849
+ name : 'Feature' ,
1850
+ type : 'BITMAP32' ,
1851
+ cluster_code : [ fc . code [ 0 ] ] ,
1852
+ } ,
1853
+ } ,
1854
+ ] )
1855
+ )
1856
+ } )
1857
+ }
1788
1858
if ( dbEnum . zclType . struct in toplevel ) {
1789
1859
Batch5 . push (
1790
1860
processStruct ( db , filePath , packageId , knownPackages , toplevel . struct )
@@ -1810,6 +1880,14 @@ async function processParsedZclData(
1810
1880
)
1811
1881
)
1812
1882
}
1883
+ // Treating features in a cluster as a bitmap
1884
+ if ( featureClusters . length > 0 ) {
1885
+ featureClusters . forEach ( ( fc ) => {
1886
+ batch6 . push (
1887
+ processBitmapFields ( db , filePath , packageId , knownPackages , fc )
1888
+ )
1889
+ } )
1890
+ }
1813
1891
if ( dbEnum . zclType . struct in toplevel ) {
1814
1892
batch6 . push (
1815
1893
processStructItems (
0 commit comments