@@ -917,26 +917,21 @@ - (void)readAttributePaths:(NSArray<MTRAttributeRequestPath *> * _Nullable)attri
917
917
completion : (MTRDeviceResponseHandler)completion
918
918
{
919
919
if ((attributePaths == nil || [attributePaths count ] == 0 ) && (eventPaths == nil || [eventPaths count ] == 0 )) {
920
+ // No paths, just return an empty array.
920
921
dispatch_async (queue, ^{
921
- completion (nil , [MTRError errorForCHIPErrorCode: CHIP_ERROR_INVALID_ARGUMENT] );
922
+ completion (@[], nil );
922
923
});
923
924
return ;
924
925
}
925
926
926
- NSMutableArray <MTRAttributeRequestPath *> * attributes = nil ;
927
+ NSArray <MTRAttributeRequestPath *> * attributes = nil ;
927
928
if (attributePaths != nil ) {
928
- attributes = [[NSMutableArray alloc ] init ];
929
- for (MTRAttributeRequestPath * attributePath in attributePaths) {
930
- [attributes addObject: [attributePath copy ]];
931
- }
929
+ attributes = [[NSArray alloc ] initWithArray: attributePaths copyItems: YES ];
932
930
}
933
931
934
- NSMutableArray <MTREventRequestPath *> * events = nil ;
932
+ NSArray <MTREventRequestPath *> * events = nil ;
935
933
if (eventPaths != nil ) {
936
- events = [[NSMutableArray alloc ] init ];
937
- for (MTRAttributeRequestPath * eventPath in eventPaths) {
938
- [events addObject: [eventPath copy ]];
939
- }
934
+ events = [[NSArray alloc ] initWithArray: eventPaths copyItems: YES ];
940
935
}
941
936
params = (params == nil ) ? nil : [params copy ];
942
937
auto * bridge = new MTRDataValueDictionaryCallbackBridge (queue, completion,
@@ -1006,9 +1001,9 @@ - (void)readAttributePaths:(NSArray<MTRAttributeRequestPath *> * _Nullable)attri
1006
1001
chip::app::ReadPrepareParams readParams (session);
1007
1002
[params toReadPrepareParams: readParams];
1008
1003
readParams.mpAttributePathParamsList = attributePathParamsList.Get ();
1009
- readParams.mAttributePathParamsListSize = [attributePaths count ];
1004
+ readParams.mAttributePathParamsListSize = [attributes count ];
1010
1005
readParams.mpEventPathParamsList = eventPathParamsList.Get ();
1011
- readParams.mEventPathParamsListSize = [eventPaths count ];
1006
+ readParams.mEventPathParamsListSize = [events count ];
1012
1007
1013
1008
AttributePathParams * attributePathParamsListToFree = attributePathParamsList.Get ();
1014
1009
EventPathParams * eventPathParamsListToFree = eventPathParamsList.Get ();
@@ -1288,8 +1283,10 @@ - (void)subscribeToAttributePaths:(NSArray<MTRAttributeRequestPath *> * _Nullabl
1288
1283
resubscriptionScheduled : (MTRDeviceResubscriptionScheduledHandler _Nullable)resubscriptionScheduled
1289
1284
{
1290
1285
if ((attributePaths == nil || [attributePaths count ] == 0 ) && (eventPaths == nil || [eventPaths count ] == 0 )) {
1286
+ // Per spec a server would respond InvalidAction to this, so just go
1287
+ // ahead and do that.
1291
1288
dispatch_async (queue, ^{
1292
- reportHandler (nil , [MTRError errorForCHIPErrorCode: CHIP_ERROR_INVALID_ARGUMENT ]);
1289
+ reportHandler (nil , [MTRError errorForIMStatus: StatusIB ( Status: :InvalidAction) ]);
1293
1290
});
1294
1291
return ;
1295
1292
}
@@ -1303,20 +1300,14 @@ - (void)subscribeToAttributePaths:(NSArray<MTRAttributeRequestPath *> * _Nullabl
1303
1300
}
1304
1301
1305
1302
// Copy params before going async.
1306
- NSMutableArray <MTRAttributeRequestPath *> * attributes = nil ;
1303
+ NSArray <MTRAttributeRequestPath *> * attributes = nil ;
1307
1304
if (attributePaths != nil ) {
1308
- attributes = [[NSMutableArray alloc ] init ];
1309
- for (MTRAttributeRequestPath * attributePath in attributePaths) {
1310
- [attributes addObject: [attributePath copy ]];
1311
- }
1305
+ attributes = [[NSArray alloc ] initWithArray: attributePaths copyItems: YES ];
1312
1306
}
1313
1307
1314
- NSMutableArray <MTREventRequestPath *> * events = nil ;
1308
+ NSArray <MTREventRequestPath *> * events = nil ;
1315
1309
if (eventPaths != nil ) {
1316
- events = [[NSMutableArray alloc ] init ];
1317
- for (MTRAttributeRequestPath * eventPath in eventPaths) {
1318
- [events addObject: [eventPath copy ]];
1319
- }
1310
+ events = [[NSArray alloc ] initWithArray: eventPaths copyItems: YES ];
1320
1311
}
1321
1312
1322
1313
params = (params == nil ) ? nil : [params copy ];
0 commit comments