diff --git a/CHANGES.md b/CHANGES.md index 402d3fcec..1222ce6f5 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -1,3 +1,6 @@ +# HAP-Java 2.0.6 +* Implement unpaired identify. + # HAP-Java 2.0.5 * Implement List-Pairings method. Compatibility with new Home infrastructure from iOS 16.2? diff --git a/src/main/java/io/github/hapjava/server/impl/HomekitRegistry.java b/src/main/java/io/github/hapjava/server/impl/HomekitRegistry.java index 3e3be9b6b..3850a7329 100644 --- a/src/main/java/io/github/hapjava/server/impl/HomekitRegistry.java +++ b/src/main/java/io/github/hapjava/server/impl/HomekitRegistry.java @@ -22,6 +22,7 @@ public class HomekitRegistry { private final String label; private final SubscriptionManager subscriptions; private final Map accessories; + private HomekitAccessory primaryAccessory = null; private final Map> services = new HashMap<>(); private final Map> characteristics = new HashMap<>(); @@ -78,6 +79,10 @@ public Collection getAccessories() { return accessories.values(); } + public HomekitAccessory getPrimaryAccessory() { + return primaryAccessory; + } + public Map getServices(Integer aid) { return Collections.unmodifiableMap(services.get(accessories.get(aid))); } @@ -91,10 +96,17 @@ public Map getCharacteristics(Integer aid) { } public void add(HomekitAccessory accessory) { + if (accessories.isEmpty()) { + primaryAccessory = accessory; + } accessories.put(accessory.getId(), accessory); } public boolean remove(HomekitAccessory accessory) { + HomekitAccessory localPrimaryAccessory = primaryAccessory; + if (localPrimaryAccessory != null && localPrimaryAccessory.getId() == accessory.getId()) { + primaryAccessory = null; + } return accessories.remove(accessory.getId()) != null; } diff --git a/src/main/java/io/github/hapjava/server/impl/connections/HttpSession.java b/src/main/java/io/github/hapjava/server/impl/connections/HttpSession.java index f1c97c62c..5ef2b6a3e 100644 --- a/src/main/java/io/github/hapjava/server/impl/connections/HttpSession.java +++ b/src/main/java/io/github/hapjava/server/impl/connections/HttpSession.java @@ -12,7 +12,9 @@ import io.github.hapjava.server.impl.pairing.PairSetupManager; import io.github.hapjava.server.impl.pairing.PairVerifyManager; import io.github.hapjava.server.impl.pairing.PairingsManager; +import io.github.hapjava.server.impl.responses.BadRequestResponse; import io.github.hapjava.server.impl.responses.InternalServerErrorResponse; +import io.github.hapjava.server.impl.responses.NoContentResponse; import io.github.hapjava.server.impl.responses.NotFoundResponse; import java.io.IOException; import java.net.InetAddress; @@ -49,6 +51,13 @@ public HttpSession( public HttpResponse handleRequest(HttpRequest request) throws IOException { switch (request.getUri()) { + case "/identify": + HomekitAccessory accessory = registry.getPrimaryAccessory(); + if (accessory != null) { + accessory.identify(); + } + return new NoContentResponse(); + case "/pair-setup": return handlePairSetup(request); @@ -83,6 +92,9 @@ public HttpResponse handleAuthenticatedRequest(HttpRequest request) throws IOExc return new NotFoundResponse(); } + case "/identify": + return new BadRequestResponse(); + case "/pairings": return new PairingsManager(authInfo, advertiser).handle(request); diff --git a/src/main/java/io/github/hapjava/server/impl/responses/BadRequestResponse.java b/src/main/java/io/github/hapjava/server/impl/responses/BadRequestResponse.java new file mode 100644 index 000000000..1b5818f30 --- /dev/null +++ b/src/main/java/io/github/hapjava/server/impl/responses/BadRequestResponse.java @@ -0,0 +1,11 @@ +package io.github.hapjava.server.impl.responses; + +import io.github.hapjava.server.impl.http.HttpResponse; + +public class BadRequestResponse implements HttpResponse { + + @Override + public int getStatusCode() { + return 400; + } +} diff --git a/src/main/java/io/github/hapjava/server/impl/responses/NoContentResponse.java b/src/main/java/io/github/hapjava/server/impl/responses/NoContentResponse.java new file mode 100644 index 000000000..e851f95c9 --- /dev/null +++ b/src/main/java/io/github/hapjava/server/impl/responses/NoContentResponse.java @@ -0,0 +1,11 @@ +package io.github.hapjava.server.impl.responses; + +import io.github.hapjava.server.impl.http.HttpResponse; + +public class NoContentResponse implements HttpResponse { + + @Override + public int getStatusCode() { + return 204; + } +}