Skip to content

Commit

Permalink
Allow for enums that are not used in a DataModel struct to be generat…
Browse files Browse the repository at this point in the history
…ed differently
  • Loading branch information
tehampson committed Oct 12, 2023
1 parent 6deee69 commit 888a865
Show file tree
Hide file tree
Showing 8 changed files with 89 additions and 169 deletions.
13 changes: 13 additions & 0 deletions src/app/common/templates/config-data.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,19 @@ WeakEnums:
- RadioFaultEnum
- StepMode

EnumsNotUsedInDataModelStruct:
# List of enums that are not used in a DataModel Struct. By adding an enum
# to this list you prevent incorrectly assuming from code that you are
# able to use kUnknownEnumValue safely. This happens for derivate clusters
# such as ModeBase where there are CommonTag, DerivedClusterTags, MfgTags.
- "DishwasherMode::ModeTag"
- "LaundryWasherMode::ModeTag"
- "RefrigeratorAndTemperatureControlledCabinetMode::ModeTag"
- "RvcRunMode::ModeTag"
- "RvcRunMode::StatusCode"
- "RvcCleanMode::ModeTag"
- "RvcCleanMode::StatusCode"

CommandHandlerInterfaceOnlyClusters:
# List of clusters that are implemented entirely with
# CommandHandlerInterface and hence do not need generated command dispatch.
Expand Down
2 changes: 2 additions & 0 deletions src/app/zap-templates/templates/app/cluster-enums-check.zapt
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ namespace app {
namespace Clusters {
{{#zcl_clusters}}
{{#zcl_enums}}
{{#unless (isInConfigList (concat (asUpperCamelCase ../name) "::" label) "EnumsNotUsedInDataModelStruct")}}
static auto __attribute__((unused)) EnsureKnownEnumValue({{asUpperCamelCase ../name}}::{{asType label}} val)
{
using EnumType = {{asUpperCamelCase ../name}}::{{asType label}};
Expand All @@ -33,6 +34,7 @@ static auto __attribute__((unused)) EnsureKnownEnumValue({{asUpperCamelCase ../n
return static_cast<EnumType>({{first_unused_enum_value mode="first_unused"}});
}
}
{{/unless}}
{{/zcl_enums}}

{{/zcl_clusters}}
Expand Down
7 changes: 7 additions & 0 deletions src/app/zap-templates/templates/app/cluster-enums.zapt
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,18 @@ enum class {{asType label}} : {{asUnderlyingZclType name}} {
{{#zcl_enum_items}}
k{{asUpperCamelCase label}} = {{asHex value 2}},
{{/zcl_enum_items}}
{{#unless (isInConfigList (concat (asUpperCamelCase ../name) "::" label) "EnumsNotUsedInDataModelStruct")}}
// All received enum values that are not listed above will be mapped
// to kUnknownEnumValue. This is a helper enum value that should only
// be used by code to process how it handles receiving and unknown
// enum value. This specific should never be transmitted.
kUnknownEnumValue = {{first_unused_enum_value mode="first_unused"}},
{{else}}
// kUnknownEnumValue intentionally not defined. This enum is not used
// in a DataModel struct, likely because it is a part of a derivative
// cluster. As a result having kUnknownEnumValue in this enum is error
// prone, and was removed.
{{/unless}}
};
{{#if (isInConfigList label "WeakEnums")}}
#else // CHIP_USE_ENUM_CLASS_FOR_IM_ENUM
Expand Down
63 changes: 28 additions & 35 deletions src/controller/python/chip/clusters/Objects.py

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -54,11 +54,18 @@ class {{asUpperCamelCase name}}(Cluster):
{{#zcl_enum_items}}
k{{asUpperCamelCase label}} = {{asHex value 2}}
{{/zcl_enum_items}}
{{#unless (isInConfigList (concat (asUpperCamelCase ../name) "::" label) "EnumsNotUsedInDataModelStruct")}}
# All received enum values that are not listed above will be mapped
# to kUnknownEnumValue. This is a helper enum value that should only
# be used by code to process how it handles receiving and unknown
# enum value. This specific should never be transmitted.
kUnknownEnumValue = {{first_unused_enum_value mode="first_unused"}},
{{else}}
# kUnknownEnumValue intentionally not defined. This enum is not used
# in a DataModel struct, likely because it is a part of a derivative
# cluster. As a result having kUnknownEnumValue in this enum is error
# prone, and was removed.
{{/unless}}

{{#last}}
{{/last}}
Expand Down
5 changes: 4 additions & 1 deletion src/controller/python/templates/templates.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@
"templates/chip/helper.js",
"controller/python/templates/helper.js"
],
"resources": {
"config-data": "../../../../src/app/common/templates/config-data.yaml"
},
"override": "../../../../src/app/zap-templates/common/override.js",
"partials": [
{
Expand Down Expand Up @@ -35,4 +38,4 @@
"output": "src/controller/python/chip/clusters/Objects.py"
}
]
}
}

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 888a865

Please sign in to comment.