Skip to content

Commit f2bdd1f

Browse files
authored
EnergyPreference: Simplify logic around interaction with delegate (#32271)
`Optional<CharSpan>` is directly constructible from `Optional<MutableCharSpan>`
1 parent 3edfb9c commit f2bdd1f

File tree

1 file changed

+2
-6
lines changed

1 file changed

+2
-6
lines changed

src/app/clusters/energy-preference-server/energy-preference-server.cpp

+2-6
Original file line numberDiff line numberDiff line change
@@ -78,9 +78,7 @@ CHIP_ERROR EnergyPrefAttrAccess::Read(const ConcreteReadAttributePath & aPath, A
7878
Optional<MutableCharSpan> label{ MutableCharSpan(buffer) };
7979
if ((err = gsDelegate->GetEnergyBalanceAtIndex(endpoint, index, step, label)) == CHIP_NO_ERROR)
8080
{
81-
BalanceStruct::Type balance = { step,
82-
label.HasValue() ? Optional<CharSpan>(label.Value())
83-
: Optional<CharSpan>() };
81+
BalanceStruct::Type balance = { step, Optional<CharSpan>(label) };
8482
ReturnErrorOnFailure(encoder.Encode(balance));
8583
index++;
8684
}
@@ -137,9 +135,7 @@ CHIP_ERROR EnergyPrefAttrAccess::Read(const ConcreteReadAttributePath & aPath, A
137135
Optional<MutableCharSpan> label{ MutableCharSpan(buffer) };
138136
if ((err = gsDelegate->GetLowPowerModeSensitivityAtIndex(endpoint, index, step, label)) == CHIP_NO_ERROR)
139137
{
140-
BalanceStruct::Type balance = { step,
141-
label.HasValue() ? Optional<CharSpan>(label.Value())
142-
: Optional<CharSpan>() };
138+
BalanceStruct::Type balance = { step, Optional<CharSpan>(label) };
143139
ReturnErrorOnFailure(encoder.Encode(balance));
144140
index++;
145141
}

0 commit comments

Comments
 (0)