Skip to content

Commit

Permalink
Fix the commandFields type on MTRDevice invoke methods. (project-chip…
Browse files Browse the repository at this point in the history
…#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.
  • Loading branch information
bzbarsky-apple authored Sep 12, 2024
1 parent 4a47e59 commit 3299927
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 3 deletions.
17 changes: 16 additions & 1 deletion src/darwin/Framework/CHIP/MTRDevice.mm
Original file line number Diff line number Diff line change
Expand Up @@ -1313,6 +1313,21 @@ - (void)invokeCommandWithEndpointID:(NSNumber *)endpointID
// here for now.
// TODO: https://github.com/project-chip/connectedhomeip/issues/24563

if (![commandFields isKindOfClass:NSDictionary.class]) {
MTR_LOG_ERROR("%@ invokeCommandWithEndpointID passed a commandFields (%@) that is not a data-value NSDictionary object",
self, commandFields);
completion(nil, [MTRError errorForCHIPErrorCode:CHIP_ERROR_INVALID_ARGUMENT]);
return;
}

MTRDeviceDataValueDictionary fieldsDataValue = commandFields;
if (fieldsDataValue[MTRTypeKey] != MTRStructureValueType) {
MTR_LOG_ERROR("%@ invokeCommandWithEndpointID passed a commandFields (%@) that is not a structure-typed data-value object",
self, commandFields);
completion(nil, [MTRError errorForCHIPErrorCode:CHIP_ERROR_INVALID_ARGUMENT]);
return;
}

[self _invokeCommandWithEndpointID:endpointID
clusterID:clusterID
commandID:commandID
Expand All @@ -1328,7 +1343,7 @@ - (void)invokeCommandWithEndpointID:(NSNumber *)endpointID
- (void)_invokeCommandWithEndpointID:(NSNumber *)endpointID
clusterID:(NSNumber *)clusterID
commandID:(NSNumber *)commandID
commandFields:(id)commandFields
commandFields:(MTRDeviceDataValueDictionary)commandFields
expectedValues:(NSArray<NSDictionary<NSString *, id> *> * _Nullable)expectedValues
expectedValueInterval:(NSNumber * _Nullable)expectedValueInterval
timedInvokeTimeout:(NSNumber * _Nullable)timeout
Expand Down
2 changes: 1 addition & 1 deletion src/darwin/Framework/CHIP/MTRDevice_Concrete.mm
Original file line number Diff line number Diff line change
Expand Up @@ -2966,7 +2966,7 @@ - (void)writeAttributeWithEndpointID:(NSNumber *)endpointID
- (void)_invokeCommandWithEndpointID:(NSNumber *)endpointID
clusterID:(NSNumber *)clusterID
commandID:(NSNumber *)commandID
commandFields:(id)commandFields
commandFields:(MTRDeviceDataValueDictionary)commandFields
expectedValues:(NSArray<NSDictionary<NSString *, id> *> * _Nullable)expectedValues
expectedValueInterval:(NSNumber * _Nullable)expectedValueInterval
timedInvokeTimeout:(NSNumber * _Nullable)timeout
Expand Down
2 changes: 1 addition & 1 deletion src/darwin/Framework/CHIP/MTRDevice_XPC.mm
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,7 @@ - (oneway void)device:(NSNumber *)nodeID internalStateUpdated:(NSDictionary *)di
- (void)_invokeCommandWithEndpointID:(NSNumber *)endpointID
clusterID:(NSNumber *)clusterID
commandID:(NSNumber *)commandID
commandFields:(id)commandFields
commandFields:(MTRDeviceDataValueDictionary)commandFields
expectedValues:(NSArray<NSDictionary<NSString *, id> *> * _Nullable)expectedValues
expectedValueInterval:(NSNumber * _Nullable)expectedValueInterval
timedInvokeTimeout:(NSNumber * _Nullable)timeout
Expand Down

0 comments on commit 3299927

Please sign in to comment.