From 4084573bd546555bad6a1e576322551b447e9edb Mon Sep 17 00:00:00 2001 From: Boris Zbarsky Date: Tue, 24 Oct 2023 11:08:04 -0400 Subject: [PATCH] Expose device class for device types. (#1180) Also fixes endpoint-config codegen for the device type array: These are 32-bit values, not 16-bit. --- src-electron/db/db-mapping.js | 1 + src-electron/db/query-device-type.js | 8 ++++---- src-electron/generator/helper-endpointconfig.js | 2 +- test/gen-matter-4.test.js | 12 ++++++------ 4 files changed, 12 insertions(+), 11 deletions(-) diff --git a/src-electron/db/db-mapping.js b/src-electron/db/db-mapping.js index fcb813b84a..4b493b18cc 100644 --- a/src-electron/db/db-mapping.js +++ b/src-electron/db/db-mapping.js @@ -381,6 +381,7 @@ exports.map = { label: x.NAME, name: x.NAME, caption: x.DESCRIPTION, + class: x.CLASS, } }, diff --git a/src-electron/db/query-device-type.js b/src-electron/db/query-device-type.js index 70819958e7..cde005ad44 100644 --- a/src-electron/db/query-device-type.js +++ b/src-electron/db/query-device-type.js @@ -34,7 +34,7 @@ async function selectAllDeviceTypes(db, packageId) { return dbApi .dbAll( db, - 'SELECT DEVICE_TYPE_ID, DOMAIN, CODE, PROFILE_ID, NAME, DESCRIPTION FROM DEVICE_TYPE WHERE PACKAGE_REF = ? ORDER BY DOMAIN, CODE', + 'SELECT DEVICE_TYPE_ID, DOMAIN, CODE, PROFILE_ID, NAME, DESCRIPTION, CLASS FROM DEVICE_TYPE WHERE PACKAGE_REF = ? ORDER BY DOMAIN, CODE', [packageId] ) .then((rows) => rows.map(dbMapping.map.deviceType)) @@ -51,7 +51,7 @@ async function selectDeviceTypeById(db, id) { return dbApi .dbGet( db, - 'SELECT DEVICE_TYPE_ID, DOMAIN, CODE, PROFILE_ID, NAME, DESCRIPTION FROM DEVICE_TYPE WHERE DEVICE_TYPE_ID = ?', + 'SELECT DEVICE_TYPE_ID, DOMAIN, CODE, PROFILE_ID, NAME, DESCRIPTION, CLASS FROM DEVICE_TYPE WHERE DEVICE_TYPE_ID = ?', [id] ) .then(dbMapping.map.deviceType) @@ -70,7 +70,7 @@ async function selectDeviceTypeByCodeAndName(db, packageId, code, name) { return dbApi .dbGet( db, - 'SELECT DEVICE_TYPE_ID, DOMAIN, CODE, PROFILE_ID, NAME, DESCRIPTION FROM DEVICE_TYPE WHERE CODE = ? AND NAME = ? AND PACKAGE_REF = ? ', + 'SELECT DEVICE_TYPE_ID, DOMAIN, CODE, PROFILE_ID, NAME, DESCRIPTION, CLASS FROM DEVICE_TYPE WHERE CODE = ? AND NAME = ? AND PACKAGE_REF = ? ', [code, name, packageId] ) .then(dbMapping.map.deviceType) @@ -89,7 +89,7 @@ async function selectDeviceTypeByCode(db, packageId, code) { return dbApi .dbGet( db, - 'SELECT DEVICE_TYPE_ID, DOMAIN, CODE, PROFILE_ID, NAME, DESCRIPTION FROM DEVICE_TYPE WHERE CODE = ? AND PACKAGE_REF = ? ', + 'SELECT DEVICE_TYPE_ID, DOMAIN, CODE, PROFILE_ID, NAME, DESCRIPTION, CLASS FROM DEVICE_TYPE WHERE CODE = ? AND PACKAGE_REF = ? ', [code, packageId] ) .then(dbMapping.map.deviceType) diff --git a/src-electron/generator/helper-endpointconfig.js b/src-electron/generator/helper-endpointconfig.js index 4f6594debc..8401e43d97 100644 --- a/src-electron/generator/helper-endpointconfig.js +++ b/src-electron/generator/helper-endpointconfig.js @@ -361,7 +361,7 @@ async function endpoint_fixed_device_type_array(options) { ret += '{' + '0x' + - bin.int16ToHex(deviceList[i].deviceId) + + bin.int32ToHex(deviceList[i].deviceId) + ',' + deviceList[i].deviceVersion.toString() + endpointIdentifier + diff --git a/test/gen-matter-4.test.js b/test/gen-matter-4.test.js index 641cf4051b..c78fd3c8e0 100644 --- a/test/gen-matter-4.test.js +++ b/test/gen-matter-4.test.js @@ -159,10 +159,10 @@ test( '#define FIXED_PROFILE_IDS { 0x0103, 0x0103, 0x0103, 0x0103 }' ) expect(ept).toContain( - '#define FIXED_DEVICE_TYPES {{0x0016,1},{0x0100,1},{0x0100,1},{0xF002,1}}' + '#define FIXED_DEVICE_TYPES {{0x00000016,1},{0x00000100,1},{0x00000100,1},{0x0000F002,1}}' ) expect(ept).toContain( - '#define FIXED_DEVICE_TYPES_WITH_ENDPOINT {{0x0016,1,0},{0x0100,1,1},{0x0100,1,2},{0xF002,1,65534}}' + '#define FIXED_DEVICE_TYPES_WITH_ENDPOINT {{0x00000016,1,0},{0x00000100,1,1},{0x00000100,1,2},{0x0000F002,1,65534}}' ) expect(ept).toContain('#define FIXED_DEVICE_TYPE_OFFSETS { 0,1,2,3}') expect(ept).toContain('#define FIXED_DEVICE_TYPE_LENGTHS { 1,1,1,1}') @@ -265,10 +265,10 @@ test( '#define FIXED_PROFILE_IDS { 0x0103, 0x0103, 0x0103, 0x0103 }' ) expect(ept).toContain( - '#define FIXED_DEVICE_TYPES {{0x0016,1},{0x0100,1},{0x0100,1},{0xF002,1}}' + '#define FIXED_DEVICE_TYPES {{0x00000016,1},{0x00000100,1},{0x00000100,1},{0x0000F002,1}}' ) expect(ept).toContain( - '#define FIXED_DEVICE_TYPES_WITH_ENDPOINT {{0x0016,1,0},{0x0100,1,1},{0x0100,1,2},{0xF002,1,65534}}' + '#define FIXED_DEVICE_TYPES_WITH_ENDPOINT {{0x00000016,1,0},{0x00000100,1,1},{0x00000100,1,2},{0x0000F002,1,65534}}' ) expect(ept).toContain('#define FIXED_DEVICE_TYPE_OFFSETS { 0,1,2,3}') expect(ept).toContain('#define FIXED_DEVICE_TYPE_LENGTHS { 1,1,1,1}') @@ -314,10 +314,10 @@ test( let ept = genResult.content['endpoint_config.h'] expect(ept).toContain( - '#define FIXED_DEVICE_TYPES {{0x0016,1},{0x0101,2},{0x0100,1},{0x0101,1},{0x0100,1},{0xF002,1}}' + '#define FIXED_DEVICE_TYPES {{0x00000016,1},{0x00000101,2},{0x00000100,1},{0x00000101,1},{0x00000100,1},{0x0000F002,1}}' ) expect(ept).toContain( - '#define FIXED_DEVICE_TYPES_WITH_ENDPOINT {{0x0016,1,0},{0x0101,2,1},{0x0100,1,1},{0x0101,1,2},{0x0100,1,2},{0xF002,1,65534}}' + '#define FIXED_DEVICE_TYPES_WITH_ENDPOINT {{0x00000016,1,0},{0x00000101,2,1},{0x00000100,1,1},{0x00000101,1,2},{0x00000100,1,2},{0x0000F002,1,65534}}' ) expect(ept).toContain('#define FIXED_DEVICE_TYPE_OFFSETS { 0,1,3,5}') expect(ept).toContain('#define FIXED_DEVICE_TYPE_LENGTHS { 1,2,2,1}')