Skip to content

Commit 571e924

Browse files
nivi-applerestyled-commitsbzbarsky-apple
authored andcommitted
Update the preset handle field in the SetActivePresetRequest c… (project-chip#35105)
* Update the preset handle field in the SetActivePresetRequestRequest command to be nullable - Update the deleagte API for getting the active preset handle to return a nullable handle * Return error if CopySpanToMutableSpan fails * Restyled by clang-format * Apply suggestions from code review Co-authored-by: Boris Zbarsky <bzbarsky@apple.com> --------- Co-authored-by: Restyled.io <commits@restyled.io> Co-authored-by: Boris Zbarsky <bzbarsky@apple.com>
1 parent b9d5afe commit 571e924

File tree

26 files changed

+65
-52
lines changed

26 files changed

+65
-52
lines changed

examples/air-purifier-app/air-purifier-common/air-purifier-app.matter

+1-1
Original file line numberDiff line numberDiff line change
@@ -1856,7 +1856,7 @@ cluster Thermostat = 513 {
18561856
}
18571857

18581858
request struct SetActivePresetRequestRequest {
1859-
octet_string<16> presetHandle = 0;
1859+
nullable octet_string<16> presetHandle = 0;
18601860
}
18611861

18621862
response struct AtomicResponse = 253 {

examples/all-clusters-app/all-clusters-common/all-clusters-app.matter

+1-1
Original file line numberDiff line numberDiff line change
@@ -5696,7 +5696,7 @@ cluster Thermostat = 513 {
56965696
}
56975697

56985698
request struct SetActivePresetRequestRequest {
5699-
octet_string<16> presetHandle = 0;
5699+
nullable octet_string<16> presetHandle = 0;
57005700
}
57015701

57025702
response struct AtomicResponse = 253 {

examples/all-clusters-minimal-app/all-clusters-common/all-clusters-minimal-app.matter

+1-1
Original file line numberDiff line numberDiff line change
@@ -4130,7 +4130,7 @@ cluster Thermostat = 513 {
41304130
}
41314131

41324132
request struct SetActivePresetRequestRequest {
4133-
octet_string<16> presetHandle = 0;
4133+
nullable octet_string<16> presetHandle = 0;
41344134
}
41354135

41364136
response struct AtomicResponse = 253 {

examples/chef/devices/rootnode_airpurifier_airqualitysensor_temperaturesensor_humiditysensor_thermostat_56de3d5f45.matter

+1-1
Original file line numberDiff line numberDiff line change
@@ -1779,7 +1779,7 @@ cluster Thermostat = 513 {
17791779
}
17801780

17811781
request struct SetActivePresetRequestRequest {
1782-
octet_string<16> presetHandle = 0;
1782+
nullable octet_string<16> presetHandle = 0;
17831783
}
17841784

17851785
response struct AtomicResponse = 253 {

examples/chef/devices/rootnode_heatingcoolingunit_ncdGai1E5a.matter

+1-1
Original file line numberDiff line numberDiff line change
@@ -2136,7 +2136,7 @@ cluster Thermostat = 513 {
21362136
}
21372137

21382138
request struct SetActivePresetRequestRequest {
2139-
octet_string<16> presetHandle = 0;
2139+
nullable octet_string<16> presetHandle = 0;
21402140
}
21412141

21422142
response struct AtomicResponse = 253 {

examples/chef/devices/rootnode_roomairconditioner_9cf3607804.matter

+1-1
Original file line numberDiff line numberDiff line change
@@ -1719,7 +1719,7 @@ cluster Thermostat = 513 {
17191719
}
17201720

17211721
request struct SetActivePresetRequestRequest {
1722-
octet_string<16> presetHandle = 0;
1722+
nullable octet_string<16> presetHandle = 0;
17231723
}
17241724

17251725
response struct AtomicResponse = 253 {

examples/chef/devices/rootnode_thermostat_bm3fb8dhYi.matter

+1-1
Original file line numberDiff line numberDiff line change
@@ -1939,7 +1939,7 @@ cluster Thermostat = 513 {
19391939
}
19401940

19411941
request struct SetActivePresetRequestRequest {
1942-
octet_string<16> presetHandle = 0;
1942+
nullable octet_string<16> presetHandle = 0;
19431943
}
19441944

19451945
response struct AtomicResponse = 253 {

examples/placeholder/linux/apps/app1/config.matter

+2-2
Original file line numberDiff line numberDiff line change
@@ -5414,7 +5414,7 @@ cluster Thermostat = 513 {
54145414
}
54155415

54165416
request struct SetActivePresetRequestRequest {
5417-
octet_string<16> presetHandle = 0;
5417+
nullable octet_string<16> presetHandle = 0;
54185418
}
54195419

54205420
response struct AtomicResponse = 253 {
@@ -5769,7 +5769,7 @@ cluster Thermostat = 513 {
57695769
}
57705770

57715771
request struct SetActivePresetRequestRequest {
5772-
octet_string<16> presetHandle = 0;
5772+
nullable octet_string<16> presetHandle = 0;
57735773
}
57745774

57755775
response struct AtomicResponse = 253 {

examples/placeholder/linux/apps/app2/config.matter

+2-2
Original file line numberDiff line numberDiff line change
@@ -5371,7 +5371,7 @@ cluster Thermostat = 513 {
53715371
}
53725372

53735373
request struct SetActivePresetRequestRequest {
5374-
octet_string<16> presetHandle = 0;
5374+
nullable octet_string<16> presetHandle = 0;
53755375
}
53765376

53775377
response struct AtomicResponse = 253 {
@@ -5726,7 +5726,7 @@ cluster Thermostat = 513 {
57265726
}
57275727

57285728
request struct SetActivePresetRequestRequest {
5729-
octet_string<16> presetHandle = 0;
5729+
nullable octet_string<16> presetHandle = 0;
57305730
}
57315731

57325732
response struct AtomicResponse = 253 {

examples/thermostat/linux/include/thermostat-delegate-impl.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ class ThermostatDelegate : public Delegate
5454

5555
CHIP_ERROR GetPresetAtIndex(size_t index, PresetStructWithOwnedMembers & preset) override;
5656

57-
CHIP_ERROR GetActivePresetHandle(MutableByteSpan & activePresetHandle) override;
57+
CHIP_ERROR GetActivePresetHandle(DataModel::Nullable<MutableByteSpan> & activePresetHandle) override;
5858

5959
CHIP_ERROR SetActivePresetHandle(const DataModel::Nullable<ByteSpan> & newActivePresetHandle) override;
6060

examples/thermostat/linux/thermostat-delegate-impl.cpp

+12-2
Original file line numberDiff line numberDiff line change
@@ -117,9 +117,19 @@ CHIP_ERROR ThermostatDelegate::GetPresetAtIndex(size_t index, PresetStructWithOw
117117
return CHIP_ERROR_PROVIDER_LIST_EXHAUSTED;
118118
}
119119

120-
CHIP_ERROR ThermostatDelegate::GetActivePresetHandle(MutableByteSpan & activePresetHandle)
120+
CHIP_ERROR ThermostatDelegate::GetActivePresetHandle(DataModel::Nullable<MutableByteSpan> & activePresetHandle)
121121
{
122-
return CopySpanToMutableSpan(ByteSpan(mActivePresetHandleData, mActivePresetHandleDataSize), activePresetHandle);
122+
if (mActivePresetHandleDataSize != 0)
123+
{
124+
ReturnErrorOnFailure(
125+
CopySpanToMutableSpan(ByteSpan(mActivePresetHandleData, mActivePresetHandleDataSize), activePresetHandle.Value()));
126+
activePresetHandle.Value().reduce_size(mActivePresetHandleDataSize);
127+
}
128+
else
129+
{
130+
activePresetHandle.SetNull();
131+
}
132+
return CHIP_NO_ERROR;
123133
}
124134

125135
CHIP_ERROR ThermostatDelegate::SetActivePresetHandle(const DataModel::Nullable<ByteSpan> & newActivePresetHandle)

examples/thermostat/nxp/zap/thermostat_matter_thread.matter

+1-1
Original file line numberDiff line numberDiff line change
@@ -2530,7 +2530,7 @@ cluster Thermostat = 513 {
25302530
}
25312531

25322532
request struct SetActivePresetRequestRequest {
2533-
octet_string<16> presetHandle = 0;
2533+
nullable octet_string<16> presetHandle = 0;
25342534
}
25352535

25362536
response struct AtomicResponse = 253 {

examples/thermostat/nxp/zap/thermostat_matter_wifi.matter

+1-1
Original file line numberDiff line numberDiff line change
@@ -2441,7 +2441,7 @@ cluster Thermostat = 513 {
24412441
}
24422442

24432443
request struct SetActivePresetRequestRequest {
2444-
octet_string<16> presetHandle = 0;
2444+
nullable octet_string<16> presetHandle = 0;
24452445
}
24462446

24472447
response struct AtomicResponse = 253 {

examples/thermostat/qpg/zap/thermostaticRadiatorValve.matter

+1-1
Original file line numberDiff line numberDiff line change
@@ -2138,7 +2138,7 @@ cluster Thermostat = 513 {
21382138
}
21392139

21402140
request struct SetActivePresetRequestRequest {
2141-
octet_string<16> presetHandle = 0;
2141+
nullable octet_string<16> presetHandle = 0;
21422142
}
21432143

21442144
response struct AtomicResponse = 253 {

examples/thermostat/thermostat-common/thermostat.matter

+1-1
Original file line numberDiff line numberDiff line change
@@ -2318,7 +2318,7 @@ cluster Thermostat = 513 {
23182318
}
23192319

23202320
request struct SetActivePresetRequestRequest {
2321-
octet_string<16> presetHandle = 0;
2321+
nullable octet_string<16> presetHandle = 0;
23222322
}
23232323

23242324
response struct AtomicResponse = 253 {

src/app/clusters/thermostat-server/thermostat-delegate.h

+3-4
Original file line numberDiff line numberDiff line change
@@ -78,11 +78,10 @@ class Delegate
7878
/**
7979
* @brief Get the ActivePresetHandle attribute value.
8080
*
81-
* @param[out] activePresetHandle The MutableByteSpan to copy the active preset handle into. On success,
82-
* the callee must update the length to the length of the copied data. If the value of
83-
* the attribute is null, the callee must set the MutableByteSpan to empty.
81+
* @param[out] activePresetHandle The nullable MutableByteSpan to copy the active preset handle into. On success,
82+
* the size of the activePresetHandle is updated to the length of the copied data.
8483
*/
85-
virtual CHIP_ERROR GetActivePresetHandle(MutableByteSpan & activePresetHandle) = 0;
84+
virtual CHIP_ERROR GetActivePresetHandle(DataModel::Nullable<MutableByteSpan> & activePresetHandle) = 0;
8685

8786
/**
8887
* @brief Set the ActivePresetHandle attribute value.

src/app/clusters/thermostat-server/thermostat-server.cpp

+10-15
Original file line numberDiff line numberDiff line change
@@ -761,19 +761,13 @@ CHIP_ERROR ThermostatAttrAccess::Read(const ConcreteReadAttributePath & aPath, A
761761
VerifyOrReturnError(delegate != nullptr, CHIP_ERROR_INCORRECT_STATE, ChipLogError(Zcl, "Delegate is null"));
762762

763763
uint8_t buffer[kPresetHandleSize];
764-
MutableByteSpan activePresetHandle(buffer);
764+
MutableByteSpan activePresetHandleSpan(buffer);
765+
auto activePresetHandle = DataModel::MakeNullable(activePresetHandleSpan);
765766

766767
CHIP_ERROR err = delegate->GetActivePresetHandle(activePresetHandle);
767768
ReturnErrorOnFailure(err);
768769

769-
if (activePresetHandle.empty())
770-
{
771-
ReturnErrorOnFailure(aEncoder.EncodeNull());
772-
}
773-
else
774-
{
775-
ReturnErrorOnFailure(aEncoder.Encode(activePresetHandle));
776-
}
770+
ReturnErrorOnFailure(aEncoder.Encode(activePresetHandle));
777771
}
778772
break;
779773
case ScheduleTypes::Id: {
@@ -1299,16 +1293,16 @@ bool emberAfThermostatClusterSetActivePresetRequestCallback(
12991293
return true;
13001294
}
13011295

1302-
ByteSpan newPresetHandle = commandData.presetHandle;
1296+
DataModel::Nullable<ByteSpan> newPresetHandle = commandData.presetHandle;
13031297

13041298
// If the preset handle passed in the command is not present in the Presets attribute, return INVALID_COMMAND.
1305-
if (!IsPresetHandlePresentInPresets(delegate, newPresetHandle))
1299+
if (!newPresetHandle.IsNull() && !IsPresetHandlePresentInPresets(delegate, newPresetHandle.Value()))
13061300
{
13071301
commandObj->AddStatus(commandPath, imcode::InvalidCommand);
13081302
return true;
13091303
}
13101304

1311-
CHIP_ERROR err = delegate->SetActivePresetHandle(DataModel::MakeNullable(newPresetHandle));
1305+
CHIP_ERROR err = delegate->SetActivePresetHandle(newPresetHandle);
13121306

13131307
if (err != CHIP_NO_ERROR)
13141308
{
@@ -1470,7 +1464,8 @@ imcode commitPresets(Delegate * delegate, EndpointId endpoint)
14701464
// attribute. If a preset is not found with the same presetHandle, return INVALID_IN_STATE. If there is no ActivePresetHandle
14711465
// attribute set, continue with other checks.
14721466
uint8_t buffer[kPresetHandleSize];
1473-
MutableByteSpan activePresetHandle(buffer);
1467+
MutableByteSpan activePresetHandleSpan(buffer);
1468+
auto activePresetHandle = DataModel::MakeNullable(activePresetHandleSpan);
14741469

14751470
err = delegate->GetActivePresetHandle(activePresetHandle);
14761471

@@ -1479,9 +1474,9 @@ imcode commitPresets(Delegate * delegate, EndpointId endpoint)
14791474
return imcode::InvalidInState;
14801475
}
14811476

1482-
if (!activePresetHandle.empty())
1477+
if (!activePresetHandle.IsNull())
14831478
{
1484-
uint8_t count = CountPresetsInPendingListWithPresetHandle(delegate, activePresetHandle);
1479+
uint8_t count = CountPresetsInPendingListWithPresetHandle(delegate, activePresetHandle.Value());
14851480
if (count == 0)
14861481
{
14871482
return imcode::InvalidInState;

src/app/zap-templates/zcl/data-model/chip/thermostat-cluster.xml

+1-1
Original file line numberDiff line numberDiff line change
@@ -481,7 +481,7 @@ limitations under the License.
481481

482482
<command source="client" code="0x06" name="SetActivePresetRequest" optional="true">
483483
<description>ID</description>
484-
<arg id="0" name="PresetHandle" type="octet_string" length="16"/>
484+
<arg id="0" name="PresetHandle" type="octet_string" length="16" isNullable="true"/>
485485
</command>
486486

487487
<!-- Server Commands/Responses -->

src/controller/data_model/controller-clusters.matter

+1-1
Original file line numberDiff line numberDiff line change
@@ -6994,7 +6994,7 @@ cluster Thermostat = 513 {
69946994
}
69956995

69966996
request struct SetActivePresetRequestRequest {
6997-
octet_string<16> presetHandle = 0;
6997+
nullable octet_string<16> presetHandle = 0;
69986998
}
69996999

70007000
response struct AtomicResponse = 253 {

src/controller/java/generated/java/chip/devicecontroller/ChipClusters.java

+3-3
Original file line numberDiff line numberDiff line change
@@ -40637,16 +40637,16 @@ public void onResponse(StructType invokeStructValue) {
4063740637
}}, commandId, commandArgs, timedInvokeTimeoutMs);
4063840638
}
4063940639

40640-
public void setActivePresetRequest(DefaultClusterCallback callback, byte[] presetHandle) {
40640+
public void setActivePresetRequest(DefaultClusterCallback callback, @Nullable byte[] presetHandle) {
4064140641
setActivePresetRequest(callback, presetHandle, 0);
4064240642
}
4064340643

40644-
public void setActivePresetRequest(DefaultClusterCallback callback, byte[] presetHandle, int timedInvokeTimeoutMs) {
40644+
public void setActivePresetRequest(DefaultClusterCallback callback, @Nullable byte[] presetHandle, int timedInvokeTimeoutMs) {
4064540645
final long commandId = 6L;
4064640646

4064740647
ArrayList<StructElement> elements = new ArrayList<>();
4064840648
final long presetHandleFieldID = 0L;
40649-
BaseTLVType presetHandletlvValue = new ByteArrayType(presetHandle);
40649+
BaseTLVType presetHandletlvValue = presetHandle != null ? new ByteArrayType(presetHandle) : new NullType();
4065040650
elements.add(new StructElement(presetHandleFieldID, presetHandletlvValue));
4065140651

4065240652
StructType commandArgs = new StructType(elements);

src/controller/java/generated/java/matter/controller/cluster/clusters/ThermostatCluster.kt

+2-2
Original file line numberDiff line numberDiff line change
@@ -504,7 +504,7 @@ class ThermostatCluster(private val controller: MatterController, private val en
504504
}
505505

506506
suspend fun setActivePresetRequest(
507-
presetHandle: ByteArray,
507+
presetHandle: ByteArray?,
508508
timedInvokeTimeout: Duration? = null,
509509
) {
510510
val commandId: UInt = 6u
@@ -513,7 +513,7 @@ class ThermostatCluster(private val controller: MatterController, private val en
513513
tlvWriter.startStructure(AnonymousTag)
514514

515515
val TAG_PRESET_HANDLE_REQ: Int = 0
516-
tlvWriter.put(ContextSpecificTag(TAG_PRESET_HANDLE_REQ), presetHandle)
516+
presetHandle?.let { tlvWriter.put(ContextSpecificTag(TAG_PRESET_HANDLE_REQ), presetHandle) }
517517
tlvWriter.endStructure()
518518

519519
val request: InvokeRequest =

src/controller/python/chip/clusters/Objects.py

+2-2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/darwin/Framework/CHIP/zap-generated/MTRCommandPayloadsObjc.h

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/darwin/Framework/CHIP/zap-generated/MTRCommandPayloadsObjc.mm

+7-2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

zzz_generated/app-common/app-common/zap-generated/cluster-objects.h

+2-2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

zzz_generated/darwin-framework-tool/zap-generated/cluster/Commands.h

+5-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)