EDIT: I get the following error codes:
Error adding accessory The operation couldn’t be completed. (HMErrorDomain error 2.)
And:
Error adding accessory Failed to start pairing with the accessory [ name = xxxxx, providedName = xxxxx, uuid = xxxxx-xxxxx-xxxxx-xxxxx-xxxxx, identifier = xxxxx, configuration-app-id = (null), home = (null), bridge = (null) ]
Both with number 2.
What I don't understand is why on the HMCatalog app this works. What's wrong with my code? It works fine on the Accessory simulator but not on the real accessory (the real accessory is added only via the HMCatalog app but not my custom app).
Actual Behaviour:
- add accessory from my app (works the first time)
- reset accessory and then re-add it (does not work and gives pairing error in screenshot below). However when it does give those errors if I use the Apple example HMCatalog it does work.
And sometimes:
Expected results:
- adds accessory from my app too without pairing error
This is my add accessory code:
[self.home addAccessory:self.accessory completionHandler:^(NSError *error) {
NSLog(@"in adding for accessory %@", self.accessory.name);
if (error) {
NSLog(@"Error adding accessory %@ %li", error.localizedDescription, (long)error.code);
UIAlertController *alertController = [UIAlertController
alertControllerWithTitle:@"Pairing error"
message:error.localizedDescription
preferredStyle:UIAlertControllerStyleAlert];
UIAlertAction *okAction = [UIAlertAction
actionWithTitle:NSLocalizedString(@"OK", @"OK action")
style:UIAlertActionStyleDefault
handler:^(UIAlertAction *action)
{
NSLog(@"OK action");
}];
[alertController addAction:okAction];
[self presentViewController:alertController animated:YES completion:nil];
}
else{
// TODO: Tweak this
NSLog(@"Added to home");
[self dismiss:nil];
/**
[homeSweetHome assignAccessory:accessory toRoom:nil completionHandler:^(NSError *error) {
if (error) {
NSLog(@"Failed adding accessory %@ to room %@", accessory.name, room.name);
}
}];**/
}
}];