Skip to content

Commit

Permalink
Merge pull request #3 from hap-java/master
Browse files Browse the repository at this point in the history
merge with upstream
  • Loading branch information
yfre authored Oct 18, 2019
2 parents d2b2f4f + 58d068a commit b099f56
Show file tree
Hide file tree
Showing 7 changed files with 51 additions and 21 deletions.
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
language: java
jdk: oraclejdk8
jdk: openjdk8
after_success:
- openssl aes-256-cbc -pass pass:$ENCRYPTION_PASSWORD -in deploy/pubring.gpg.enc -out
deploy/pubring.gpg -d
Expand Down
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@
<plugin>
<groupId>com.coveo</groupId>
<artifactId>fmt-maven-plugin</artifactId>
<version>2.6.0</version>
<version>2.9</version>
<executions>
<execution>
<goals>
Expand Down
20 changes: 20 additions & 0 deletions src/main/java/io/github/hapjava/accessories/TemperatureSensor.java
Original file line number Diff line number Diff line change
Expand Up @@ -60,4 +60,24 @@ default Collection<Service> getServices() {
default TemperatureUnit getTemperatureUnit() {
return TemperatureUnit.CELSIUS;
}

/**
* set default temperature unit of the thermostat. this is the unit thermostat use to display
* temprature. the homekit interface uses celsius.
*
* @param unit the temperature unit of the thermostat.
*/
default void setTemperatureUnit(TemperatureUnit unit) {
// override depending on the thermostat if required.
}

/**
* subscribe to unit changes.
*
* @param callback callback
*/
default void subscribeTemperatureUnit(final HomekitCharacteristicChangeCallback callback) {}

/** unsubscribe from unit changes. */
default void unsubscribeTemperatureUnit() {}
}
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
@@ -1,25 +1,40 @@
package io.github.hapjava.impl.characteristics.thermostat;

import io.github.hapjava.HomekitCharacteristicChangeCallback;
import io.github.hapjava.accessories.properties.TemperatureUnit;
import io.github.hapjava.accessories.thermostat.BasicThermostat;
import io.github.hapjava.characteristics.EnumCharacteristic;
import io.github.hapjava.characteristics.EventableCharacteristic;
import java.util.concurrent.CompletableFuture;

public class TemperatureUnitsCharacteristic extends EnumCharacteristic {
public class TemperatureUnitsCharacteristic extends EnumCharacteristic
implements EventableCharacteristic {

private final BasicThermostat thermostat;

public TemperatureUnitsCharacteristic(BasicThermostat thermostat) {
super("00000036-0000-1000-8000-0026BB765291", false, true, "The temperature unit", 1);
super("00000036-0000-1000-8000-0026BB765291", true, true, "The temperature unit", 1);
this.thermostat = thermostat;
}

@Override
protected void setValue(Integer value) throws Exception {
// Not writable
thermostat.setTemperatureUnit(
value == 1 ? TemperatureUnit.FAHRENHEIT : TemperatureUnit.CELSIUS);
}

@Override
protected CompletableFuture<Integer> getValue() {
return CompletableFuture.completedFuture(thermostat.getTemperatureUnit().getCode());
}

@Override
public void subscribe(final HomekitCharacteristicChangeCallback callback) {
thermostat.subscribeTemperatureUnit(callback);
}

@Override
public void unsubscribe() {
thermostat.unsubscribeTemperatureUnit();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -49,11 +49,6 @@ public synchronized void addSubscription(
LOGGER.info(
"Added subscription to " + characteristic.getClass() + " for " + connection.hashCode());
}
try {
connection.outOfBand(new EventController().getMessage(aid, iid, characteristic));
} catch (Exception e) {
LOGGER.error("Could not send initial state in response to subscribe event", e);
}
}

public synchronized void removeSubscription(
Expand Down

0 comments on commit b099f56

Please sign in to comment.