@@ -325,7 +325,7 @@ using namespace chip::python;
325325namespace {
326326// Helper function to process write attributes data - reduces code duplication
327327CHIP_ERROR ProcessWriteAttributesData (WriteClient * client, python::PyWriteAttributeData * writeAttributesData,
328- size_t attributeDataLength)
328+ size_t attributeDataLength, bool forceLegacyListEncoding = false )
329329{
330330 CHIP_ERROR err = CHIP_NO_ERROR;
331331
@@ -346,9 +346,19 @@ CHIP_ERROR ProcessWriteAttributesData(WriteClient * client, python::PyWriteAttri
346346 dataVersion.SetValue (path.dataVersion );
347347 }
348348
349- SuccessOrExit (
350- err = client->PutPreencodedAttribute (
351- chip::app::ConcreteDataAttributePath (path.endpointId , path.clusterId , path.attributeId , dataVersion), reader));
349+ if (forceLegacyListEncoding)
350+ {
351+ auto listEncodingOverride = WriteClient::TestListEncodingOverride::kForceLegacyEncoding ;
352+ SuccessOrExit (err = client->PutPreencodedAttribute (
353+ chip::app::ConcreteDataAttributePath (path.endpointId , path.clusterId , path.attributeId , dataVersion),
354+ reader, listEncodingOverride));
355+ }
356+ else
357+ {
358+ SuccessOrExit (
359+ err = client->PutPreencodedAttribute (
360+ chip::app::ConcreteDataAttributePath (path.endpointId , path.clusterId , path.attributeId , dataVersion), reader));
361+ }
352362 }
353363
354364exit:
@@ -402,37 +412,7 @@ PyChipError pychip_WriteClient_WriteAttributes(void * appContext, DeviceProxy *
402412
403413 VerifyOrExit (device != nullptr && device->GetSecureSession ().HasValue (), err = CHIP_ERROR_MISSING_SECURE_SESSION);
404414
405- // Handle legacy list encoding override if needed
406- if (forceLegacyListEncoding)
407- {
408- for (size_t i = 0 ; i < attributeDataLength; i++)
409- {
410- python::PyAttributePath path = writeAttributesData[i].attributePath ;
411- void * tlv = writeAttributesData[i].tlvData ;
412- size_t length = writeAttributesData[i].tlvLength ;
413-
414- uint8_t * tlvBuffer = reinterpret_cast <uint8_t *>(tlv);
415-
416- TLV::TLVReader reader;
417- reader.Init (tlvBuffer, static_cast <uint32_t >(length));
418- reader.Next ();
419- Optional<DataVersion> dataVersion;
420- if (path.hasDataVersion == 1 )
421- {
422- dataVersion.SetValue (path.dataVersion );
423- }
424-
425- auto listEncodingOverride = WriteClient::TestListEncodingOverride::kForceLegacyEncoding ;
426-
427- SuccessOrExit (err = client->PutPreencodedAttribute (
428- chip::app::ConcreteDataAttributePath (path.endpointId , path.clusterId , path.attributeId , dataVersion),
429- reader, listEncodingOverride));
430- }
431- }
432- else
433- {
434- SuccessOrExit (err = ProcessWriteAttributesData (client.get (), writeAttributesData, attributeDataLength));
435- }
415+ SuccessOrExit (err = ProcessWriteAttributesData (client.get (), writeAttributesData, attributeDataLength, forceLegacyListEncoding));
436416
437417 SuccessOrExit (err = client->SendWriteRequest (device->GetSecureSession ().Value (),
438418 interactionTimeoutMs != 0 ? System::Clock::Milliseconds32 (interactionTimeoutMs)
0 commit comments