From c9f907e0d3e8ee9c09a2ff35c756f9f611455c83 Mon Sep 17 00:00:00 2001 From: Boris Zbarsky Date: Fri, 26 Jul 2024 16:46:21 -0400 Subject: [PATCH] Add support for global types in the Python Matter codegen. --- .../app/zap-templates/templates/app/helper.js | 23 +++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/src-electron/generator/matter/app/zap-templates/templates/app/helper.js b/src-electron/generator/matter/app/zap-templates/templates/app/helper.js index b21e6c09d1..d03ad2c6b1 100644 --- a/src-electron/generator/matter/app/zap-templates/templates/app/helper.js +++ b/src-electron/generator/matter/app/zap-templates/templates/app/helper.js @@ -820,6 +820,18 @@ async function _zapTypeToPythonClusterObjectType(type, options) { if (type.toLowerCase().match(/^enum\d+$/g)) { return 'uint'; } + + const enumObj = await zclQuery.selectEnumByName( + this.global.db, + type, + pkgId + ); + + if (enumObj.enumClusterCount == 0) { + // This is a global enum. + return `Globals.Enums.${type}`; + } + return ns + '.Enums.' + type; } @@ -828,6 +840,17 @@ async function _zapTypeToPythonClusterObjectType(type, options) { } if (await typeChecker('isStruct')) { + const structObj = await zclQuery.selectStructByName( + this.global.db, + type, + pkgId + ); + + if (structObj.structClusterCount == 0) { + // This is a global struct. + return `Globals.Structs.${type}`; + } + return ns + '.Structs.' + type; }