Skip to content
Merged
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
1 change: 1 addition & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# HAP-Java 2.0.1
## Fixes
* Log accessory names instead of futures. [#150](https://github.com/hap-java/HAP-Java/issues/150)
* Fix rotation speed data type (BREAKING API CHANGE). According to HAP specification it must be float

# HAP-Java 2.0.0
* major refactoring to support optional characteristics
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ public interface AccessoryWithRotationSpeed {
*
* @return a future that will contain the speed, expressed as an integer between 0 and 100.
*/
CompletableFuture<Integer> getRotationSpeed();
CompletableFuture<Double> getRotationSpeed();

/**
* Sets the speed of the rotation
Expand All @@ -20,7 +20,7 @@ public interface AccessoryWithRotationSpeed {
* @return a future that completes when the change is made
* @throws Exception when the change cannot be made
*/
CompletableFuture<Void> setRotationSpeed(Integer speed) throws Exception;
CompletableFuture<Void> setRotationSpeed(Double speed) throws Exception;

/**
* Subscribes to changes in the rotation speed.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,30 +3,52 @@
import io.github.hapjava.characteristics.EventableCharacteristic;
import io.github.hapjava.characteristics.ExceptionalConsumer;
import io.github.hapjava.characteristics.HomekitCharacteristicChangeCallback;
import io.github.hapjava.characteristics.impl.base.IntegerCharacteristic;
import io.github.hapjava.characteristics.impl.base.FloatCharacteristic;
import java.util.Optional;
import java.util.concurrent.CompletableFuture;
import java.util.function.Consumer;
import java.util.function.Supplier;

/** This characteristic describes the rotation speed of a fan. */
public class RotationSpeedCharacteristic extends IntegerCharacteristic
public class RotationSpeedCharacteristic extends FloatCharacteristic
implements EventableCharacteristic {
public static final double DEFAULT_MIN_VALUE = 0;
public static final double DEFAULT_MAX_VALUE = 100;
public static final double DEFAULT_STEP = 1;

public RotationSpeedCharacteristic(
Supplier<CompletableFuture<Integer>> getter,
ExceptionalConsumer<Integer> setter,
double minValue,
double maxValue,
double minStep,
Supplier<CompletableFuture<Double>> getter,
ExceptionalConsumer<Double> setter,
Consumer<HomekitCharacteristicChangeCallback> subscriber,
Runnable unsubscriber) {
super(
"00000029-0000-1000-8000-0026BB765291",
"Rotation Speed",
0,
100,
minValue,
maxValue,
minStep,
"%",
Optional.of(getter),
Optional.of(setter),
Optional.of(subscriber),
Optional.of(unsubscriber));
}

public RotationSpeedCharacteristic(
Supplier<CompletableFuture<Double>> getter,
ExceptionalConsumer<Double> setter,
Consumer<HomekitCharacteristicChangeCallback> subscriber,
Runnable unsubscriber) {
this(
DEFAULT_MIN_VALUE,
DEFAULT_MAX_VALUE,
DEFAULT_STEP,
getter,
setter,
subscriber,
unsubscriber);
}
}