Skip to content

Commit 01d8e00

Browse files
authored
Adding struct item helper based on struct and cluster name (#1002)
- Add zcl_struct_items_by_struct_and_cluster_name helper for retrieving struct items based on struct and cluster name in helper-zcl.js - Updating selectAllStructItemsByStructName to handle cluster name as well - Updating the xml for TargetStruct such that it is now present in binding and access control clusters - Adding a test to make sure the right struct items are generated based on cluster names - Github: ZAP#916
1 parent a702abf commit 01d8e00

File tree

5 files changed

+89
-6
lines changed

5 files changed

+89
-6
lines changed

src-electron/db/query-zcl.js

Lines changed: 31 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -438,13 +438,39 @@ ORDER BY
438438
}
439439

440440
/**
441-
*
441+
* Retrieves the struct items based on struct and cluster name.
442+
* Note: By default clusterName is null.
442443
*
443444
* @param db
444445
* @param name
445-
* @returns the details of the struct items given the name of the struct
446+
* @param packageIds
447+
* @param clusterName
448+
* @returns the details of the struct items
446449
*/
447-
async function selectAllStructItemsByStructName(db, name, packageIds) {
450+
async function selectAllStructItemsByStructName(
451+
db,
452+
name,
453+
packageIds,
454+
clusterName = null
455+
) {
456+
let clusterJoinQuery = ''
457+
let clusterWhereQuery = ''
458+
if (clusterName) {
459+
clusterJoinQuery = `
460+
INNER JOIN
461+
DATA_TYPE_CLUSTER
462+
ON
463+
DATA_TYPE_CLUSTER.DATA_TYPE_REF = DT.DATA_TYPE_ID
464+
INNER JOIN
465+
CLUSTER
466+
ON
467+
DATA_TYPE_CLUSTER.CLUSTER_REF = CLUSTER.CLUSTER_ID
468+
`
469+
clusterWhereQuery = `
470+
AND
471+
CLUSTER.NAME = "${clusterName}"
472+
`
473+
}
448474
return dbApi
449475
.dbAll(
450476
db,
@@ -474,12 +500,14 @@ INNER JOIN
474500
DATA_TYPE AS DT
475501
ON
476502
DT.DATA_TYPE_ID = STRUCT.STRUCT_ID
503+
${clusterJoinQuery}
477504
INNER JOIN
478505
DISCRIMINATOR
479506
ON
480507
DT.DISCRIMINATOR_REF = DISCRIMINATOR.DISCRIMINATOR_ID
481508
WHERE DT.NAME = ?
482509
AND DT.PACKAGE_REF IN (${dbApi.toInClause(packageIds)})
510+
${clusterWhereQuery}
483511
ORDER BY FIELD_IDENTIFIER`,
484512
[name]
485513
)

src-electron/generator/helper-zcl.js

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -296,6 +296,32 @@ async function zcl_struct_items_by_struct_name(name, options) {
296296
return templateUtil.templatePromise(this.global, promise)
297297
}
298298

299+
/**
300+
* Block helper iterating over all struct items given the struct name and
301+
* cluster name.
302+
*
303+
* @param name
304+
* @param clusterName
305+
* @param options
306+
* @returns Promise of content.
307+
*/
308+
async function zcl_struct_items_by_struct_and_cluster_name(
309+
name,
310+
clusterName,
311+
options
312+
) {
313+
let packageIds = await templateUtil.ensureZclPackageIds(this)
314+
let promise = queryZcl
315+
.selectAllStructItemsByStructName(
316+
this.global.db,
317+
name,
318+
packageIds,
319+
clusterName
320+
)
321+
.then((st) => templateUtil.collectBlocks(st, options, this))
322+
return templateUtil.templatePromise(this.global, promise)
323+
}
324+
299325
/**
300326
* Block helper iterating over all deviceTypes.
301327
*
@@ -2987,3 +3013,5 @@ exports.if_compare = if_compare
29873013
exports.if_is_data_type_signed = if_is_data_type_signed
29883014
exports.as_zcl_data_type_size = as_zcl_data_type_size
29893015
exports.zcl_command_responses = zcl_command_responses
3016+
exports.zcl_struct_items_by_struct_and_cluster_name =
3017+
zcl_struct_items_by_struct_and_cluster_name

test/gen-matter-4.test.js

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -257,6 +257,24 @@ test(
257257
expect(ept).toContain(
258258
'attribute GeneratedCommandList of type command_id is unsigned. The size of this attribute is: 32 bits'
259259
)
260+
261+
// Testing cluster specific structs
262+
expect(ept).toContain(
263+
'TargetStruct item 0 from Access Control cluster: Cluster'
264+
)
265+
expect(ept).toContain(
266+
'TargetStruct item 1 from Access Control cluster: Endpoint'
267+
)
268+
expect(ept).toContain(
269+
'TargetStruct item 2 from Access Control cluster: DeviceType'
270+
)
271+
expect(ept).toContain('TargetStruct item 0 from Binding cluster: Node')
272+
expect(ept).toContain('TargetStruct item 1 from Binding cluster: Group')
273+
expect(ept).toContain('TargetStruct item 2 from Binding cluster: Endpoint')
274+
expect(ept).toContain('TargetStruct item 3 from Binding cluster: Cluster')
275+
expect(ept).toContain(
276+
'TargetStruct item 4 from Binding cluster: FabricIndex'
277+
)
260278
},
261279
testUtil.timeout.long()
262280
)

test/gen-template/matter3/miscellaneous_helper_tests.zapt

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,4 +19,13 @@ attribute {{name}} of type {{type}} is unsigned. The size of this attribute is:
1919
{{/if_is_data_type_signed}}
2020

2121
{{/zcl_attributes_server}}
22-
{{/chip_client_clusters}}
22+
{{/chip_client_clusters}}
23+
24+
25+
{{#zcl_struct_items_by_struct_and_cluster_name "TargetStruct" "Access Control"}}
26+
TargetStruct item {{index}} from Access Control cluster: {{name}}
27+
{{/zcl_struct_items_by_struct_and_cluster_name}}
28+
29+
{{#zcl_struct_items_by_struct_and_cluster_name "TargetStruct" "Binding"}}
30+
TargetStruct item {{index}} from Binding cluster: {{name}}
31+
{{/zcl_struct_items_by_struct_and_cluster_name}}

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ limitations under the License.
4040
<item name="Removed" value="0x02"/>
4141
</enum>
4242

43-
<struct name="Target">
43+
<struct name="TargetStruct">
4444
<cluster code="0x001F"/>
4545
<item fieldId="0" name="Cluster" type="cluster_id" isNullable="true"/>
4646
<item fieldId="1" name="Endpoint" type="endpoint_no" isNullable="true"/>
@@ -52,7 +52,7 @@ limitations under the License.
5252
<item fieldId="1" name="Privilege" type="AccessControlEntryPrivilegeEnum" isFabricSensitive="true"/>
5353
<item fieldId="2" name="AuthMode" type="AccessControlEntryAuthModeEnum" isFabricSensitive="true"/>
5454
<item fieldId="3" name="Subjects" type="INT64U" isNullable="true" array="true" isFabricSensitive="true"/>
55-
<item fieldId="4" name="Targets" type="Target" isNullable="true" array="true" isFabricSensitive="true"/>
55+
<item fieldId="4" name="Targets" type="TargetStruct" isNullable="true" array="true" isFabricSensitive="true"/>
5656
</struct>
5757

5858
<struct name="AccessControlExtensionStruct" isFabricScoped="true">

0 commit comments

Comments
 (0)