Skip to content

Commit

Permalink
Addressing more review comments.
Browse files Browse the repository at this point in the history
  • Loading branch information
bzbarsky-apple committed Sep 30, 2023
1 parent 90fff86 commit 2ebe6ef
Show file tree
Hide file tree
Showing 8 changed files with 15,927 additions and 4,637 deletions.
13 changes: 11 additions & 2 deletions src/darwin/Framework/CHIP/MTRDevice.mm
Original file line number Diff line number Diff line change
Expand Up @@ -999,14 +999,20 @@ static BOOL AttributeHasChangesOmittedQuality(MTRAttributePath * attributePath)
- (nullable id)readAttributeWithEndpointID:(NSNumber *)endpointID
clusterID:(NSNumber *)clusterID
attributeID:(NSNumber *)attributeID
params:(MTRReadParams * _Nullable)params
error:(NSError * __autoreleasing *)error
{
if (error) {
*error = nil;
}

NSDictionary<NSString *, id> * value = [self readAttributeWithEndpointID:endpointID
clusterID:clusterID
attributeID:attributeID
params:params];
params:nil];
if (value == nil) {
if (error) {
*error = [NSError errorWithDomain:MTRErrorDomain code:MTRErrorCodeAttributeValueUnavailable userInfo:nil];
}
return nil;
}

Expand All @@ -1021,6 +1027,9 @@ - (nullable id)readAttributeWithEndpointID:(NSNumber *)endpointID
return nil;
}

// Because our responseValue has MTRDataKey, we either errored out (and got nil for
// the report) or report.value is the (possibly nil) correct value for the
// attribute.
return report.value;
}

Expand Down
1 change: 0 additions & 1 deletion src/darwin/Framework/CHIP/MTRDevice_Internal.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,6 @@ typedef void (^MTRDevicePerformAsyncBlock)(MTRBaseDevice * baseDevice);
- (nullable id)readAttributeWithEndpointID:(NSNumber *)endpointID
clusterID:(NSNumber *)clusterID
attributeID:(NSNumber *)attributeID
params:(MTRReadParams * _Nullable)params
error:(NSError * __autoreleasing *)error;

@property (nonatomic, readonly) MTRDeviceController * deviceController;
Expand Down
6 changes: 6 additions & 0 deletions src/darwin/Framework/CHIP/MTRError.h
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,12 @@ typedef NS_ERROR_ENUM(MTRErrorDomain, MTRErrorCode){
* TLV-level failures.
*/
MTRErrorCodeTLVDecodeFailed MTR_AVAILABLE(ios(17.0), macos(14.0), watchos(10.0), tvos(17.0)) = 14,
/**
* MTRErrorCodeAttributeValueUnavailable means the value for an attribute is
* not available. This could be because the attribute is not supported, or
* because we have not yet received the value from the server.
*/
MTRErrorCodeAttributeValueUnavailable MTR_NEWLY_AVAILABLE = 15,
};
// clang-format on

Expand Down
4 changes: 2 additions & 2 deletions src/darwin/Framework/CHIP/templates/MTRClusters-src.zapt
Original file line number Diff line number Diff line change
Expand Up @@ -177,9 +177,9 @@ completionHandler
return [self.device readAttributeWithEndpointID:@(self.endpoint) clusterID:@(MTRClusterIDType{{>cluster}}ID) attributeID:@(MTRAttributeIDTypeCluster{{>cluster}}{{>attribute}}ID) params:params];
}

- ({{asObjectiveCClass type parent.name stronglyTypedArrays=true}} * _Nullable)read{{>attribute}}WithParams:(MTRReadParams * _Nullable)params error:(NSError * __autoreleasing *)error
- ({{asObjectiveCClass type parent.name stronglyTypedArrays=true}} * _Nullable){{asMethodName name}}:(NSError * __autoreleasing *)error
{
return [self.device readAttributeWithEndpointID:@(self.endpoint) clusterID:@(MTRClusterIDType{{>cluster}}ID) attributeID:@(MTRAttributeIDTypeCluster{{>cluster}}{{>attribute}}ID) params:params error:error];
return [self.device readAttributeWithEndpointID:@(self.endpoint) clusterID:@(MTRClusterIDType{{>cluster}}ID) attributeID:@(MTRAttributeIDTypeCluster{{>cluster}}{{>attribute}}ID) error:error];
}

{{#if isWritableAttribute}}
Expand Down
13 changes: 12 additions & 1 deletion src/darwin/Framework/CHIP/templates/MTRClusters.zapt
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,18 @@ NS_ASSUME_NONNULL_BEGIN
{{availability (asUpperCamelCase parent.name preserveAcronyms=true) attribute=(asUpperCamelCase name preserveAcronyms=true)}}
{{/inline}}
- (NSDictionary<NSString *, id> *)read{{>attribute}}WithParams:(MTRReadParams * _Nullable)params {{> availability}};
- ({{asObjectiveCClass type parent.name stronglyTypedArrays=true}} * _Nullable)read{{>attribute}}WithParams:(MTRReadParams * _Nullable)params error:(NSError * __autoreleasing *)error {{availability (asUpperCamelCase parent.name preserveAcronyms=true) attribute=(asUpperCamelCase name preserveAcronyms=true) minimalRelease="Future"}};

/**
{{#if isNullable}}
* {{asMethodName name}} can return nil and set *error to nil. This indicates that the value of the attribute is available and is null.
*
{{/if}}
* If the attribute value is not available, an MTRErrorCodeAttributeValueUnavailable error will be returned.
*
* If the attribute value canot be decoded to `{{#if isNullable}}nullable {{/if}}{{asObjectiveCClass type parent.name stronglyTypedArrays=true}} *`,
* an MTRErrorCodeSchemaMismatch error will be returned.
*/
- ({{asObjectiveCClass type parent.name stronglyTypedArrays=true}} * _Nullable){{asMethodName name}}:(NSError * __autoreleasing *)error {{availability (asUpperCamelCase parent.name preserveAcronyms=true) attribute=(asUpperCamelCase name preserveAcronyms=true) minimalRelease="Future"}}{{#if isNullable}} __attribute__((swift_error(nonnull_error))){{/if}};
{{#if isWritableAttribute}}
- (void)write{{>attribute}}WithValue:(NSDictionary<NSString *, id> *)dataValueDictionary expectedValueInterval:(NSNumber *)expectedValueIntervalMs {{> availability}};
- (void)write{{>attribute}}WithValue:(NSDictionary<NSString *, id> *)dataValueDictionary expectedValueInterval:(NSNumber *)expectedValueIntervalMs params:(MTRWriteParams * _Nullable)params {{> availability}};
Expand Down
Loading

0 comments on commit 2ebe6ef

Please sign in to comment.