diff --git a/src/app/common/templates/config-data.yaml b/src/app/common/templates/config-data.yaml index 40251139dae555..50d174a8a52902 100644 --- a/src/app/common/templates/config-data.yaml +++ b/src/app/common/templates/config-data.yaml @@ -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. diff --git a/src/app/zap-templates/templates/app/cluster-enums-check.zapt b/src/app/zap-templates/templates/app/cluster-enums-check.zapt index e673a7af185278..630614a1da1ee3 100644 --- a/src/app/zap-templates/templates/app/cluster-enums-check.zapt +++ b/src/app/zap-templates/templates/app/cluster-enums-check.zapt @@ -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}}; @@ -33,6 +34,7 @@ static auto __attribute__((unused)) EnsureKnownEnumValue({{asUpperCamelCase ../n return static_cast({{first_unused_enum_value mode="first_unused"}}); } } +{{/unless}} {{/zcl_enums}} {{/zcl_clusters}} diff --git a/src/app/zap-templates/templates/app/cluster-enums.zapt b/src/app/zap-templates/templates/app/cluster-enums.zapt index 4394ed79a7c25a..e41c615d26d0ba 100644 --- a/src/app/zap-templates/templates/app/cluster-enums.zapt +++ b/src/app/zap-templates/templates/app/cluster-enums.zapt @@ -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 diff --git a/src/controller/python/chip/clusters/Objects.py b/src/controller/python/chip/clusters/Objects.py index 300e8b56cb66c7..6e3ed958fccfde 100644 --- a/src/controller/python/chip/clusters/Objects.py +++ b/src/controller/python/chip/clusters/Objects.py @@ -15261,11 +15261,10 @@ class ModeTag(MatterIntEnum): kDelicate = 0x4001 kHeavy = 0x4002 kWhites = 0x4003 - # 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 = 0, + # 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. class Bitmaps: class Feature(IntFlag): @@ -15532,11 +15531,10 @@ class Enums: class ModeTag(MatterIntEnum): kRapidCool = 0x4000 kRapidFreeze = 0x4001 - # 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 = 0, + # 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. class Bitmaps: class Feature(IntFlag): @@ -16013,11 +16011,10 @@ class Enums: class ModeTag(MatterIntEnum): kIdle = 0x4000 kCleaning = 0x4001 - # 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 = 0, + # 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. class StatusCode(MatterIntEnum): kStuck = 0x41 @@ -16028,11 +16025,10 @@ class StatusCode(MatterIntEnum): kWaterTankLidOpen = 0x46 kMopCleaningPadMissing = 0x47 kBatteryLow = 0x48 - # 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 = 0, + # 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. class Bitmaps: class Feature(IntFlag): @@ -16300,19 +16296,17 @@ class ModeTag(MatterIntEnum): kDeepClean = 0x4000 kVacuum = 0x4001 kMop = 0x4002 - # 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 = 0, + # 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. class StatusCode(MatterIntEnum): kCleaningInProgress = 0x40 - # 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 = 0, + # 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. class Bitmaps: class Feature(IntFlag): @@ -17039,11 +17033,10 @@ class ModeTag(MatterIntEnum): kNormal = 0x4000 kHeavy = 0x4001 kLight = 0x4002 - # 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 = 0, + # 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. class Bitmaps: class Feature(IntFlag): diff --git a/src/controller/python/templates/python-cluster-Objects-py.zapt b/src/controller/python/templates/python-cluster-Objects-py.zapt index 9fada4b5792c4e..b41f8de5992a68 100644 --- a/src/controller/python/templates/python-cluster-Objects-py.zapt +++ b/src/controller/python/templates/python-cluster-Objects-py.zapt @@ -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}} diff --git a/src/controller/python/templates/templates.json b/src/controller/python/templates/templates.json index e5d15198c5aac8..0fb4defaa2b345 100644 --- a/src/controller/python/templates/templates.json +++ b/src/controller/python/templates/templates.json @@ -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": [ { @@ -35,4 +38,4 @@ "output": "src/controller/python/chip/clusters/Objects.py" } ] -} +} \ No newline at end of file diff --git a/zzz_generated/app-common/app-common/zap-generated/cluster-enums-check.h b/zzz_generated/app-common/app-common/zap-generated/cluster-enums-check.h index 949458b352d355..a68a5dcc8cc234 100644 --- a/zzz_generated/app-common/app-common/zap-generated/cluster-enums-check.h +++ b/zzz_generated/app-common/app-common/zap-generated/cluster-enums-check.h @@ -1237,34 +1237,6 @@ static auto __attribute__((unused)) EnsureKnownEnumValue(GroupKeyManagement::Gro } } -static auto __attribute__((unused)) EnsureKnownEnumValue(LaundryWasherMode::ModeTag val) -{ - using EnumType = LaundryWasherMode::ModeTag; - switch (val) - { - case EnumType::kNormal: - case EnumType::kDelicate: - case EnumType::kHeavy: - case EnumType::kWhites: - return val; - default: - return static_cast(0); - } -} - -static auto __attribute__((unused)) EnsureKnownEnumValue(RefrigeratorAndTemperatureControlledCabinetMode::ModeTag val) -{ - using EnumType = RefrigeratorAndTemperatureControlledCabinetMode::ModeTag; - switch (val) - { - case EnumType::kRapidCool: - case EnumType::kRapidFreeze: - return val; - default: - return static_cast(0); - } -} - static auto __attribute__((unused)) EnsureKnownEnumValue(LaundryWasherControls::NumberOfRinsesEnum val) { using EnumType = LaundryWasherControls::NumberOfRinsesEnum; @@ -1280,76 +1252,6 @@ static auto __attribute__((unused)) EnsureKnownEnumValue(LaundryWasherControls:: } } -static auto __attribute__((unused)) EnsureKnownEnumValue(RvcRunMode::ModeTag val) -{ - using EnumType = RvcRunMode::ModeTag; - switch (val) - { - case EnumType::kIdle: - case EnumType::kCleaning: - return val; - default: - return static_cast(0); - } -} -static auto __attribute__((unused)) EnsureKnownEnumValue(RvcRunMode::StatusCode val) -{ - using EnumType = RvcRunMode::StatusCode; - switch (val) - { - case EnumType::kStuck: - case EnumType::kDustBinMissing: - case EnumType::kDustBinFull: - case EnumType::kWaterTankEmpty: - case EnumType::kWaterTankMissing: - case EnumType::kWaterTankLidOpen: - case EnumType::kMopCleaningPadMissing: - case EnumType::kBatteryLow: - return val; - default: - return static_cast(0); - } -} - -static auto __attribute__((unused)) EnsureKnownEnumValue(RvcCleanMode::ModeTag val) -{ - using EnumType = RvcCleanMode::ModeTag; - switch (val) - { - case EnumType::kDeepClean: - case EnumType::kVacuum: - case EnumType::kMop: - return val; - default: - return static_cast(0); - } -} -static auto __attribute__((unused)) EnsureKnownEnumValue(RvcCleanMode::StatusCode val) -{ - using EnumType = RvcCleanMode::StatusCode; - switch (val) - { - case EnumType::kCleaningInProgress: - return val; - default: - return static_cast(0); - } -} - -static auto __attribute__((unused)) EnsureKnownEnumValue(DishwasherMode::ModeTag val) -{ - using EnumType = DishwasherMode::ModeTag; - switch (val) - { - case EnumType::kNormal: - case EnumType::kHeavy: - case EnumType::kLight: - return val; - default: - return static_cast(0); - } -} - static auto __attribute__((unused)) EnsureKnownEnumValue(AirQuality::AirQualityEnum val) { using EnumType = AirQuality::AirQualityEnum; diff --git a/zzz_generated/app-common/app-common/zap-generated/cluster-enums.h b/zzz_generated/app-common/app-common/zap-generated/cluster-enums.h index 81baf06ac090c4..eec30fdb3976ea 100644 --- a/zzz_generated/app-common/app-common/zap-generated/cluster-enums.h +++ b/zzz_generated/app-common/app-common/zap-generated/cluster-enums.h @@ -1507,11 +1507,10 @@ enum class ModeTag : uint16_t kDelicate = 0x4001, kHeavy = 0x4002, kWhites = 0x4003, - // 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 = 0, + // 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. }; // Bitmap for Feature @@ -1528,11 +1527,10 @@ enum class ModeTag : uint16_t { kRapidCool = 0x4000, kRapidFreeze = 0x4001, - // 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 = 0, + // 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. }; // Bitmap for Feature @@ -1573,11 +1571,10 @@ enum class ModeTag : uint16_t { kIdle = 0x4000, kCleaning = 0x4001, - // 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 = 0, + // 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. }; // Enum for StatusCode @@ -1591,11 +1588,10 @@ enum class StatusCode : uint8_t kWaterTankLidOpen = 0x46, kMopCleaningPadMissing = 0x47, kBatteryLow = 0x48, - // 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 = 0, + // 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. }; // Bitmap for Feature @@ -1613,22 +1609,20 @@ enum class ModeTag : uint16_t kDeepClean = 0x4000, kVacuum = 0x4001, kMop = 0x4002, - // 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 = 0, + // 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. }; // Enum for StatusCode enum class StatusCode : uint8_t { kCleaningInProgress = 0x40, - // 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 = 0, + // 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. }; // Bitmap for Feature @@ -1666,11 +1660,10 @@ enum class ModeTag : uint16_t kNormal = 0x4000, kHeavy = 0x4001, kLight = 0x4002, - // 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 = 0, + // 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. }; // Bitmap for Feature