Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

support un-paired identify request #179

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
@@ -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?

Expand Down
12 changes: 12 additions & 0 deletions src/main/java/io/github/hapjava/server/impl/HomekitRegistry.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ public class HomekitRegistry {
private final String label;
private final SubscriptionManager subscriptions;
private final Map<Integer, HomekitAccessory> accessories;
private HomekitAccessory primaryAccessory = null;
private final Map<HomekitAccessory, Map<Integer, Service>> services = new HashMap<>();
private final Map<HomekitAccessory, Map<Integer, Characteristic>> characteristics =
new HashMap<>();
Expand Down Expand Up @@ -78,6 +79,10 @@ public Collection<HomekitAccessory> getAccessories() {
return accessories.values();
}

public HomekitAccessory getPrimaryAccessory() {
return primaryAccessory;
}

public Map<Integer, Service> getServices(Integer aid) {
return Collections.unmodifiableMap(services.get(accessories.get(aid)));
}
Expand All @@ -91,10 +96,17 @@ public Map<Integer, Characteristic> 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;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);

Expand Down Expand Up @@ -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);

Expand Down
Original file line number Diff line number Diff line change
@@ -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;
}
}
Original file line number Diff line number Diff line change
@@ -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;
}
}