Skip to content

#93 Fix discoverability & pairing with ios13 #94

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

Closed
wants to merge 13 commits into from
2 changes: 1 addition & 1 deletion src/main/java/io/github/hapjava/HomekitRoot.java
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ public void allowUnauthenticatedRequests(boolean allow) {

/**
* By default, the bridge advertises itself at revision 1. If you make changes to the accessories
* you're including in the bridge after your first call to {@link start()}, you should increment
* you're including in the bridge after your first call to {@link #start()}, you should increment
* this number. The behavior of the client if the configuration index were to decrement is
* undefined, so this implementation will not manage the configuration index by automatically
* incrementing - preserving this state across invocations should be handled externally.
Expand Down
4 changes: 4 additions & 0 deletions src/main/java/io/github/hapjava/Service.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,4 +29,8 @@ public interface Service {
* ########-####-####-####-############.
*/
String getType();

List<Service> getLinkedServices();

void addLinkedService(Service service);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
package io.github.hapjava.accessories;

import io.github.hapjava.HomekitAccessory;
import io.github.hapjava.HomekitCharacteristicChangeCallback;
import io.github.hapjava.Service;
import io.github.hapjava.accessories.properties.CarbonDioxideDetectedState;
import io.github.hapjava.impl.services.CarbonDioxideSensorService;
import java.util.Collection;
import java.util.Collections;
import java.util.concurrent.CompletableFuture;

/**
* A carbon dioxide sensor reports whether carbon dioxide has been detected or not.
*
* <p>Carbon dioxide sensors that run on batteries will need to implement this interface and also
* implement {@link BatteryStatusAccessory}.
*
* @author Eugen Freiter
*/
public interface CarbonDioxideSensor extends HomekitAccessory {

/**
* Retrieves the state of the sensor that indicates if carbon dioxide has been detected.
*
* @return a future that will contain the carbon dioxide sensor's state
*/
CompletableFuture<CarbonDioxideDetectedState> getCarbonDioxideDetectedState();

@Override
default Collection<Service> getServices() {
return Collections.singleton(new CarbonDioxideSensorService(this));
}

/**
* Subscribes to changes in the carbon dioxide's state.
*
* @param callback the function to call when the state changes.
*/
void subscribeCarbonDioxideDetectedState(HomekitCharacteristicChangeCallback callback);

/**
* Retrieves the carbon dioxide level
*
* @return a future that will contain the carbon dioxide level as a value between 0 and 100000
*/
CompletableFuture<Double> getCarbonDioxideLevel();

/** Unsubscribes from changes in the carbon dioxide's state. */
void unsubscribeCarbonDioxideDetectedState();

/**
* Subscribes to changes in the carbon dioxide level.
*
* @param callback the function to call when the state changes.
*/
void subscribeCarbonDioxideLevel(HomekitCharacteristicChangeCallback callback);

/** Unsubscribes from changes in the carbon dioxide level. */
void unsubscribeCarbonDioxideLevel();
}
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ public interface ValveWithTimer extends Valve {
* <p>If the valve is currently running, then Homekit assumes that changing this value affects the
* current remaining duration.
*
* @param value duration
* @return a future with the value
*/
CompletableFuture<Void> setSetDuration(int value);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
package io.github.hapjava.accessories.properties;

import java.util.Arrays;
import java.util.Map;
import java.util.stream.Collectors;

public enum CarbonDioxideDetectedState {
NORMAL(0),
ABNORMAL(1);

private static final Map<Integer, CarbonDioxideDetectedState> reverse;

static {
reverse =
Arrays.stream(CarbonDioxideDetectedState.values())
.collect(Collectors.toMap(CarbonDioxideDetectedState::getCode, t -> t));
}

public static CarbonDioxideDetectedState fromCode(Integer code) {
return reverse.get(code);
}

private final int code;

CarbonDioxideDetectedState(int code) {
this.code = code;
}

public int getCode() {
return code;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
package io.github.hapjava.impl.characteristics.carbondioxide;

import io.github.hapjava.HomekitCharacteristicChangeCallback;
import io.github.hapjava.accessories.CarbonDioxideSensor;
import io.github.hapjava.accessories.properties.CarbonDioxideDetectedState;
import io.github.hapjava.characteristics.EnumCharacteristic;
import io.github.hapjava.characteristics.EventableCharacteristic;
import java.util.concurrent.CompletableFuture;

public class CarbonDioxideDetectedCharacteristic extends EnumCharacteristic
implements EventableCharacteristic {

private final CarbonDioxideSensor carbonDioxideSensor;

public CarbonDioxideDetectedCharacteristic(CarbonDioxideSensor carbonDioxideSensor) {
super("00000092-0000-1000-8000-0026BB765291", false, true, "Carbon Dioxide Detected", 1);
this.carbonDioxideSensor = carbonDioxideSensor;
}

@Override
protected CompletableFuture<Integer> getValue() {
return carbonDioxideSensor
.getCarbonDioxideDetectedState()
.thenApply(CarbonDioxideDetectedState::getCode);
}

@Override
protected void setValue(Integer value) throws Exception {
// Read Only
}

@Override
public void subscribe(HomekitCharacteristicChangeCallback callback) {
carbonDioxideSensor.subscribeCarbonDioxideDetectedState(callback);
}

@Override
public void unsubscribe() {
carbonDioxideSensor.unsubscribeCarbonDioxideDetectedState();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
package io.github.hapjava.impl.characteristics.carbondioxide;

import io.github.hapjava.HomekitCharacteristicChangeCallback;
import io.github.hapjava.accessories.CarbonDioxideSensor;
import io.github.hapjava.characteristics.EventableCharacteristic;
import io.github.hapjava.characteristics.FloatCharacteristic;
import java.util.concurrent.CompletableFuture;

public class CarbonDioxideLevelCharacteristic extends FloatCharacteristic
implements EventableCharacteristic {

private final CarbonDioxideSensor sensor;

public CarbonDioxideLevelCharacteristic(CarbonDioxideSensor sensor) {
super(
"00000093-0000-1000-8000-0026BB765291",
false,
true,
"Carbon Dioxide level",
0,
100000,
0.1,
"%");
this.sensor = sensor;
}

@Override
public void subscribe(HomekitCharacteristicChangeCallback callback) {
sensor.subscribeCarbonDioxideLevel(callback);
}

@Override
public void unsubscribe() {
sensor.unsubscribeCarbonDioxideLevel();
}

@Override
protected void setValue(Double value) throws Exception {
// Read Only
}

@Override
protected CompletableFuture<Double> getDoubleValue() {
return sensor.getCarbonDioxideLevel();
}

@Override
public String toString() {
return "CarbonDioxideLevelCharacteristic{"
+ "sensor level ="
+ sensor.getCarbonDioxideLevel()
+ '}';
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

import io.github.hapjava.HomekitCharacteristicChangeCallback;
import io.github.hapjava.accessories.GarageDoor;
import io.github.hapjava.accessories.properties.DoorState;
import io.github.hapjava.characteristics.EnumCharacteristic;
import io.github.hapjava.characteristics.EventableCharacteristic;
import java.util.concurrent.CompletableFuture;
Expand All @@ -13,27 +12,27 @@ public class CurrentDoorStateCharacteristic extends EnumCharacteristic
private final GarageDoor door;

public CurrentDoorStateCharacteristic(GarageDoor door) {
super("00000032-0000-1000-8000-0026BB765291", true, true, "Target Door State", 1);
super("0000000E-0000-1000-8000-0026BB765291", false, true, "Current Door State", 4);
this.door = door;
}

@Override
protected void setValue(Integer value) throws Exception {
door.setTargetDoorState(DoorState.fromCode(value));
// Read Only
}

@Override
protected CompletableFuture<Integer> getValue() {
return door.getTargetDoorState().thenApply(s -> s.getCode());
return door.getCurrentDoorState().thenApply(s -> s.getCode());
}

@Override
public void subscribe(HomekitCharacteristicChangeCallback callback) {
door.subscribeTargetDoorState(callback);
door.subscribeCurrentDoorState(callback);
}

@Override
public void unsubscribe() {
door.unsubscribeTargetDoorState();
door.unsubscribeCurrentDoorState();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import io.github.hapjava.HomekitCharacteristicChangeCallback;
import io.github.hapjava.accessories.GarageDoor;
import io.github.hapjava.accessories.properties.DoorState;
import io.github.hapjava.characteristics.EnumCharacteristic;
import io.github.hapjava.characteristics.EventableCharacteristic;
import java.util.concurrent.CompletableFuture;
Expand All @@ -12,27 +13,27 @@ public class TargetDoorStateCharacteristic extends EnumCharacteristic
private final GarageDoor door;

public TargetDoorStateCharacteristic(GarageDoor door) {
super("0000000E-0000-1000-8000-0026BB765291", false, true, "Current Door State", 4);
super("00000032-0000-1000-8000-0026BB765291", true, true, "Target Door State", 1);
this.door = door;
}

@Override
protected void setValue(Integer value) throws Exception {
// Read Only
door.setTargetDoorState(DoorState.fromCode(value));
}

@Override
protected CompletableFuture<Integer> getValue() {
return door.getCurrentDoorState().thenApply(s -> s.getCode());
return door.getTargetDoorState().thenApply(s -> s.getCode());
}

@Override
public void subscribe(HomekitCharacteristicChangeCallback callback) {
door.subscribeCurrentDoorState(callback);
door.subscribeTargetDoorState(callback);
}

@Override
public void unsubscribe() {
door.unsubscribeCurrentDoorState();
door.unsubscribeTargetDoorState();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ private HttpResponse handlePairSetup(HttpRequest request) {
if (pairingManager == null) {
synchronized (HttpSession.class) {
if (pairingManager == null) {
pairingManager = new PairingManager(authInfo, registry, advertiser);
pairingManager = new PairingManager(authInfo, registry);
}
}
}
Expand Down

This file was deleted.

Loading