Skip to content

Commit

Permalink
Add countryCode to MTRCommissioningParameters. (#27080)
Browse files Browse the repository at this point in the history
This lets commissioners control what the Location of a device is set to at
commissioning time.
  • Loading branch information
bzbarsky-apple authored and pull[bot] committed Sep 15, 2023
1 parent 109c6f3 commit 1170128
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 3 deletions.
8 changes: 8 additions & 0 deletions src/darwin/Framework/CHIP/MTRCommissioningParameters.h
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,14 @@ NS_ASSUME_NONNULL_BEGIN
*/
@property (nonatomic, assign) BOOL skipCommissioningComplete MTR_NEWLY_AVAILABLE;

/**
* The country code to provide to the device during commissioning.
*
* If not nil, this must be a 2-character ISO 3166-1 country code, which the
* device can use to decide on things like radio communications bands.
*/
@property (nonatomic, copy, nullable) NSString * countryCode MTR_NEWLY_AVAILABLE;

@end

@interface MTRCommissioningParameters (Deprecated)
Expand Down
4 changes: 4 additions & 0 deletions src/darwin/Framework/CHIP/MTRDeviceController.mm
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
#import "MTRPersistentStorageDelegateBridge.h"
#import "MTRSetupPayload.h"
#import "NSDataSpanConversion.h"
#import "NSStringSpanConversion.h"
#import <setup_payload/ManualSetupPayloadGenerator.h>
#import <setup_payload/SetupPayload.h>
#import <zap-generated/MTRBaseClusters.h>
Expand Down Expand Up @@ -492,6 +493,9 @@ - (BOOL)commissionNodeWithID:(NSNumber *)nodeID
self, commissioningParams.deviceAttestationDelegate, timeoutSecs, shouldWaitAfterDeviceAttestation);
params.SetDeviceAttestationDelegate(self->_deviceAttestationDelegateBridge);
}
if (commissioningParams.countryCode != nil) {
params.SetCountryCode(AsCharSpan(commissioningParams.countryCode));
}

chip::NodeId deviceId = [nodeID unsignedLongLongValue];
self->_operationalCredentialsDelegate->SetDeviceID(deviceId);
Expand Down
26 changes: 23 additions & 3 deletions src/darwin/Framework/CHIPTests/MTRDeviceTests.m
Original file line number Diff line number Diff line change
Expand Up @@ -96,10 +96,11 @@ - (void)controller:(MTRDeviceController *)controller commissioningSessionEstabli
{
XCTAssertEqual(error.code, 0);

__auto_type * params = [[MTRCommissioningParameters alloc] init];
params.countryCode = @("au");

NSError * commissionError = nil;
[sController commissionNodeWithID:@(kDeviceId)
commissioningParams:[[MTRCommissioningParameters alloc] init]
error:&commissionError];
[sController commissionNodeWithID:@(kDeviceId) commissioningParams:params error:&commissionError];
XCTAssertNil(commissionError);

// Keep waiting for controller:commissioningComplete:
Expand Down Expand Up @@ -2350,6 +2351,25 @@ - (void)test025_SubscribeMultipleEvents
[self waitForExpectations:@[ startupEventExpectation, expectation ] timeout:kTimeoutInSeconds];
}

- (void)test026_LocationAttribute
{
__auto_type * device = GetConnectedDevice();
dispatch_queue_t queue = dispatch_get_main_queue();

XCTestExpectation * expectation = [self expectationWithDescription:@"read Basic Information Location attribute"];

__auto_type * cluster = [[MTRBaseClusterBasicInformation alloc] initWithDevice:device endpointID:@(0) queue:queue];
[cluster readAttributeLocationWithCompletion:^(NSString * _Nullable value, NSError * _Nullable error) {
XCTAssertNil(error);

// Matches what we passed in during commissioning.
XCTAssertEqualObjects(value, @"au");
[expectation fulfill];
}];

[self waitForExpectations:@[ expectation ] timeout:kTimeoutInSeconds];
}

- (void)test900_SubscribeAllAttributes
{
MTRBaseDevice * device = GetConnectedDevice();
Expand Down

0 comments on commit 1170128

Please sign in to comment.