Skip to content

Commit

Permalink
RemoveAllFabrics logic + UI support in iOS chiptool
Browse files Browse the repository at this point in the history
  • Loading branch information
shana-apple committed May 6, 2021
1 parent d41a80a commit 1067543
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -273,3 +273,12 @@ bool emberAfOperationalCredentialsClusterUpdateFabricLabelCallback(chip::app::Co
emberAfSendImmediateDefaultResponse(status);
return true;
}

// Up for discussion in Multi-Admin TT: chip-spec:#2891
bool emberAfOperationalCredentialsClusterRemoveAllFabricsCallback(chip::app::Command * commandObj)
{
emberAfPrintln(EMBER_AF_PRINT_DEBUG, "OpCreds: Remove all Fabrics");
emberAfSendImmediateDefaultResponse(EMBER_ZCL_STATUS_SUCCESS);
OpenDefaultPairingWindow(ResetAdmins::kYes);
return true;
}
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,24 @@ - (void)setupUIElements

removeFabricView.translatesAutoresizingMaskIntoConstraints = false;
[removeFabricView.trailingAnchor constraintEqualToAnchor:_stackView.trailingAnchor].active = YES;

// Remove All Fabrics

UIButton * removeAllFabricsButton = [UIButton new];
removeAllFabricsButton.titleLabel.font = [UIFont systemFontOfSize:17];
removeAllFabricsButton.titleLabel.textColor = [UIColor blackColor];
removeAllFabricsButton.layer.cornerRadius = 5;
removeAllFabricsButton.clipsToBounds = YES;
removeAllFabricsButton.backgroundColor = UIColor.systemBlueColor;
[removeAllFabricsButton setTitle:@"Remove All Fabrics" forState:UIControlStateNormal];
[removeAllFabricsButton addTarget:self
action:@selector(removeAllFabricsButtonPressed:)
forControlEvents:UIControlEventTouchUpInside];
[_stackView addArrangedSubview:removeAllFabricsButton];

removeAllFabricsButton.translatesAutoresizingMaskIntoConstraints = false;
[removeAllFabricsButton.trailingAnchor constraintEqualToAnchor:_stackView.trailingAnchor].active = YES;
[removeAllFabricsButton.leadingAnchor constraintEqualToAnchor:_stackView.leadingAnchor].active = YES;

// Get Fabrics List

Expand Down Expand Up @@ -223,6 +241,35 @@ - (void)fetchFabricsList

// MARK: UIButton methods

- (IBAction)removeAllFabricsButtonPressed:(id)sender
{
NSLog(@"Request to Remove All Fabrics.");
UIAlertController* alert = [UIAlertController alertControllerWithTitle:@"Remove All Fabrics?"
message:@"Are you sure you want to remove all fabrics, this will remove all fabrics on accessory, including this one, and put the device back in commissioning."
preferredStyle:UIAlertControllerStyleAlert];

UIAlertAction* defaultAction = [UIAlertAction actionWithTitle:@"Remove" style:UIAlertActionStyleDefault
handler:^(UIAlertAction * action) {
[self.cluster removeAllFabrics:^(NSError * error, NSDictionary * values) {
BOOL errorOccured = (error != nil);
NSString * resultString = errorOccured ? [NSString stringWithFormat:@"An error occured: 0x%02lx", error.code]
: @"Remove all fabrics success";
dispatch_async(dispatch_get_main_queue(), ^{
[self updateResult:resultString isError:errorOccured];
});
}];
}];

UIAlertAction* cancelAction = [UIAlertAction actionWithTitle:@"Cancel" style:UIAlertActionStyleCancel
handler:^(UIAlertAction * action) {}];

[alert addAction:cancelAction];
[alert addAction:defaultAction];

[self presentViewController:alert animated:YES completion:nil];
}


- (IBAction)updateFabricLabelButtonPressed:(id)sender
{
NSString * label = _updateFabricLabelTextField.text;
Expand Down

0 comments on commit 1067543

Please sign in to comment.