Skip to content

Commit

Permalink
Adding functionality for attribute qualities from the data model spec…
Browse files Browse the repository at this point in the history
… into ZAP: (project-chip#1367)

- Is_scene_required was already part of the attribute table so updating that with the new xml format
- Also adding change_comitted and persistence quality fields to the attribute table
- Updating all relevant helpers and their associated queries with the above loaded information
- Updating dbmap for attribute and extendedEndpointTypeAttribute with above fields
- Adding tests to check the loading of qualities such as scene, changeOmitted and persistence
- Updating the schema
- Github: ZAP#980
  • Loading branch information
brdandu authored Jul 26, 2024
1 parent a115226 commit b0d702c
Show file tree
Hide file tree
Showing 13 changed files with 3,918 additions and 3,830 deletions.
3,821 changes: 1,915 additions & 1,906 deletions docs/zap-schema.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 4 additions & 0 deletions src-electron/db/db-mapping.js
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,8 @@ exports.map = {
isArray: x.ARRAY_TYPE ? 1 : 0,
mustUseTimedWrite: dbApi.fromDbBool(x.MUST_USE_TIMED_WRITE),
apiMaturity: x.API_MATURITY,
isChangeComitted: dbApi.fromDbBool(x.IS_CHANGE_COMITTED),
persistence: x.PERSISTENCE,
}
},

Expand Down Expand Up @@ -665,6 +667,8 @@ exports.map = {
tokenId: x.TOKEN_ID, // Endpoint type attribute's token id
type: x.TYPE != 'array' ? x.TYPE : x.ARRAY_TYPE, // Attribute type
apiMaturity: x.API_MATURITY,
isChangeComitted: x.IS_CHANGE_COMITTED,
persistence: x.PERSISTENCE,
}
},

