Update the preset handle field in the SetActivePresetRequest c… (#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>
diff --git a/examples/air-purifier-app/air-purifier-common/air-purifier-app.matter b/examples/air-purifier-app/air-purifier-common/air-purifier-app.matter
index cb1c102..c35b8b6 100644
--- a/examples/air-purifier-app/air-purifier-common/air-purifier-app.matter
+++ b/examples/air-purifier-app/air-purifier-common/air-purifier-app.matter
@@ -1856,7 +1856,7 @@
   }
 
   request struct SetActivePresetRequestRequest {
-    octet_string<16> presetHandle = 0;
+    nullable octet_string<16> presetHandle = 0;
   }
 
   response struct AtomicResponse = 253 {
diff --git a/examples/all-clusters-app/all-clusters-common/all-clusters-app.matter b/examples/all-clusters-app/all-clusters-common/all-clusters-app.matter
index c18c616..4180b1e 100644
--- a/examples/all-clusters-app/all-clusters-common/all-clusters-app.matter
+++ b/examples/all-clusters-app/all-clusters-common/all-clusters-app.matter
@@ -5696,7 +5696,7 @@
   }
 
   request struct SetActivePresetRequestRequest {
-    octet_string<16> presetHandle = 0;
+    nullable octet_string<16> presetHandle = 0;
   }
 
   response struct AtomicResponse = 253 {
diff --git a/examples/all-clusters-minimal-app/all-clusters-common/all-clusters-minimal-app.matter b/examples/all-clusters-minimal-app/all-clusters-common/all-clusters-minimal-app.matter
index 16f170c..363da41 100644
--- a/examples/all-clusters-minimal-app/all-clusters-common/all-clusters-minimal-app.matter
+++ b/examples/all-clusters-minimal-app/all-clusters-common/all-clusters-minimal-app.matter
@@ -4130,7 +4130,7 @@
   }
 
   request struct SetActivePresetRequestRequest {
-    octet_string<16> presetHandle = 0;
+    nullable octet_string<16> presetHandle = 0;
   }
 
   response struct AtomicResponse = 253 {
diff --git a/examples/chef/devices/rootnode_airpurifier_airqualitysensor_temperaturesensor_humiditysensor_thermostat_56de3d5f45.matter b/examples/chef/devices/rootnode_airpurifier_airqualitysensor_temperaturesensor_humiditysensor_thermostat_56de3d5f45.matter
index ed130f2..d47b3a9 100644
--- a/examples/chef/devices/rootnode_airpurifier_airqualitysensor_temperaturesensor_humiditysensor_thermostat_56de3d5f45.matter
+++ b/examples/chef/devices/rootnode_airpurifier_airqualitysensor_temperaturesensor_humiditysensor_thermostat_56de3d5f45.matter
@@ -1779,7 +1779,7 @@
   }
 
   request struct SetActivePresetRequestRequest {
-    octet_string<16> presetHandle = 0;
+    nullable octet_string<16> presetHandle = 0;
   }
 
   response struct AtomicResponse = 253 {
diff --git a/examples/chef/devices/rootnode_heatingcoolingunit_ncdGai1E5a.matter b/examples/chef/devices/rootnode_heatingcoolingunit_ncdGai1E5a.matter
index ec62d45..84b5d94 100644
--- a/examples/chef/devices/rootnode_heatingcoolingunit_ncdGai1E5a.matter
+++ b/examples/chef/devices/rootnode_heatingcoolingunit_ncdGai1E5a.matter
@@ -2136,7 +2136,7 @@
   }
 
   request struct SetActivePresetRequestRequest {
-    octet_string<16> presetHandle = 0;
+    nullable octet_string<16> presetHandle = 0;
   }
 
   response struct AtomicResponse = 253 {
diff --git a/examples/chef/devices/rootnode_roomairconditioner_9cf3607804.matter b/examples/chef/devices/rootnode_roomairconditioner_9cf3607804.matter
index 95e0ba2..20b7d6b 100644
--- a/examples/chef/devices/rootnode_roomairconditioner_9cf3607804.matter
+++ b/examples/chef/devices/rootnode_roomairconditioner_9cf3607804.matter
@@ -1719,7 +1719,7 @@
   }
 
   request struct SetActivePresetRequestRequest {
-    octet_string<16> presetHandle = 0;
+    nullable octet_string<16> presetHandle = 0;
   }
 
   response struct AtomicResponse = 253 {
diff --git a/examples/chef/devices/rootnode_thermostat_bm3fb8dhYi.matter b/examples/chef/devices/rootnode_thermostat_bm3fb8dhYi.matter
index 6c27235..ae6441c 100644
--- a/examples/chef/devices/rootnode_thermostat_bm3fb8dhYi.matter
+++ b/examples/chef/devices/rootnode_thermostat_bm3fb8dhYi.matter
@@ -1939,7 +1939,7 @@
   }
 
   request struct SetActivePresetRequestRequest {
-    octet_string<16> presetHandle = 0;
+    nullable octet_string<16> presetHandle = 0;
   }
 
   response struct AtomicResponse = 253 {
diff --git a/examples/placeholder/linux/apps/app1/config.matter b/examples/placeholder/linux/apps/app1/config.matter
index 8befb87..33521a7 100644
--- a/examples/placeholder/linux/apps/app1/config.matter
+++ b/examples/placeholder/linux/apps/app1/config.matter
@@ -5414,7 +5414,7 @@
   }
 
   request struct SetActivePresetRequestRequest {
-    octet_string<16> presetHandle = 0;
+    nullable octet_string<16> presetHandle = 0;
   }
 
   response struct AtomicResponse = 253 {
@@ -5769,7 +5769,7 @@
   }
 
   request struct SetActivePresetRequestRequest {
-    octet_string<16> presetHandle = 0;
+    nullable octet_string<16> presetHandle = 0;
   }
 
   response struct AtomicResponse = 253 {
diff --git a/examples/placeholder/linux/apps/app2/config.matter b/examples/placeholder/linux/apps/app2/config.matter
index 6cfcc1a..86d20b2 100644
--- a/examples/placeholder/linux/apps/app2/config.matter
+++ b/examples/placeholder/linux/apps/app2/config.matter
@@ -5371,7 +5371,7 @@
   }
 
   request struct SetActivePresetRequestRequest {
-    octet_string<16> presetHandle = 0;
+    nullable octet_string<16> presetHandle = 0;
   }
 
   response struct AtomicResponse = 253 {
@@ -5726,7 +5726,7 @@
   }
 
   request struct SetActivePresetRequestRequest {
-    octet_string<16> presetHandle = 0;
+    nullable octet_string<16> presetHandle = 0;
   }
 
   response struct AtomicResponse = 253 {
diff --git a/examples/thermostat/linux/include/thermostat-delegate-impl.h b/examples/thermostat/linux/include/thermostat-delegate-impl.h
index 8252f22..6bf9d02 100644
--- a/examples/thermostat/linux/include/thermostat-delegate-impl.h
+++ b/examples/thermostat/linux/include/thermostat-delegate-impl.h
@@ -54,7 +54,7 @@
 
     CHIP_ERROR GetPresetAtIndex(size_t index, PresetStructWithOwnedMembers & preset) override;
 
-    CHIP_ERROR GetActivePresetHandle(MutableByteSpan & activePresetHandle) override;
+    CHIP_ERROR GetActivePresetHandle(DataModel::Nullable<MutableByteSpan> & activePresetHandle) override;
 
     CHIP_ERROR SetActivePresetHandle(const DataModel::Nullable<ByteSpan> & newActivePresetHandle) override;
 
diff --git a/examples/thermostat/linux/thermostat-delegate-impl.cpp b/examples/thermostat/linux/thermostat-delegate-impl.cpp
index c39a757..b931db2 100644
--- a/examples/thermostat/linux/thermostat-delegate-impl.cpp
+++ b/examples/thermostat/linux/thermostat-delegate-impl.cpp
@@ -117,9 +117,19 @@
     return CHIP_ERROR_PROVIDER_LIST_EXHAUSTED;
 }
 
