hap-java / HAP-Java

Java implementation of the HomeKit Accessory Protocol
MIT License
155 stars 82 forks source link

improve pairing reliability with iOS 16.2 #175

Closed ccutrer closed 1 year ago

ccutrer commented 1 year ago

also keep track of admin permissions for users

note that those permissions aren't actually enforced yet

ktgeek commented 1 year ago

So, I got things working again and I think @ccutrer's change made a difference, but I'm not 100% sure.

I downloaded the PR, did a quick String username_sans_mac = username.replaceFirst(AuthInfo.getMac(), ""); and used that in place of line 53 as Cody suggested. Recompiled the HomeKit add-on and put it in place. Unfortunately, that didn't work. I decided to unpair and repair to see how that would go, but still no dice.

Not sure why I decided to do this, but I restored a offsite backup of my /var/lib/openhab/jsondb from the beginning of the month and compared the users in the two HomeKit files. I only had one user in the new file, and 4, including the one being reported in the error, in the old file.

I shutdown OpenHAB, edited the new homekit.json and added the entire stanza for the old user. I started OpenHAB back up and HomeKit worked again! I noticed in scanning the logs that another user threw that error, so I shutdown openhab to add that one, and while editing the new homekit.json I noticed the original user I transported over was no longer in the HomeKit.json, and there were now 3 other entries that didn't exist a moment ago.

My theory is that during the upgrade process the HomeKit hubs wanted to list the associations and then clear them out. Until it could successfully do that it was holding on to old pairings. This PR allows the listing to work so the process can complete, but I was in a bad state since I unpaired and few times in here. I don't know when my old pairings that caused the error disappeared, but since stuff stopped working immediately after the upgrade, maybe OpenHAB acted on some sort of clear/reset that the Hubs didn't understand/acknowledge? I am still coming up to speed on this side of stuff.

I think a good test would be someone who hasn't upgraded to get this change in place before they upgrade, then do the upgrade and see if it succeeds.

(On the issue in openhab-addons I know @yfre suggested copying just the user over and keeping the value, but I think we might be able to get people to work if they moved the full json entry over. I'm going to go over there and suggest that.)

ktgeek commented 1 year ago

I had two home hub devices (an AppleTV and a HomePod mini) unplugged while I was doing the other tinkering. When I pulled one back in, my Unknown user error came back and HomeKit broke again. I transported the user over again, and I'm working again. Same dance when I plugged the other in.

I now wonder if the HomeKit upgrade process as it happens on each hub needs to clear out the same keys, but we get confused because we've already done it? (I have 4 AppleTVs and 4 HomePod minis... I wonder if the people who are working have the simple case of only one hub?)

ccutrer commented 1 year ago

I now wonder if the HomeKit upgrade process as it happens on each hub needs to clear out the same keys, but we get confused because we've already done it? (I have 4 AppleTVs and 4 HomePod minis... I wonder if the people who are working have the simple case of only one hub?)

I have two AppleTVs.

yfre commented 1 year ago

@ccutrer is it ready for merge? Looks good for me and fixes at least the listing issue. But was not sure as it marked as draft

ccutrer commented 1 year ago

@ccutrer is it ready for merge? Looks good for me and fixes at least the listing issue. But was not sure as it marked as draft

I'm happy with the code for this now, but I'm hesitant to merge it not ever having tested it. HomeKit only did these requests the one time when I upgraded my Home on Friday. I can't in good conscious say code is ready to merge that I've never actually seen run.

I'm trying to work through a full pairing process on 16.2 (as my limited time permits), and I'm hoping by the end of that I'll have seen this work at least once. Regardless, I'll keep GitHub updated with my progress.