Expand Down
16 changes: 12 additions & 4 deletions src-electron/db/query-attribute.js
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,9 @@ async function selectAllAttributeDetailsFromEnabledClusters(
ENDPOINT_TYPE_ATTRIBUTE.MIN_INTERVAL,
ENDPOINT_TYPE_ATTRIBUTE.MAX_INTERVAL,
ENDPOINT_TYPE_ATTRIBUTE.REPORTABLE_CHANGE,
ATTRIBUTE.API_MATURITY
ATTRIBUTE.API_MATURITY,
ATTRIBUTE.IS_CHANGE_COMITTED,
ATTRIBUTE.PERSISTENCE
FROM ATTRIBUTE
INNER JOIN ENDPOINT_TYPE_ATTRIBUTE
ON ATTRIBUTE.ATTRIBUTE_ID = ENDPOINT_TYPE_ATTRIBUTE.ATTRIBUTE_REF
Expand Down Expand Up @@ -255,7 +257,9 @@ async function selectAttributeDetailsFromAllEndpointTypesAndClustersUtil(
ENDPOINT_TYPE_CLUSTER.SIDE,
CLUSTER.NAME AS CLUSTER_NAME,
ENDPOINT_TYPE_CLUSTER.ENABLED,
ATTRIBUTE.API_MATURITY
ATTRIBUTE.API_MATURITY,
ATTRIBUTE.IS_CHANGE_COMITTED,
ATTRIBUTE.PERSISTENCE
FROM
ATTRIBUTE
INNER JOIN
Expand Down Expand Up @@ -859,7 +863,9 @@ SELECT
A.IS_SCENE_REQUIRED,
A.ARRAY_TYPE,
A.MUST_USE_TIMED_WRITE,
A.API_MATURITY
A.API_MATURITY,
A.IS_CHANGE_COMITTED,
A.PERSISTENCE
FROM ATTRIBUTE AS A
INNER JOIN CLUSTER AS C
ON C.CLUSTER_ID = A.CLUSTER_REF
Expand Down Expand Up @@ -916,7 +922,9 @@ SELECT
A.IS_SCENE_REQUIRED,
A.ARRAY_TYPE,
A.MUST_USE_TIMED_WRITE,
A.API_MATURITY
A.API_MATURITY,
A.IS_CHANGE_COMITTED,
A.PERSISTENCE
FROM ATTRIBUTE AS A
WHERE A.PACKAGE_REF IN (${dbApi.toInClause(packageIds)})
AND A.CODE = ?
Expand Down
6 changes: 5 additions & 1 deletion src-electron/db/query-loader.js
Original file line number Diff line number Diff line change
Expand Up @@ -163,11 +163,15 @@ INSERT OR REPLACE INTO ATTRIBUTE (
MANUFACTURER_CODE,
INTRODUCED_IN_REF,
REMOVED_IN_REF,
API_MATURITY
API_MATURITY,
IS_CHANGE_COMITTED,
PERSISTENCE
) VALUES (
?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?,
(SELECT SPEC_ID FROM SPEC WHERE CODE = ? AND PACKAGE_REF = ?),
(SELECT SPEC_ID FROM SPEC WHERE CODE = ? AND PACKAGE_REF = ?),
?,
?,
?
)`

Expand Down
4 changes: 3 additions & 1 deletion src-electron/db/query-session-zcl.js
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,9 @@ SELECT
ATTRIBUTE.IS_NULLABLE,
ATTRIBUTE.IS_SCENE_REQUIRED,
ATTRIBUTE.ARRAY_TYPE,
ATTRIBUTE.MUST_USE_TIMED_WRITE
ATTRIBUTE.MUST_USE_TIMED_WRITE,
ATTRIBUTE.IS_CHANGE_COMITTED,
ATTRIBUTE.PERSISTENCE
FROM
ATTRIBUTE, CLUSTER, SESSION_PACKAGE
INNER JOIN
Expand Down
28 changes: 21 additions & 7 deletions src-electron/db/query-zcl.js
Original file line number Diff line number Diff line change
Expand Up @@ -678,7 +678,9 @@ SELECT
ARRAY_TYPE,
MUST_USE_TIMED_WRITE,
API_MATURITY,
PACKAGE_REF
PACKAGE_REF,
IS_CHANGE_COMITTED,
PERSISTENCE
FROM ATTRIBUTE
WHERE (CLUSTER_REF = ? OR CLUSTER_REF IS NULL)
AND PACKAGE_REF IN (${dbApi.toInClause(packageIds)})
Expand Down Expand Up @@ -724,7 +726,9 @@ SELECT
IS_SCENE_REQUIRED,
ARRAY_TYPE,
MUST_USE_TIMED_WRITE,
API_MATURITY
API_MATURITY,
IS_CHANGE_COMITTED,
PERSISTENCE
FROM ATTRIBUTE
WHERE
SIDE = ?
Expand Down Expand Up @@ -789,7 +793,9 @@ SELECT
A.IS_SCENE_REQUIRED,
A.ARRAY_TYPE,
A.MUST_USE_TIMED_WRITE,
A.API_MATURITY
A.API_MATURITY,
A.IS_CHANGE_COMITTED,
A.PERSISTENCE
FROM
ATTRIBUTE AS A,
CLUSTER AS C
Expand Down Expand Up @@ -834,7 +840,9 @@ SELECT
IS_SCENE_REQUIRED,
ARRAY_TYPE,
MUST_USE_TIMED_WRITE,
API_MATURITY
API_MATURITY,
IS_CHANGE_COMITTED,
PERSISTENCE
FROM ATTRIBUTE
WHERE ATTRIBUTE_ID = ?`,
[id]
Expand Down Expand Up @@ -898,7 +906,9 @@ SELECT
A.IS_SCENE_REQUIRED,
A.ARRAY_TYPE,
A.MUST_USE_TIMED_WRITE,
A.API_MATURITY
A.API_MATURITY,
A.IS_CHANGE_COMITTED,
A.PERSISTENCE
FROM ATTRIBUTE AS A
WHERE ATTRIBUTE_ID = ?`,
[clusterRef, clusterRef, attributeId]
Expand Down Expand Up @@ -938,7 +948,9 @@ SELECT
A.ARRAY_TYPE,
A.MUST_USE_TIMED_WRITE,
A.API_MATURITY,
C.CODE AS CLUSTER_CODE
C.CODE AS CLUSTER_CODE,
A.IS_CHANGE_COMITTED,
A.PERSISTENCE
FROM
ATTRIBUTE AS A
LEFT JOIN
Expand Down Expand Up @@ -992,7 +1004,9 @@ SELECT
IS_SCENE_REQUIRED,
ARRAY_TYPE,
MUST_USE_TIMED_WRITE,
API_MATURITY
API_MATURITY,
IS_CHANGE_COMITTED,
PERSISTENCE
FROM ATTRIBUTE
WHERE SIDE = ?
AND PACKAGE_REF IN (${dbApi.toInClause(packageIds)})
Expand Down
2 changes: 2 additions & 0 deletions src-electron/db/zap-schema.sql
Original file line number Diff line number Diff line change
Expand Up @@ -281,6 +281,8 @@ CREATE TABLE IF NOT EXISTS "ATTRIBUTE" (
"INTRODUCED_IN_REF" integer,
"REMOVED_IN_REF" integer,
"API_MATURITY" text,
"IS_CHANGE_COMITTED" integer,
"PERSISTENCE" text,
foreign key (INTRODUCED_IN_REF) references SPEC(SPEC_ID) ON DELETE CASCADE ON UPDATE CASCADE,
foreign key (REMOVED_IN_REF) references SPEC(SPEC_ID) ON DELETE CASCADE ON UPDATE CASCADE,
foreign key (CLUSTER_REF) references CLUSTER(CLUSTER_ID) ON DELETE CASCADE ON UPDATE CASCADE,
Expand Down
10 changes: 9 additions & 1 deletion src-electron/zcl/zcl-loader-silabs.js
Original file line number Diff line number Diff line change
Expand Up @@ -559,9 +559,13 @@ function prepareCluster(cluster, context, isExtension = false) {
ret.attributes = []
cluster.attribute.forEach((attribute) => {
let name = attribute._
let quality = null
if ('description' in attribute && name == null) {
name = attribute.description.join('')
}
if ('quality' in attribute) {
quality = attribute.quality[0].$
}
let reportingPolicy = context.defaultReportingPolicy
if (attribute.$.reportable == 'true') {
reportingPolicy = dbEnum.reportingPolicy.suggested
Expand Down Expand Up @@ -607,13 +611,17 @@ function prepareCluster(cluster, context, isExtension = false) {
isOptional: attribute.$.optional == 'true',
reportingPolicy: reportingPolicy,
storagePolicy: storagePolicy,
isSceneRequired: attribute.$.sceneRequired == 'true',
isSceneRequired:
attribute.$.sceneRequired == 'true' ||
(quality != null && quality.scene == 'true'),
introducedIn: attribute.$.introducedIn,
removedIn: attribute.$.removedIn,
isNullable: attribute.$.isNullable == 'true' ? true : false,
entryType: attribute.$.entryType,
mustUseTimedWrite: attribute.$.mustUseTimedWrite == 'true',
apiMaturity: attribute.$.apiMaturity,
changeOmitted: quality ? quality.changeOmitted == 'true' : false,
persistence: quality ? quality.persistence : null,
}
att.access = extractAccessIntoArray(attribute)
if (att.manufacturerCode == null) {
Expand Down
7 changes: 7 additions & 0 deletions test/gen-matter-1.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,13 @@ test(
expect(chipToolHelper).toContain(
'0,UINT0_MAX// actual type: ThermostatScheduleTransition'
)

// Testing attribute's scene loading
expect(
sdkExt.includes(
"// attribute: 0x0300 / 0x4001 => EnhancedColorMode, extensions: '', '', scene: true"
)
)
},
testUtil.timeout.long()
)
Expand Down
2 changes: 1 addition & 1 deletion test/gen-template/matter/sdk-ext.zapt
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ property="testCommandExtension"}}'
------------------- Attributes -------------------
{{#zcl_attributes}}
// attribute: {{asHex clusterCode 4}} / {{asHex code 4}} => {{label}}, extensions: '{{attribute_extension
property="testAttributeExtension1"}}', '{{attribute_extension property="testAttributeExtension2"}}'
property="testAttributeExtension1"}}', '{{attribute_extension property="testAttributeExtension2"}}', scene: {{isSceneRequired}}
{{/zcl_attributes}}

-------------------- Events -----------------------
Expand Down
17 changes: 16 additions & 1 deletion zap-schema.dot
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ digraph "SchemaCrawler_Diagram" {
</tr>
<tr>
<td align='right'>generated on</td>
<td align='left'>2024-07-01 18:22:19</td>
<td align='left'>2024-07-24 18:16:40</td>
</tr>
</table>
>
Expand Down Expand Up @@ -351,6 +351,16 @@ digraph "SchemaCrawler_Diagram" {
<td align='left'> </td>
<td port='api_maturity_a069c8bb.end' align='left'>TEXT</td>
</tr>
<tr>
<td port='change_comitted_5a82d25b.start' align='left'>CHANGE_COMITTED</td>
<td align='left'> </td>
<td port='change_comitted_5a82d25b.end' align='left'>INTEGER</td>
</tr>
<tr>
<td port='persistence_685f8304.start' align='left'>PERSISTENCE</td>
<td align='left'> </td>
<td port='persistence_685f8304.end' align='left'>TEXT</td>
</tr>
</table>
>
];
Expand Down Expand Up @@ -2838,6 +2848,11 @@ digraph "SchemaCrawler_Diagram" {
<td align='left'> </td>
<td port='size_badc6a4d.end' align='left'>INTEGER</td>
</tr>
<tr>
<td port='api_maturity_25f9ae82.start' align='left'>API_MATURITY</td>
<td align='left'> </td>
<td port='api_maturity_25f9ae82.end' align='left'>TEXT</td>
</tr>
</table>
>
];
Expand Down
Loading

0 comments on commit b0d702c

Please sign in to comment.