Skip to content

Commit d439600

Browse files
authored
Adapt ZAP to Support Both List Type Definition Formats for Attributes (#1530)
* support parsing list type in both formats * add unit test
1 parent b7c0b36 commit d439600

File tree

3 files changed

+48
-1
lines changed

3 files changed

+48
-1
lines changed

src-electron/zcl/zcl-loader-silabs.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -630,6 +630,12 @@ function prepareCluster(cluster, context, isExtension = false) {
630630
attribute.$.reportingPolicy
631631
)
632632
}
633+
/* If the XML uses `array="true" type="X"` to define a list type,
634+
convert it to `type="array" entryType="X"` to support both formats */
635+
if (attribute.$.array == 'true') {
636+
attribute.$.entryType = attribute.$.type
637+
attribute.$.type = 'array'
638+
}
633639
let storagePolicy = dbEnum.storagePolicy.any
634640
if (context.listsUseAttributeAccessInterface && attribute.$.entryType) {
635641
storagePolicy = dbEnum.storagePolicy.attributeAccessInterface

test/zcl-loader.test.js

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -555,3 +555,42 @@ test(
555555
},
556556
testUtil.timeout.long()
557557
)
558+
559+
test(
560+
'test Matter list-typed attribute loading in memory',
561+
async () => {
562+
let db = await dbApi.initRamDatabase()
563+
try {
564+
await dbApi.loadSchema(db, env.schemaFile(), env.zapVersion())
565+
let ctx = await zclLoader.loadZcl(db, env.builtinMatterZclMetafile())
566+
let packageId = ctx.packageId
567+
568+
let zclCluster = await queryZcl.selectClusterByCode(db, packageId, 0x001f)
569+
570+
/* Verify that the ACL attribute, defined using the list type format `array="true" type="X"` in XML,
571+
is correctly parsed and stored in the database as an array of AccessControlEntryStruct. */
572+
let attributes = await dbApi.dbAll(
573+
db,
574+
"SELECT * FROM ATTRIBUTE WHERE CLUSTER_REF = ? AND CODE = 0x0000 AND NAME = 'ACL'",
575+
[zclCluster.id]
576+
)
577+
expect(attributes.length).toBe(1)
578+
let aclAttribute = attributes[0]
579+
expect(aclAttribute.TYPE).toBe('array')
580+
expect(aclAttribute.ARRAY_TYPE).toBe('AccessControlEntryStruct')
581+
582+
// verify that the ACL attribute data retrieved from the database is an array of AccessControlEntryStruct after mapping
583+
let aclAttributeMapped = await queryZcl.selectAttributeById(
584+
db,
585+
aclAttribute.ATTRIBUTE_ID
586+
)
587+
expect(aclAttributeMapped).not.toBe(null)
588+
expect(aclAttributeMapped.name).toBe('ACL')
589+
expect(aclAttributeMapped.entryType).toBe('AccessControlEntryStruct')
590+
expect(aclAttributeMapped.isArray).toBe(1)
591+
} finally {
592+
await dbApi.closeDatabase(db)
593+
}
594+
},
595+
testUtil.timeout.long()
596+
)

zcl-builtin/matter/data-model/chip/access-control-cluster.xml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,9 @@ limitations under the License.
7272
and enforce Access Control for the Node's endpoints and their associated
7373
cluster instances.</description>
7474

75-
<attribute side="server" code="0x0000" define="ACL" type="ARRAY" entryType="AccessControlEntryStruct" writable="true">
75+
<!-- Modified attribute definition from `type="array" entryType="X"` to `array="true" type="X"`
76+
to support testing loading list-typed attributes -->
77+
<attribute side="server" code="0x0000" define="ACL" array="true" type="AccessControlEntryStruct" writable="true">
7678
<description>ACL</description>
7779
<access op="read" privilege="administer"/>
7880
<access op="write" privilege="administer"/>

0 commit comments

Comments
 (0)