Skip to content

Commit 7dd15ec

Browse files
authored
Allow cluster specific and generic data types with the same name in the XML (#1542)
* Allow cluster specific and generic data types with the same name in the XML - This solves the issue of loading a same named generic and cluster specific data type. - The issue was with the generic data type type searches not checking if their cluster reference does not exist and thus getting the cluster specific data type instead. Now that check is added and duplicates issue is resolved - Ran into another ZAP generation issue while running zap_regen_all.py and fixed that error in helper.js - add tests for loading same named data types where one is generic and another is cluster specific - Github: ZAP#1540
1 parent 049aa34 commit 7dd15ec

File tree

5 files changed

+61
-5
lines changed

5 files changed

+61
-5
lines changed

src-electron/db/query-loader.js

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -203,10 +203,16 @@ SELECT
203203
DATA_TYPE.DATA_TYPE_ID
204204
FROM
205205
DATA_TYPE
206+
LEFT JOIN
207+
DATA_TYPE_CLUSTER
208+
ON
209+
DATA_TYPE.DATA_TYPE_ID = DATA_TYPE_CLUSTER.DATA_TYPE_REF
206210
WHERE
207211
DATA_TYPE.NAME = ?
208212
AND
209-
DATA_TYPE.DISCRIMINATOR_REF = ?`
213+
DATA_TYPE.DISCRIMINATOR_REF = ?
214+
AND
215+
DATA_TYPE_CLUSTER.CLUSTER_CODE IS NULL`
210216

211217
/**
212218
* Transforms the array of attributes in a certain format and returns it.
@@ -1821,6 +1827,8 @@ INNER JOIN
18211827
DATA_TYPE
18221828
ON
18231829
ENUM.ENUM_ID = DATA_TYPE.DATA_TYPE_ID
1830+
LEFT JOIN
1831+
DATA_TYPE_CLUSTER ON DATA_TYPE.DATA_TYPE_ID = DATA_TYPE_CLUSTER.DATA_TYPE_REF
18241832
WHERE
18251833
DATA_TYPE.PACKAGE_REF = ?
18261834
AND
@@ -1836,6 +1844,8 @@ AND
18361844
PACKAGE_REF
18371845
IN
18381846
(${dbApi.toInClause(knownPackages)}))
1847+
AND
1848+
DATA_TYPE_CLUSTER.CLUSTER_CODE IS NULL
18391849
`
18401850

18411851
return dbApi.dbMultiInsert(
@@ -2041,6 +2051,8 @@ async function insertBitmapFields(db, packageId, knownPackages, data) {
20412051
DATA_TYPE
20422052
ON
20432053
BITMAP.BITMAP_ID = DATA_TYPE.DATA_TYPE_ID
2054+
LEFT JOIN
2055+
DATA_TYPE_CLUSTER ON DATA_TYPE.DATA_TYPE_ID = DATA_TYPE_CLUSTER.DATA_TYPE_REF
20442056
WHERE
20452057
DATA_TYPE.PACKAGE_REF = ?
20462058
AND
@@ -2055,6 +2067,8 @@ async function insertBitmapFields(db, packageId, knownPackages, data) {
20552067
AND
20562068
PACKAGE_REF
20572069
IN (${dbApi.toInClause(knownPackages)}))
2070+
AND
2071+
DATA_TYPE_CLUSTER.CLUSTER_CODE IS NULL
20582072
`
20592073

20602074
return dbApi.dbMultiInsert(
@@ -2241,6 +2255,8 @@ async function insertStructItems(db, packageIds, data) {
22412255
STRUCT
22422256
INNER JOIN
22432257
DATA_TYPE ON STRUCT.STRUCT_ID = DATA_TYPE.DATA_TYPE_ID
2258+
LEFT JOIN
2259+
DATA_TYPE_CLUSTER ON DATA_TYPE.DATA_TYPE_ID = DATA_TYPE_CLUSTER.DATA_TYPE_REF
22442260
WHERE
22452261
DATA_TYPE.PACKAGE_REF
22462262
IN
@@ -2258,6 +2274,8 @@ async function insertStructItems(db, packageIds, data) {
22582274
PACKAGE_REF
22592275
IN
22602276
(${dbApi.toInClause(packageIds)}))
2277+
AND
2278+
DATA_TYPE_CLUSTER.CLUSTER_CODE IS NULL
22612279
`
22622280

22632281
return dbApi.dbMultiInsert(

src-electron/generator/matter/controller/python/templates/helper.js

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -82,9 +82,11 @@ async function as_underlying_python_zcl_type(type, clusterId, options) {
8282
if (type && type.toLowerCase() == 'boolean') {
8383
return 'bool';
8484
} else if (
85-
dataType.discriminatorName.toLowerCase() == dbEnum.zclType.bitmap ||
86-
dataType.discriminatorName.toLowerCase() == dbEnum.zclType.enum ||
87-
dataType.discriminatorName.toLowerCase() == dbEnum.zclType.number
85+
dataType &&
86+
dataType.discriminatorName &&
87+
(dataType.discriminatorName.toLowerCase() == dbEnum.zclType.bitmap ||
88+
dataType.discriminatorName.toLowerCase() == dbEnum.zclType.enum ||
89+
dataType.discriminatorName.toLowerCase() == dbEnum.zclType.number)
8890
) {
8991
// Do not know on why this is the case but returning nothing for floats
9092
// and this is done for compatibility with asPythonType.

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1651,7 +1651,7 @@ async function processStructItems(db, filePath, packageIds, data, context) {
16511651
) {
16521652
structItems.push({
16531653
structName: si.$.name,
1654-
structClusterCode: si.cluster ? parseInt(si.clusterCode) : null,
1654+
structClusterCode: si.cluster ? si.cluster : null,
16551655
name: context.fabricHandling.indexFieldName,
16561656
type: context.fabricHandling.indexType,
16571657
fieldIdentifier: context.fabricHandling.indexFieldId,

test/zcl-loader.test.js

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -549,6 +549,35 @@ test(
549549
expect(x).toEqual(testUtil.totalMatterEventFields)
550550
x = await testQuery.selectCountFrom(db, 'GLOBAL_ATTRIBUTE_BIT')
551551
expect(x).toBe(testUtil.totalMatterGlobalAttributeBits)
552+
553+
// Test for same named data type such that one is generic and the other
554+
// is cluster specific. eg: SemanticTagStruct in xml
555+
let structs = await dbApi.dbAll(
556+
db,
557+
`SELECT
558+
*
559+
FROM
560+
DATA_TYPE
561+
LEFT JOIN
562+
DATA_TYPE_CLUSTER
563+
ON
564+
DATA_TYPE.DATA_TYPE_ID = DATA_TYPE_CLUSTER.DATA_TYPE_REF
565+
WHERE
566+
DATA_TYPE.NAME = 'SemanticTagStruct'`
567+
)
568+
569+
expect(structs.length).toBe(2)
570+
// Validate the generic struct
571+
let genericStruct = structs.find((s) => s.CLUSTER_REF === null)
572+
expect(genericStruct).not.toBeUndefined()
573+
expect(genericStruct.NAME).toBe('SemanticTagStruct')
574+
expect(genericStruct.CLUSTER_REF).toBeNull()
575+
576+
// Validate the cluster-specific struct
577+
let clusterSpecificStruct = structs.find((s) => s.CLUSTER_REF !== null)
578+
expect(clusterSpecificStruct).not.toBeUndefined()
579+
expect(clusterSpecificStruct.NAME).toBe('SemanticTagStruct')
580+
expect(clusterSpecificStruct.CLUSTER_REF).not.toBeNull()
552581
} finally {
553582
await dbApi.closeDatabase(db)
554583
}

zcl-builtin/matter/data-model/chip/descriptor-cluster.xml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,13 @@ limitations under the License.
1717
<configurator>
1818
<domain name="CHIP"/>
1919

20+
<struct name="SemanticTagStruct">
21+
<item name="MfgCode" type="vendor_id" isNullable="true"/>
22+
<item name="NamespaceID" type="enum8"/>
23+
<item name="Tag" type="enum8"/>
24+
<item name="Label" type="char_string" isNullable="true" optional="true"/>
25+
</struct>
26+
2027
<struct name="DeviceTypeStruct">
2128
<cluster code="0x001d"/>
2229
<item name="DeviceType" type="DEVTYPE_ID"/>

0 commit comments

Comments
 (0)