From 2f176066f61bbe817f1ae38f8ff0de5c4bdbb2e8 Mon Sep 17 00:00:00 2001 From: Jeff Tung <100387939+jtung-apple@users.noreply.github.com> Date: Thu, 28 Mar 2024 15:27:15 -0700 Subject: [PATCH] [Darwin] Fix for API changes and address post-merge comments for #32765 (#32778) --- src/darwin/Framework/CHIP/MTRBaseDevice.h | 5 +---- src/darwin/Framework/CHIP/MTRDevice.mm | 6 +++++- src/darwin/Framework/CHIP/MTRDevice_Internal.h | 2 ++ 3 files changed, 8 insertions(+), 5 deletions(-) diff --git a/src/darwin/Framework/CHIP/MTRBaseDevice.h b/src/darwin/Framework/CHIP/MTRBaseDevice.h index fe1592a45fc7b2..5eb00475dfdd8d 100644 --- a/src/darwin/Framework/CHIP/MTRBaseDevice.h +++ b/src/darwin/Framework/CHIP/MTRBaseDevice.h @@ -26,9 +26,6 @@ NS_ASSUME_NONNULL_BEGIN -typedef NSDictionary * MTRDeviceResponseValueDictionary; -typedef NSDictionary * MTRDeviceDataValueDictionary; - /** * Handler for read attribute response, write attribute response, invoke command response and reports. * @@ -99,7 +96,7 @@ typedef NSDictionary * MTRDeviceDataValueDictionary; * * MTRDataKey : Data-value NSDictionary object. */ -typedef void (^MTRDeviceResponseHandler)(NSArray * _Nullable values, NSError * _Nullable error); +typedef void (^MTRDeviceResponseHandler)(NSArray *> * _Nullable values, NSError * _Nullable error); /** * Handler for -subscribeWithQueue: attribute and event reports diff --git a/src/darwin/Framework/CHIP/MTRDevice.mm b/src/darwin/Framework/CHIP/MTRDevice.mm index 9640a4a533005b..730a4024b4bc9b 100644 --- a/src/darwin/Framework/CHIP/MTRDevice.mm +++ b/src/darwin/Framework/CHIP/MTRDevice.mm @@ -188,6 +188,7 @@ - (NSString *)description return [NSString stringWithFormat:@"", _dataVersion, static_cast(_attributes.count)]; } +// Attributes dictionary is: attributeID => data-value dictionary - (nullable instancetype)initWithDataVersion:(NSNumber * _Nullable)dataVersion attributes:(NSDictionary * _Nullable)attributes { self = [super init]; @@ -884,7 +885,10 @@ - (void)_handleReportBegin NSMutableDictionary * clusterDataToReturn = [NSMutableDictionary dictionary]; for (MTRClusterPath * clusterPath in clusterPaths) { NSNumber * dataVersion = _clusterData[clusterPath].dataVersion; - NSDictionary * attributes = [self _attributesForCluster:clusterPath]; + NSDictionary * attributes = nil; +#if MTRDEVICE_ATTRIBUTE_CACHE_STORE_ATTRIBUTES_BY_CLUSTER + attributes = [self _attributesForCluster:clusterPath]; +#endif if (dataVersion || attributes) { MTRDeviceClusterData * clusterData = [[MTRDeviceClusterData alloc] initWithDataVersion:dataVersion attributes:attributes]; clusterDataToReturn[clusterPath] = clusterData; diff --git a/src/darwin/Framework/CHIP/MTRDevice_Internal.h b/src/darwin/Framework/CHIP/MTRDevice_Internal.h index 5d82847f4cbd00..1444e602bd5247 100644 --- a/src/darwin/Framework/CHIP/MTRDevice_Internal.h +++ b/src/darwin/Framework/CHIP/MTRDevice_Internal.h @@ -26,6 +26,8 @@ NS_ASSUME_NONNULL_BEGIN @class MTRAsyncWorkQueue; +typedef NSDictionary * MTRDeviceDataValueDictionary; + typedef void (^MTRDevicePerformAsyncBlock)(MTRBaseDevice * baseDevice); // Whether to store attributes by cluster instead of as individual entries for each attribute