Skip to content

Commit 3299927

Browse files
Fix the commandFields type on MTRDevice invoke methods. (#35556)
The "id" was a copy/paste error. For the public API we can't do much about that, but internally we can sanity-check and use the right type.
1 parent 4a47e59 commit 3299927

File tree

3 files changed

+18
-3
lines changed

3 files changed

+18
-3
lines changed

src/darwin/Framework/CHIP/MTRDevice.mm

+16-1
Original file line numberDiff line numberDiff line change
@@ -1313,6 +1313,21 @@ - (void)invokeCommandWithEndpointID:(NSNumber *)endpointID
13131313
// here for now.
13141314
// TODO: https://github.com/project-chip/connectedhomeip/issues/24563
13151315

1316+
if (![commandFields isKindOfClass:NSDictionary.class]) {
1317+
MTR_LOG_ERROR("%@ invokeCommandWithEndpointID passed a commandFields (%@) that is not a data-value NSDictionary object",
1318+
self, commandFields);
1319+
completion(nil, [MTRError errorForCHIPErrorCode:CHIP_ERROR_INVALID_ARGUMENT]);
1320+
return;
1321+
}
1322+
1323+
MTRDeviceDataValueDictionary fieldsDataValue = commandFields;
1324+
if (fieldsDataValue[MTRTypeKey] != MTRStructureValueType) {
1325+
MTR_LOG_ERROR("%@ invokeCommandWithEndpointID passed a commandFields (%@) that is not a structure-typed data-value object",
1326+
self, commandFields);
1327+
completion(nil, [MTRError errorForCHIPErrorCode:CHIP_ERROR_INVALID_ARGUMENT]);
1328+
return;
1329+
}
1330+
13161331
[self _invokeCommandWithEndpointID:endpointID
13171332
clusterID:clusterID
13181333
commandID:commandID
@@ -1328,7 +1343,7 @@ - (void)invokeCommandWithEndpointID:(NSNumber *)endpointID
13281343
- (void)_invokeCommandWithEndpointID:(NSNumber *)endpointID
13291344
clusterID:(NSNumber *)clusterID
13301345
commandID:(NSNumber *)commandID
1331-
commandFields:(id)commandFields
1346+
commandFields:(MTRDeviceDataValueDictionary)commandFields
13321347
expectedValues:(NSArray<NSDictionary<NSString *, id> *> * _Nullable)expectedValues
13331348
expectedValueInterval:(NSNumber * _Nullable)expectedValueInterval
13341349
timedInvokeTimeout:(NSNumber * _Nullable)timeout

src/darwin/Framework/CHIP/MTRDevice_Concrete.mm

+1-1
Original file line numberDiff line numberDiff line change
@@ -2966,7 +2966,7 @@ - (void)writeAttributeWithEndpointID:(NSNumber *)endpointID
29662966
- (void)_invokeCommandWithEndpointID:(NSNumber *)endpointID
29672967
clusterID:(NSNumber *)clusterID
29682968
commandID:(NSNumber *)commandID
2969-
commandFields:(id)commandFields
2969+
commandFields:(MTRDeviceDataValueDictionary)commandFields
29702970
expectedValues:(NSArray<NSDictionary<NSString *, id> *> * _Nullable)expectedValues
29712971
expectedValueInterval:(NSNumber * _Nullable)expectedValueInterval
29722972
timedInvokeTimeout:(NSNumber * _Nullable)timeout

src/darwin/Framework/CHIP/MTRDevice_XPC.mm

+1-1
Original file line numberDiff line numberDiff line change
@@ -234,7 +234,7 @@ - (oneway void)device:(NSNumber *)nodeID internalStateUpdated:(NSDictionary *)di
234234
- (void)_invokeCommandWithEndpointID:(NSNumber *)endpointID
235235
clusterID:(NSNumber *)clusterID
236236
commandID:(NSNumber *)commandID
237-
commandFields:(id)commandFields
237+
commandFields:(MTRDeviceDataValueDictionary)commandFields
238238
expectedValues:(NSArray<NSDictionary<NSString *, id> *> * _Nullable)expectedValues
239239
expectedValueInterval:(NSNumber * _Nullable)expectedValueInterval
240240
timedInvokeTimeout:(NSNumber * _Nullable)timeout

0 commit comments

Comments
 (0)