-CHIP_ERROR ThermostatDelegate::GetActivePresetHandle(MutableByteSpan & activePresetHandle)
+CHIP_ERROR ThermostatDelegate::GetActivePresetHandle(DataModel::Nullable<MutableByteSpan> & activePresetHandle)
 {
-    return CopySpanToMutableSpan(ByteSpan(mActivePresetHandleData, mActivePresetHandleDataSize), activePresetHandle);
+    if (mActivePresetHandleDataSize != 0)
+    {
+        ReturnErrorOnFailure(
+            CopySpanToMutableSpan(ByteSpan(mActivePresetHandleData, mActivePresetHandleDataSize), activePresetHandle.Value()));
+        activePresetHandle.Value().reduce_size(mActivePresetHandleDataSize);
+    }
+    else
+    {
+        activePresetHandle.SetNull();
+    }
+    return CHIP_NO_ERROR;
 }
 
 CHIP_ERROR ThermostatDelegate::SetActivePresetHandle(const DataModel::Nullable<ByteSpan> & newActivePresetHandle)
diff --git a/examples/thermostat/nxp/zap/thermostat_matter_thread.matter b/examples/thermostat/nxp/zap/thermostat_matter_thread.matter
index 001e1b4..cbe6a62 100644
--- a/examples/thermostat/nxp/zap/thermostat_matter_thread.matter
+++ b/examples/thermostat/nxp/zap/thermostat_matter_thread.matter
@@ -2530,7 +2530,7 @@
   }
 
   request struct SetActivePresetRequestRequest {
-    octet_string<16> presetHandle = 0;
+    nullable octet_string<16> presetHandle = 0;
   }
 
   response struct AtomicResponse = 253 {
diff --git a/examples/thermostat/nxp/zap/thermostat_matter_wifi.matter b/examples/thermostat/nxp/zap/thermostat_matter_wifi.matter
index 066afc8..cd9ddc3 100644
--- a/examples/thermostat/nxp/zap/thermostat_matter_wifi.matter
+++ b/examples/thermostat/nxp/zap/thermostat_matter_wifi.matter
@@ -2441,7 +2441,7 @@
   }
 
   request struct SetActivePresetRequestRequest {
-    octet_string<16> presetHandle = 0;
+    nullable octet_string<16> presetHandle = 0;
   }
 
   response struct AtomicResponse = 253 {
diff --git a/examples/thermostat/qpg/zap/thermostaticRadiatorValve.matter b/examples/thermostat/qpg/zap/thermostaticRadiatorValve.matter
index 31e5775..548db02 100644
--- a/examples/thermostat/qpg/zap/thermostaticRadiatorValve.matter
+++ b/examples/thermostat/qpg/zap/thermostaticRadiatorValve.matter
@@ -2138,7 +2138,7 @@
   }
 
   request struct SetActivePresetRequestRequest {
-    octet_string<16> presetHandle = 0;
+    nullable octet_string<16> presetHandle = 0;
   }
 
   response struct AtomicResponse = 253 {
diff --git a/examples/thermostat/thermostat-common/thermostat.matter b/examples/thermostat/thermostat-common/thermostat.matter
index c53651c..a66c2df 100644
--- a/examples/thermostat/thermostat-common/thermostat.matter
+++ b/examples/thermostat/thermostat-common/thermostat.matter
@@ -2318,7 +2318,7 @@
   }
 
   request struct SetActivePresetRequestRequest {
-    octet_string<16> presetHandle = 0;
+    nullable octet_string<16> presetHandle = 0;
   }
 
   response struct AtomicResponse = 253 {
diff --git a/src/app/clusters/thermostat-server/thermostat-delegate.h b/src/app/clusters/thermostat-server/thermostat-delegate.h
index c8c21d8..0f89f69 100644
--- a/src/app/clusters/thermostat-server/thermostat-delegate.h
+++ b/src/app/clusters/thermostat-server/thermostat-delegate.h
@@ -78,11 +78,10 @@
     /**
      * @brief Get the ActivePresetHandle attribute value.
      *
-     * @param[out] activePresetHandle The MutableByteSpan to copy the active preset handle into. On success,
-     *             the callee must update the length to the length of the copied data. If the value of
-     *             the attribute is null, the callee must set the MutableByteSpan to empty.
+     * @param[out] activePresetHandle The nullable MutableByteSpan to copy the active preset handle into. On success,
+     *             the size of the activePresetHandle is updated to the length of the copied data.
      */
-    virtual CHIP_ERROR GetActivePresetHandle(MutableByteSpan & activePresetHandle) = 0;
+    virtual CHIP_ERROR GetActivePresetHandle(DataModel::Nullable<MutableByteSpan> & activePresetHandle) = 0;
 
     /**
      * @brief Set the ActivePresetHandle attribute value.
diff --git a/src/app/clusters/thermostat-server/thermostat-server.cpp b/src/app/clusters/thermostat-server/thermostat-server.cpp
index 91c045c..8fe7021 100644
--- a/src/app/clusters/thermostat-server/thermostat-server.cpp
+++ b/src/app/clusters/thermostat-server/thermostat-server.cpp
@@ -761,19 +761,13 @@
         VerifyOrReturnError(delegate != nullptr, CHIP_ERROR_INCORRECT_STATE, ChipLogError(Zcl, "Delegate is null"));
 
         uint8_t buffer[kPresetHandleSize];
-        MutableByteSpan activePresetHandle(buffer);
+        MutableByteSpan activePresetHandleSpan(buffer);
+        auto activePresetHandle = DataModel::MakeNullable(activePresetHandleSpan);
 
         CHIP_ERROR err = delegate->GetActivePresetHandle(activePresetHandle);
         ReturnErrorOnFailure(err);
 
-        if (activePresetHandle.empty())
-        {
-            ReturnErrorOnFailure(aEncoder.EncodeNull());
-        }
-        else
-        {
-            ReturnErrorOnFailure(aEncoder.Encode(activePresetHandle));
-        }
+        ReturnErrorOnFailure(aEncoder.Encode(activePresetHandle));
     }
     break;
     case ScheduleTypes::Id: {
@@ -1299,16 +1293,16 @@
         return true;
     }
 
-    ByteSpan newPresetHandle = commandData.presetHandle;
+    DataModel::Nullable<ByteSpan> newPresetHandle = commandData.presetHandle;
 
     // If the preset handle passed in the command is not present in the Presets attribute, return INVALID_COMMAND.
-    if (!IsPresetHandlePresentInPresets(delegate, newPresetHandle))
+    if (!newPresetHandle.IsNull() && !IsPresetHandlePresentInPresets(delegate, newPresetHandle.Value()))
     {
         commandObj->AddStatus(commandPath, imcode::InvalidCommand);
         return true;
     }
 
-    CHIP_ERROR err = delegate->SetActivePresetHandle(DataModel::MakeNullable(newPresetHandle));
+    CHIP_ERROR err = delegate->SetActivePresetHandle(newPresetHandle);
 
     if (err != CHIP_NO_ERROR)
     {
@@ -1470,7 +1464,8 @@
     // attribute. If a preset is not found with the same presetHandle, return INVALID_IN_STATE. If there is no ActivePresetHandle
     // attribute set, continue with other checks.
     uint8_t buffer[kPresetHandleSize];
-    MutableByteSpan activePresetHandle(buffer);
+    MutableByteSpan activePresetHandleSpan(buffer);
+    auto activePresetHandle = DataModel::MakeNullable(activePresetHandleSpan);
 
     err = delegate->GetActivePresetHandle(activePresetHandle);
 
@@ -1479,9 +1474,9 @@
         return imcode::InvalidInState;
     }
 
-    if (!activePresetHandle.empty())
+    if (!activePresetHandle.IsNull())
     {
-        uint8_t count = CountPresetsInPendingListWithPresetHandle(delegate, activePresetHandle);
+        uint8_t count = CountPresetsInPendingListWithPresetHandle(delegate, activePresetHandle.Value());
         if (count == 0)
         {
             return imcode::InvalidInState;
diff --git a/src/app/zap-templates/zcl/data-model/chip/thermostat-cluster.xml b/src/app/zap-templates/zcl/data-model/chip/thermostat-cluster.xml
index 546692b..6f75aa4 100644
--- a/src/app/zap-templates/zcl/data-model/chip/thermostat-cluster.xml
+++ b/src/app/zap-templates/zcl/data-model/chip/thermostat-cluster.xml
@@ -481,7 +481,7 @@
 
     <command source="client" code="0x06" name="SetActivePresetRequest" optional="true">
       <description>ID</description>
-      <arg id="0" name="PresetHandle" type="octet_string" length="16"/>
+      <arg id="0" name="PresetHandle" type="octet_string" length="16" isNullable="true"/>
     </command>
 
     <!-- Server Commands/Responses -->
diff --git a/src/controller/data_model/controller-clusters.matter b/src/controller/data_model/controller-clusters.matter
index bfb1354..52f43c0 100644
--- a/src/controller/data_model/controller-clusters.matter
+++ b/src/controller/data_model/controller-clusters.matter
@@ -6994,7 +6994,7 @@
   }
 
   request struct SetActivePresetRequestRequest {
-    octet_string<16> presetHandle = 0;
+    nullable octet_string<16> presetHandle = 0;
   }
 
   response struct AtomicResponse = 253 {
diff --git a/src/controller/java/generated/java/chip/devicecontroller/ChipClusters.java b/src/controller/java/generated/java/chip/devicecontroller/ChipClusters.java
index 6f3e6f6..cf344db 100644
--- a/src/controller/java/generated/java/chip/devicecontroller/ChipClusters.java
+++ b/src/controller/java/generated/java/chip/devicecontroller/ChipClusters.java
@@ -40637,16 +40637,16 @@
         }}, commandId, commandArgs, timedInvokeTimeoutMs);
     }
 
-    public void setActivePresetRequest(DefaultClusterCallback callback, byte[] presetHandle) {
+    public void setActivePresetRequest(DefaultClusterCallback callback, @Nullable byte[] presetHandle) {
       setActivePresetRequest(callback, presetHandle, 0);
     }
 
-    public void setActivePresetRequest(DefaultClusterCallback callback, byte[] presetHandle, int timedInvokeTimeoutMs) {
+    public void setActivePresetRequest(DefaultClusterCallback callback, @Nullable byte[] presetHandle, int timedInvokeTimeoutMs) {
       final long commandId = 6L;
 
       ArrayList<StructElement> elements = new ArrayList<>();
       final long presetHandleFieldID = 0L;
-      BaseTLVType presetHandletlvValue = new ByteArrayType(presetHandle);
+      BaseTLVType presetHandletlvValue = presetHandle != null ? new ByteArrayType(presetHandle) : new NullType();
       elements.add(new StructElement(presetHandleFieldID, presetHandletlvValue));
 
       StructType commandArgs = new StructType(elements);
diff --git a/src/controller/java/generated/java/matter/controller/cluster/clusters/ThermostatCluster.kt b/src/controller/java/generated/java/matter/controller/cluster/clusters/ThermostatCluster.kt
index b9166c1..6f193e6 100644
--- a/src/controller/java/generated/java/matter/controller/cluster/clusters/ThermostatCluster.kt
+++ b/src/controller/java/generated/java/matter/controller/cluster/clusters/ThermostatCluster.kt
@@ -504,7 +504,7 @@
   }
 
   suspend fun setActivePresetRequest(
-    presetHandle: ByteArray,
+    presetHandle: ByteArray?,
     timedInvokeTimeout: Duration? = null,
   ) {
     val commandId: UInt = 6u
@@ -513,7 +513,7 @@
     tlvWriter.startStructure(AnonymousTag)
 
     val TAG_PRESET_HANDLE_REQ: Int = 0
-    tlvWriter.put(ContextSpecificTag(TAG_PRESET_HANDLE_REQ), presetHandle)
+    presetHandle?.let { tlvWriter.put(ContextSpecificTag(TAG_PRESET_HANDLE_REQ), presetHandle) }
     tlvWriter.endStructure()
 
     val request: InvokeRequest =
diff --git a/src/controller/python/chip/clusters/Objects.py b/src/controller/python/chip/clusters/Objects.py
index 6b8ecd1..624f42c 100644
--- a/src/controller/python/chip/clusters/Objects.py
+++ b/src/controller/python/chip/clusters/Objects.py
@@ -33168,10 +33168,10 @@
             def descriptor(cls) -> ClusterObjectDescriptor:
                 return ClusterObjectDescriptor(
                     Fields=[
-                        ClusterObjectFieldDescriptor(Label="presetHandle", Tag=0, Type=bytes),
+                        ClusterObjectFieldDescriptor(Label="presetHandle", Tag=0, Type=typing.Union[Nullable, bytes]),
                     ])
 
-            presetHandle: 'bytes' = b""
+            presetHandle: 'typing.Union[Nullable, bytes]' = NullValue
 
         @dataclass
         class AtomicResponse(ClusterCommand):
diff --git a/src/darwin/Framework/CHIP/zap-generated/MTRCommandPayloadsObjc.h b/src/darwin/Framework/CHIP/zap-generated/MTRCommandPayloadsObjc.h
index 5c86961..a5934b1 100644
--- a/src/darwin/Framework/CHIP/zap-generated/MTRCommandPayloadsObjc.h
+++ b/src/darwin/Framework/CHIP/zap-generated/MTRCommandPayloadsObjc.h
@@ -7929,7 +7929,7 @@
 MTR_PROVISIONALLY_AVAILABLE
 @interface MTRThermostatClusterSetActivePresetRequestParams : NSObject <NSCopying>
 
-@property (nonatomic, copy) NSData * _Nonnull presetHandle MTR_PROVISIONALLY_AVAILABLE;
+@property (nonatomic, copy) NSData * _Nullable presetHandle MTR_PROVISIONALLY_AVAILABLE;
 /**
  * Controls whether the command is a timed command (using Timed Invoke).
  *
diff --git a/src/darwin/Framework/CHIP/zap-generated/MTRCommandPayloadsObjc.mm b/src/darwin/Framework/CHIP/zap-generated/MTRCommandPayloadsObjc.mm
index 1334d8b..5ae9755 100644
--- a/src/darwin/Framework/CHIP/zap-generated/MTRCommandPayloadsObjc.mm
+++ b/src/darwin/Framework/CHIP/zap-generated/MTRCommandPayloadsObjc.mm
@@ -22697,7 +22697,7 @@
 {
     if (self = [super init]) {
 
-        _presetHandle = [NSData data];
+        _presetHandle = nil;
         _timedInvokeTimeoutMs = nil;
         _serverSideProcessingTimeout = nil;
     }
@@ -22730,7 +22730,12 @@
     chip::app::Clusters::Thermostat::Commands::SetActivePresetRequest::Type encodableStruct;
     ListFreer listFreer;
     {
-        encodableStruct.presetHandle = AsByteSpan(self.presetHandle);
+        if (self.presetHandle == nil) {
+            encodableStruct.presetHandle.SetNull();
+        } else {
+            auto & nonNullValue_0 = encodableStruct.presetHandle.SetNonNull();
+            nonNullValue_0 = AsByteSpan(self.presetHandle);
+        }
     }
 
     auto buffer = chip::System::PacketBufferHandle::New(chip::System::PacketBuffer::kMaxSizeWithoutReserve, 0);
diff --git a/zzz_generated/app-common/app-common/zap-generated/cluster-objects.h b/zzz_generated/app-common/app-common/zap-generated/cluster-objects.h
index e18b647..c2c1697 100644
--- a/zzz_generated/app-common/app-common/zap-generated/cluster-objects.h
+++ b/zzz_generated/app-common/app-common/zap-generated/cluster-objects.h
@@ -30149,7 +30149,7 @@
     static constexpr CommandId GetCommandId() { return Commands::SetActivePresetRequest::Id; }
     static constexpr ClusterId GetClusterId() { return Clusters::Thermostat::Id; }
 
-    chip::ByteSpan presetHandle;
+    DataModel::Nullable<chip::ByteSpan> presetHandle;
 
     CHIP_ERROR Encode(TLV::TLVWriter & aWriter, TLV::Tag aTag) const;
 
@@ -30164,7 +30164,7 @@
     static constexpr CommandId GetCommandId() { return Commands::SetActivePresetRequest::Id; }
     static constexpr ClusterId GetClusterId() { return Clusters::Thermostat::Id; }
 
-    chip::ByteSpan presetHandle;
+    DataModel::Nullable<chip::ByteSpan> presetHandle;
     CHIP_ERROR Decode(TLV::TLVReader & reader);
 };
 }; // namespace SetActivePresetRequest
diff --git a/zzz_generated/darwin-framework-tool/zap-generated/cluster/Commands.h b/zzz_generated/darwin-framework-tool/zap-generated/cluster/Commands.h
index 004bb29..dc438df 100644
--- a/zzz_generated/darwin-framework-tool/zap-generated/cluster/Commands.h
+++ b/zzz_generated/darwin-framework-tool/zap-generated/cluster/Commands.h
@@ -107995,7 +107995,11 @@
         __auto_type * params = [[MTRThermostatClusterSetActivePresetRequestParams alloc] init];
         params.timedInvokeTimeoutMs = mTimedInteractionTimeoutMs.HasValue() ? [NSNumber numberWithUnsignedShort:mTimedInteractionTimeoutMs.Value()] : nil;
 #if MTR_ENABLE_PROVISIONAL
-        params.presetHandle = [NSData dataWithBytes:mRequest.presetHandle.data() length:mRequest.presetHandle.size()];
+        if (mRequest.presetHandle.IsNull()) {
+            params.presetHandle = nil;
+        } else {
+            params.presetHandle = [NSData dataWithBytes:mRequest.presetHandle.Value().data() length:mRequest.presetHandle.Value().size()];
+        }
 #endif // MTR_ENABLE_PROVISIONAL
         uint16_t repeatCount = mRepeatCount.ValueOr(1);
         uint16_t __block responsesNeeded = repeatCount;