diff --git a/src/darwin/Framework/CHIP/MTRCommissioningParameters.h b/src/darwin/Framework/CHIP/MTRCommissioningParameters.h index c16aaf692de1bb..f1cce0e53e6699 100644 --- a/src/darwin/Framework/CHIP/MTRCommissioningParameters.h +++ b/src/darwin/Framework/CHIP/MTRCommissioningParameters.h @@ -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) diff --git a/src/darwin/Framework/CHIP/MTRDeviceController.mm b/src/darwin/Framework/CHIP/MTRDeviceController.mm index e6388e083cd3fa..2f01e499ad55db 100644 --- a/src/darwin/Framework/CHIP/MTRDeviceController.mm +++ b/src/darwin/Framework/CHIP/MTRDeviceController.mm @@ -31,6 +31,7 @@ #import "MTRPersistentStorageDelegateBridge.h" #import "MTRSetupPayload.h" #import "NSDataSpanConversion.h" +#import "NSStringSpanConversion.h" #import #import #import @@ -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); diff --git a/src/darwin/Framework/CHIPTests/MTRDeviceTests.m b/src/darwin/Framework/CHIPTests/MTRDeviceTests.m index 07999e06cafeef..eb334429336849 100644 --- a/src/darwin/Framework/CHIPTests/MTRDeviceTests.m +++ b/src/darwin/Framework/CHIPTests/MTRDeviceTests.m @@ -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: @@ -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();