hap-java / HAP-Java

Java implementation of the HomeKit Accessory Protocol
MIT License
152 stars 83 forks source link

Multi-device support #181

Closed alparr closed 1 year ago

alparr commented 1 year ago

Hello,

I have an issue that I can't get this library to work with multiple devices. E.g. if I'm pairing with my phone, the devices are showing up on my iPad and on my watch, but it tells me that there is no response from them. (If I'm pairing with my iPad then they only work on the iPad). Am I doing something wrong? Or is this use-case not supported?

Maybe it is also worth mentioning that I'm not using a hub. Would it be different if I would also use a hub?

IMG_0153 IMG_0154

yfre commented 1 year ago

multiple paired devices are supported. i have around 8 in my home :) but you need to implement management of users see. HomekitAuthInfo.createUser/listUsers/.. , which holds the key for each device (called users here the class). so, if you have multiple devices you need to have multiple users managed / stored somewhere

alparr commented 1 year ago

@yfre Could you elaborate on this a little bit more, or provide some code example? I'm basically using the code from the sample application, MockAuthInfo:createUser is already storing multiple users if it receives them, but it is only called once when I'm doing the initial pairing. So what else do I have to do for it to work also on the other devices?

yfre commented 1 year ago

checked MockAuthInfo and it looks good and should work with multiple devices (i have not tested though). another implementation is in openHAB (but pretty openHAB specific) https://github.com/openhab/openhab-addons/blob/main/bundles/org.openhab.io.homekit/src/main/java/org/openhab/io/homekit/internal/HomekitAuthInfoImpl.java

probably, the best approach would be to add more logging to MockAuthInfo to see which users are created and which are requested.

alparr commented 1 year ago

createUser is only called once, when I'm doing the pairing. getUserPublicKey is also called with different usernames occasionally, but it is returning null because it only has the public key for the initially paired device.

I also tried to start the bridge with allowUnauthenticatedRequests set to true (I don't know if this has anything to do with my issue), but it is still not working.

alparr commented 1 year ago

Can it be related to the new HomeKit architecture? https://community.openhab.org/t/homekit-ios-16-2-issues-dont-upgrade/142069

I guess I upgraded my app to 16.2 because I don't have the option in the settings. Seems like it is already fixed in OpenHAB. https://github.com/openhab/openhab-addons/issues/13949

UPDATE: Sorry, I haven't seen the release 2.0.5 (it is not showing up under Releases on the projects github page). It is working now on my iPad and Mac, but it is still not working on my watch.

yfre commented 1 year ago

ok. so, it was related to new homekit architecture. good that it is working with new release. regarding watch - we have no influence on the watch, it gets the data from the iphone. so, we need to wait for apple to fix (hopefully) the new architecture and see how it will behave