Skip to content

Commit

Permalink
Add strongly typed APIs for reading via MTRCluster* instances.
Browse files Browse the repository at this point in the history
  • Loading branch information
bzbarsky-apple committed Sep 22, 2023
1 parent c1ca759 commit adaad99
Show file tree
Hide file tree
Showing 7 changed files with 19,176 additions and 161 deletions.
25 changes: 25 additions & 0 deletions src/darwin/Framework/CHIP/MTRDevice.mm
Original file line number Diff line number Diff line change
Expand Up @@ -978,6 +978,31 @@ static BOOL AttributeHasChangesOmittedQuality(MTRAttributePath * attributePath)
return attributeValueToReturn;
}

- (nullable id)readAttributeWithEndpointID:(NSNumber *)endpointID
clusterID:(NSNumber *)clusterID
attributeID:(NSNumber *)attributeID
params:(MTRReadParams * _Nullable)params
error:(NSError * __autoreleasing *)error
{
NSDictionary<NSString *, id> * value = [self readAttributeWithEndpointID:endpointID
clusterID:clusterID
attributeID:attributeID
params:params];
if (value == nil) {
return nil;
}

auto * path = [MTRAttributePath attributePathWithEndpointID:endpointID clusterID:clusterID attributeID:attributeID];

auto * report = [[MTRAttributeReport alloc] initWithResponseValue:@{
MTRAttributePathKey : path,
MTRDataKey : value,
}
error:error];

return report.value;
}

- (void)writeAttributeWithEndpointID:(NSNumber *)endpointID
clusterID:(NSNumber *)clusterID
attributeID:(NSNumber *)attributeID
Expand Down
7 changes: 7 additions & 0 deletions src/darwin/Framework/CHIP/MTRDevice_Internal.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,13 @@ typedef void (^MTRDevicePerformAsyncBlock)(MTRBaseDevice * baseDevice);
// false-positives, for example due to compressed fabric id collisions.
- (void)nodeMayBeAdvertisingOperational;

// Helper to read strongly typed values, for use from MTRCluster.
- (nullable id)readAttributeWithEndpointID:(NSNumber *)endpointID
clusterID:(NSNumber *)clusterID
attributeID:(NSNumber *)attributeID
params:(MTRReadParams * _Nullable)params
error:(NSError * __autoreleasing *)error;

@property (nonatomic, readonly) MTRDeviceController * deviceController;
@property (nonatomic, readonly, copy) NSNumber * nodeID;
// Queue used for various internal bookkeeping work. In general endWork calls
Expand Down
5 changes: 5 additions & 0 deletions src/darwin/Framework/CHIP/templates/MTRClusters-src.zapt
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,11 @@ 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
{
return [self.device readAttributeWithEndpointID:@(self.endpoint) clusterID:@(MTRClusterIDType{{>cluster}}ID) attributeID:@(MTRAttributeIDTypeCluster{{>cluster}}{{>attribute}}ID) params:params error:error];
}

{{#if isWritableAttribute}}
{{#*inline "callbackName"}}DefaultSuccess{{/inline}}
- (void)write{{>attribute}}WithValue:(NSDictionary<NSString *, id> *)dataValueDictionary expectedValueInterval:(NSNumber *)expectedValueIntervalMs
Expand Down
1 change: 1 addition & 0 deletions src/darwin/Framework/CHIP/templates/MTRClusters.zapt
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ 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 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 adaad99

Please sign in to comment.