diff --git a/src/app/common/templates/config-data.yaml b/src/app/common/templates/config-data.yaml index e62e21a9fce29b..b404d1487020c2 100644 --- a/src/app/common/templates/config-data.yaml +++ b/src/app/common/templates/config-data.yaml @@ -10,6 +10,19 @@ WeakEnums: - PHYRateEnum - StepMode +EnumsNotUsedAsTypeInXML: + # List of enums that are not used as a type in XML. By adding an enum + # to this list you prevent incorrectly assuming from code that you are + # able to use kUnknownEnumValue safely. This happens for derived 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..cf66cef8a3d5c2 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) "EnumsNotUsedAsTypeInXML")}} 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 d6c9e46befde3c..2f4ba955abbf89 100644 --- a/src/app/zap-templates/templates/app/cluster-enums.zapt +++ b/src/app/zap-templates/templates/app/cluster-enums.zapt @@ -24,11 +24,19 @@ enum class {{asType label}} : {{asUnderlyingZclType name}} { {{#zcl_enum_items}} k{{asUpperCamelCase label}} = {{asHex value 2}}, {{/zcl_enum_items}} +{{#unless (isInConfigList (concat (asUpperCamelCase ../name) "::" label) "EnumsNotUsedAsTypeInXML")}} // 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 never goes +// through DataModel::Decode, likely because it is a part of a derived +// cluster. As a result having kUnknownEnumValue in this enum is error +// prone, and was removed. See +// src/app/common/templates/config-data.yaml. +{{/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 9fd5e22b832ab9..d9227c72573c3d 100644 --- a/src/controller/python/chip/clusters/Objects.py +++ b/src/controller/python/chip/clusters/Objects.py @@ -15261,11 +15261,11 @@ 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 never goes + # through DataModel::Decode, likely because it is a part of a derived + # cluster. As a result having kUnknownEnumValue in this enum is error + # prone, and was removed. See + # src/app/common/templates/config-data.yaml. class Bitmaps: class Feature(IntFlag): @@ -15532,11 +15532,11 @@ 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 never goes + # through DataModel::Decode, likely because it is a part of a derived + # cluster. As a result having kUnknownEnumValue in this enum is error + # prone, and was removed. See + # src/app/common/templates/config-data.yaml. class Bitmaps: class Feature(IntFlag): @@ -16013,11 +16013,11 @@ 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 never goes + # through DataModel::Decode, likely because it is a part of a derived + # cluster. As a result having kUnknownEnumValue in this enum is error + # prone, and was removed. See + # src/app/common/templates/config-data.yaml. class StatusCode(MatterIntEnum): kStuck = 0x41 @@ -16028,11 +16028,11 @@ 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 never goes + # through DataModel::Decode, likely because it is a part of a derived + # cluster. As a result having kUnknownEnumValue in this enum is error + # prone, and was removed. See + # src/app/common/templates/config-data.yaml. class Bitmaps: class Feature(IntFlag): @@ -16300,19 +16300,19 @@ 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 never goes + # through DataModel::Decode, likely because it is a part of a derived + # cluster. As a result having kUnknownEnumValue in this enum is error + # prone, and was removed. See + # src/app/common/templates/config-data.yaml. 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 never goes + # through DataModel::Decode, likely because it is a part of a derived + # cluster. As a result having kUnknownEnumValue in this enum is error + # prone, and was removed. See + # src/app/common/templates/config-data.yaml. class Bitmaps: class Feature(IntFlag): @@ -17039,11 +17039,11 @@ 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 never goes + # through DataModel::Decode, likely because it is a part of a derived + # cluster. As a result having kUnknownEnumValue in this enum is error + # prone, and was removed. See + # src/app/common/templates/config-data.yaml. 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..b5f8ed80ca03d9 100644 --- a/src/controller/python/templates/python-cluster-Objects-py.zapt +++ b/src/controller/python/templates/python-cluster-Objects-py.zapt @@ -54,11 +54,19 @@ class {{asUpperCamelCase name}}(Cluster): {{#zcl_enum_items}} k{{asUpperCamelCase label}} = {{asHex value 2}} {{/zcl_enum_items}} +{{#unless (isInConfigList (concat (asUpperCamelCase ../name) "::" label) "EnumsNotUsedAsTypeInXML")}} # 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 never goes + # through DataModel::Decode, likely because it is a part of a derived + # cluster. As a result having kUnknownEnumValue in this enum is error + # prone, and was removed. See + # src/app/common/templates/config-data.yaml. +{{/unless}} {{#last}} {{/last}} diff --git a/src/controller/python/templates/templates.json b/src/controller/python/templates/templates.json index e5d15198c5aac8..bffd9dfa2de7cc 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": [ { 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 851294af325272..9a8e5409d17453 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 @@ -1215,34 +1215,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; @@ -1258,76 +1230,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 d4925b21a741f5..80f06899acf9c2 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 @@ -1493,11 +1493,11 @@ 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 never goes + // through DataModel::Decode, likely because it is a part of a derived + // cluster. As a result having kUnknownEnumValue in this enum is error + // prone, and was removed. See + // src/app/common/templates/config-data.yaml. }; // Bitmap for Feature @@ -1514,11 +1514,11 @@ 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 never goes + // through DataModel::Decode, likely because it is a part of a derived + // cluster. As a result having kUnknownEnumValue in this enum is error + // prone, and was removed. See + // src/app/common/templates/config-data.yaml. }; // Bitmap for Feature @@ -1559,11 +1559,11 @@ 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 never goes + // through DataModel::Decode, likely because it is a part of a derived + // cluster. As a result having kUnknownEnumValue in this enum is error + // prone, and was removed. See + // src/app/common/templates/config-data.yaml. }; // Enum for StatusCode @@ -1577,11 +1577,11 @@ 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 never goes + // through DataModel::Decode, likely because it is a part of a derived + // cluster. As a result having kUnknownEnumValue in this enum is error + // prone, and was removed. See + // src/app/common/templates/config-data.yaml. }; // Bitmap for Feature @@ -1599,22 +1599,22 @@ 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 never goes + // through DataModel::Decode, likely because it is a part of a derived + // cluster. As a result having kUnknownEnumValue in this enum is error + // prone, and was removed. See + // src/app/common/templates/config-data.yaml. }; // 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 never goes + // through DataModel::Decode, likely because it is a part of a derived + // cluster. As a result having kUnknownEnumValue in this enum is error + // prone, and was removed. See + // src/app/common/templates/config-data.yaml. }; // Bitmap for Feature @@ -1652,11 +1652,11 @@ 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 never goes + // through DataModel::Decode, likely because it is a part of a derived + // cluster. As a result having kUnknownEnumValue in this enum is error + // prone, and was removed. See + // src/app/common/templates/config-data.yaml. }; // Bitmap for Feature