Skip to content

Commit 4c2702a

Browse files
Cleanup up comments and useless static cast
1 parent 64dbdd2 commit 4c2702a

File tree

2 files changed

+19
-6
lines changed

2 files changed

+19
-6
lines changed

src/app/clusters/scenes-server/SceneHandlerImpl.cpp

+14-2
Original file line numberDiff line numberDiff line change
@@ -121,8 +121,16 @@ void CapAttributeValue(typename app::NumericAttributeTraits<Type>::WorkingType &
121121

122122
if (metadata->IsBoolean())
123123
{
124-
// Caping the value to 1 in case values greater than 1 are set
125-
value = value ? 1 : 0;
124+
if (metadata->IsNullable() && (value != 1 && value != 0))
125+
{
126+
// If the attribute is nullable, the value can be set to NULL
127+
app::NumericAttributeTraits<WorkingType>::SetNull(value);
128+
}
129+
else
130+
{
131+
// Caping the value to 1 in case values greater than 1 are set
132+
value = value ? 1 : 0;
133+
}
126134
return;
127135
}
128136

@@ -134,6 +142,10 @@ void CapAttributeValue(typename app::NumericAttributeTraits<Type>::WorkingType &
134142
maxValue = ConvertDefaultValueToWorkingValue<Type>(minMaxValue->maxValue);
135143
}
136144

145+
// If the attribute is nullable, the min and max values calculated for types will not be valid, however this does not
146+
// change the behavior here as the value will already be NULL if it is out of range. E.g. a nullable INT8U has a minValue of
147+
// -127. The code above determin minValue = -128, so an input value of -128 would not enter the condition block below, but would
148+
// be considered NULL nonetheless.
137149
if (metadata->IsNullable() && (minValue > value || maxValue < value))
138150
{
139151
// If the attribute is nullable, the value can be set to NULL

src/app/tests/TestSceneTable.cpp

+5-4
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,7 @@ static EmberAfAttributeMetadata mockMetadataBool = {
176176
.attributeId = 0,
177177
.size = 1,
178178
.attributeType = ZCL_BOOLEAN_ATTRIBUTE_TYPE,
179-
.mask = ATTRIBUTE_MASK_WRITABLE | ATTRIBUTE_MASK_NULLABLE,
179+
.mask = ATTRIBUTE_MASK_WRITABLE,
180180
};
181181

182182
static EmberAfAttributeMetadata mockMetadataUint8 = {
@@ -1065,7 +1065,8 @@ TEST_F(TestSceneTable, TestHandlerFunctions)
10651065
MockCCPairs[5].attributeID = MockAttributeId(kEnhancedColorMode);
10661066
MockCCPairs[5].valueSigned8.SetValue(static_cast<int8_t>(-2)); // will cap to -1
10671067
MockCCPairs[6].attributeID = MockAttributeId(kColorLoopActiveId);
1068-
MockCCPairs[6].valueSigned16.SetValue(static_cast<int16_t>(0x7FFE)); // will cap to 0x7FFD in int16
1068+
MockCCPairs[6].valueSigned16.SetValue(
1069+
static_cast<int16_t>(0x7FFE)); // will cap to 0x7FFD in int16 due to declared maximum in the attribute's mock metadata
10691070
MockCCPairs[7].attributeID = MockAttributeId(kColorLoopDirectionId);
10701071
MockCCPairs[7].valueSigned32.SetValue(-1); // will cap to -1 in int24
10711072
MockCCPairs[8].attributeID = MockAttributeId(kColorLoopTimeId);
@@ -1279,9 +1280,9 @@ TEST_F(TestSceneTable, TestHandlerFunctions)
12791280

12801281
// Verify that the output value is capped to uint40 max value
12811282
uint64_t uint40Max = static_cast<uint64_t>(0x000000FFFFFFFFFF);
1282-
EXPECT_EQ(uint40Max, static_cast<uint64_t>(extensionFieldValueCapOut.attributeValueList[0].valueUnsigned64.Value()));
1283+
EXPECT_EQ(uint40Max, extensionFieldValueCapOut.attributeValueList[0].valueUnsigned64.Value());
12831284

1284-
// Verify that the output value is not capped
1285+
// Verify that the output value is capped to int40 max value
12851286
int64_t int40Max = static_cast<int64_t>(0x0000007FFFFFFFFF);
12861287
EXPECT_EQ(int40Max, extensionFieldValueCapOut.attributeValueList[1].valueSigned64.Value());
12871288

0 commit comments

Comments
 (0)