Skip to content

Commit d751c4b

Browse files
authored
Support device type revisions (#1658)
* Support device type revision. * Rename DEVICE_REVISION to REVISION * Add a unit test that shows device revision. Add a revision in matter-devices. * Fix XML tag. * Update matter device types template as well. * Use `_` to get the actual valure for the device revision. I am unclear when _ is to be used and when not ... * Fix light device: it should be 0x100 not 103 * Replace deviceRevision with revision.
1 parent a8323e3 commit d751c4b

File tree

11 files changed

+35
-12
lines changed

11 files changed

+35
-12
lines changed

src-electron/db/db-mapping.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -461,6 +461,7 @@ exports.map = {
461461
if (x == null) return undefined
462462
return {
463463
id: x.DEVICE_TYPE_ID,
464+
revision: x.REVISION,
464465
code: x.CODE,
465466
profileId: x.PROFILE_ID,
466467
domain: x.DOMAIN,
@@ -476,6 +477,7 @@ exports.map = {
476477
if (x == null) return undefined
477478
return {
478479
id: x.DEVICE_TYPE_ID,
480+
revision: x.REVISION,
479481
code: x.CODE,
480482
profileId: x.PROFILE_ID,
481483
domain: x.DOMAIN,

src-electron/db/query-device-type.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ async function selectAllDeviceTypes(db, packageId) {
3636
return dbApi
3737
.dbAll(
3838
db,
39-
'SELECT DEVICE_TYPE_ID, DOMAIN, CODE, PROFILE_ID, NAME, DESCRIPTION, CLASS, PACKAGE_REF FROM DEVICE_TYPE WHERE PACKAGE_REF = ? ORDER BY DOMAIN, CODE',
39+
'SELECT DEVICE_TYPE_ID, REVISION, DOMAIN, CODE, PROFILE_ID, NAME, DESCRIPTION, CLASS, PACKAGE_REF FROM DEVICE_TYPE WHERE PACKAGE_REF = ? ORDER BY DOMAIN, CODE',
4040
[packageId]
4141
)
4242
.then((rows) => rows.map(dbMapping.map.deviceType))
@@ -53,7 +53,7 @@ async function selectDeviceTypeById(db, id) {
5353
return dbApi
5454
.dbGet(
5555
db,
56-
'SELECT DEVICE_TYPE_ID, DOMAIN, CODE, PROFILE_ID, NAME, DESCRIPTION, CLASS, PACKAGE_REF FROM DEVICE_TYPE WHERE DEVICE_TYPE_ID = ?',
56+
'SELECT DEVICE_TYPE_ID, REVISION, DOMAIN, CODE, PROFILE_ID, NAME, DESCRIPTION, CLASS, PACKAGE_REF FROM DEVICE_TYPE WHERE DEVICE_TYPE_ID = ?',
5757
[id]
5858
)
5959
.then(dbMapping.map.deviceType)
@@ -72,7 +72,7 @@ async function selectDeviceTypeByCodeAndName(db, packageId, code, name) {
7272
return dbApi
7373
.dbGet(
7474
db,
75-
'SELECT DEVICE_TYPE_ID, DOMAIN, CODE, PROFILE_ID, NAME, DESCRIPTION, CLASS FROM DEVICE_TYPE WHERE CODE = ? AND NAME = ? AND PACKAGE_REF = ? ',
75+
'SELECT DEVICE_TYPE_ID, REVISION, DOMAIN, CODE, PROFILE_ID, NAME, DESCRIPTION, CLASS FROM DEVICE_TYPE WHERE CODE = ? AND NAME = ? AND PACKAGE_REF = ? ',
7676
[code, name, packageId]
7777
)
7878
.then(dbMapping.map.deviceType)
@@ -90,7 +90,7 @@ async function selectDeviceTypeByCode(db, packageId, code) {
9090
return dbApi
9191
.dbGet(
9292
db,
93-
'SELECT DEVICE_TYPE_ID, DOMAIN, CODE, PROFILE_ID, NAME, DESCRIPTION, CLASS FROM DEVICE_TYPE WHERE CODE = ? AND PACKAGE_REF = ? ',
93+
'SELECT DEVICE_TYPE_ID, REVISION, DOMAIN, CODE, PROFILE_ID, NAME, DESCRIPTION, CLASS FROM DEVICE_TYPE WHERE CODE = ? AND PACKAGE_REF = ? ',
9494
[code, packageId]
9595
)
9696
.then(dbMapping.map.deviceType)

src-electron/db/query-loader.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1256,7 +1256,7 @@ async function insertDeviceTypes(db, packageId, data) {
12561256
return dbApi
12571257
.dbMultiInsert(
12581258
db,
1259-
'INSERT INTO DEVICE_TYPE (PACKAGE_REF, DOMAIN, CODE, PROFILE_ID, NAME, DESCRIPTION, CLASS, SCOPE, SUPERSET) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?)',
1259+
'INSERT INTO DEVICE_TYPE (PACKAGE_REF, DOMAIN, CODE, PROFILE_ID, NAME, DESCRIPTION, CLASS, SCOPE, SUPERSET, REVISION) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?)',
12601260
data.map((dt) => {
12611261
return [
12621262
packageId,
@@ -1267,7 +1267,8 @@ async function insertDeviceTypes(db, packageId, data) {
12671267
dt.description,
12681268
dt.class,
12691269
dt.scope,
1270-
dt.superset
1270+
dt.superset,
1271+
dt.revision
12711272
]
12721273
})
12731274
)

src-electron/db/query-session.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -543,6 +543,7 @@ async function selectDeviceTypePackageInfoFromDeviceTypeId(db, deviceTypeIds) {
543543
`
544544
SELECT
545545
DEVICE_TYPE.DEVICE_TYPE_ID,
546+
DEVICE_TYPE.REVISION,
546547
DEVICE_TYPE.CODE,
547548
DEVICE_TYPE.NAME,
548549
DEVICE_TYPE.NAME,

src-electron/db/zap-schema.sql

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -368,6 +368,7 @@ CREATE TABLE IF NOT EXISTS "GLOBAL_ATTRIBUTE_BIT" (
368368
DROP TABLE IF EXISTS "DEVICE_TYPE";
369369
CREATE TABLE IF NOT EXISTS "DEVICE_TYPE" (
370370
"DEVICE_TYPE_ID" integer primary key autoincrement,
371+
"REVISION" integer,
371372
"PACKAGE_REF" integer,
372373
"DOMAIN" text,
373374
"CODE" integer,

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1715,8 +1715,10 @@ function prepareDeviceType(deviceType) {
17151715
class: deviceType.class ? deviceType.class[0] : '',
17161716
scope: deviceType.scope ? deviceType.scope[0] : '',
17171717
superset: deviceType.superset ? deviceType.superset[0] : '',
1718+
revision: deviceType.revision ? parseInt(deviceType.revision[0]['_']) : 1,
17181719
compositionType: null
17191720
}
1721+
17201722
if ('endpointComposition' in deviceType) {
17211723
try {
17221724
ret.compositionType = deviceType.endpointComposition[0].compositionType[0]

test/gen-matter-1.test.js

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -243,8 +243,14 @@ test(
243243
expect(simpleTest).toContain('Base type for ipv6adr : long_octet_string')
244244

245245
let deviceType = genResult.content['device-types.txt']
246+
247+
// Default device revision if unknown: 1
248+
expect(deviceType).toContain(
249+
'// device type: CHIP / 0x0105 : 1 => MA-colordimmerswitch // extension: '
250+
)
251+
// set revision for onoff: 3 right now
246252
expect(deviceType).toContain(
247-
'// device type: CHIP / 0x0105 => MA-colordimmerswitch // extension: '
253+
'// device type: CHIP / 0x0100 : 3 => MA-onofflight // extension: '
248254
)
249255
expect(deviceType).toContain('>> Attribute: StartUpCurrentLevel [16384]')
250256
expect(deviceType).toContain('>> Command: MoveToLevelWithOnOff [4]')

test/gen-template/matter/device-types.zapt

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{{#zcl_device_types}}
2-
// device type: {{domain}} / {{asHex code 4}} => {{label}} // extension: '{{device_type_extension
2+
// device type: {{domain}} / {{asHex code 4}} : {{revision}} => {{label}} // extension: '{{device_type_extension
33
property="testDeviceTypeExtension"}}'
44

55
{{#zcl_device_type_clusters}}
@@ -15,4 +15,3 @@ property="testDeviceTypeExtension"}}'
1515

1616

1717
{{/zcl_device_types}}
18-

test/gen-template/matter/sdk-ext.zapt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ property="testEventExtension1"}}'
4242

4343
------------------- Device types -------------------
4444
{{#zcl_device_types}}
45-
// device type: {{domain}} / {{asHex code 4}} => {{label}} // extension: '{{device_type_extension
45+
// device type: {{domain}} / {{asHex code 4}} : {{revision}} => {{label}} // extension: '{{device_type_extension
4646
property="testDeviceTypeExtension"}}'
4747
{{/zcl_device_types}}
4848

@@ -60,4 +60,4 @@ IMPLEMENTED_COMMANDS2>{{#all_user_clusters}}{{#all_user_cluster_commands_irrespe
6060
{{#zcl_struct_items}}
6161
Struct name: {{../name}}, Struct Item Name: {{./name}}, Struct Item Type: {{./type}}, {{#if defaultValue}}Struct Default Value: {{defaultValue}}{{/if}}
6262
{{/zcl_struct_items}}
63-
{{/zcl_structs}}
63+
{{/zcl_structs}}

zcl-builtin/matter/data-model/chip/matter-devices.xml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -176,6 +176,7 @@ limitations under the License.
176176
<typeName>Matter On/Off Light</typeName>
177177
<profileId editable="false">0x0103</profileId>
178178
<deviceId editable="false">0x0100</deviceId>
179+
<revision editable="false">3</revision>
179180
<clusters lockOthers="true">
180181
<include cluster="Identify" client="false" server="true" clientLocked="true" serverLocked="true">
181182
<requireAttribute>IDENTIFY_TIME</requireAttribute>
@@ -2073,7 +2074,7 @@ limitations under the License.
20732074
<requireAttribute>SERVER_LIST</requireAttribute>
20742075
<requireAttribute>CLIENT_LIST</requireAttribute>
20752076
<requireAttribute>PARTS_LIST</requireAttribute>
2076-
</include>
2077+
</include>
20772078
</clusters>
20782079
</deviceType>
20792080
<deviceType>

0 commit comments

Comments
 (0)