diff --git a/CHANGES.md b/CHANGES.md index 1977e7fb7..a3a55a290 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -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 diff --git a/src/main/java/io/github/hapjava/accessories/optionalcharacteristic/AccessoryWithRotationSpeed.java b/src/main/java/io/github/hapjava/accessories/optionalcharacteristic/AccessoryWithRotationSpeed.java index 8b00e3350..ef39947ce 100644 --- a/src/main/java/io/github/hapjava/accessories/optionalcharacteristic/AccessoryWithRotationSpeed.java +++ b/src/main/java/io/github/hapjava/accessories/optionalcharacteristic/AccessoryWithRotationSpeed.java @@ -11,7 +11,7 @@ public interface AccessoryWithRotationSpeed { * * @return a future that will contain the speed, expressed as an integer between 0 and 100. */ - CompletableFuture getRotationSpeed(); + CompletableFuture getRotationSpeed(); /** * Sets the speed of the rotation @@ -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 setRotationSpeed(Integer speed) throws Exception; + CompletableFuture setRotationSpeed(Double speed) throws Exception; /** * Subscribes to changes in the rotation speed. diff --git a/src/main/java/io/github/hapjava/characteristics/impl/fan/RotationSpeedCharacteristic.java b/src/main/java/io/github/hapjava/characteristics/impl/fan/RotationSpeedCharacteristic.java index 27c715530..d7a1d6929 100644 --- a/src/main/java/io/github/hapjava/characteristics/impl/fan/RotationSpeedCharacteristic.java +++ b/src/main/java/io/github/hapjava/characteristics/impl/fan/RotationSpeedCharacteristic.java @@ -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> getter, - ExceptionalConsumer setter, + double minValue, + double maxValue, + double minStep, + Supplier> getter, + ExceptionalConsumer setter, Consumer 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> getter, + ExceptionalConsumer setter, + Consumer subscriber, + Runnable unsubscriber) { + this( + DEFAULT_MIN_VALUE, + DEFAULT_MAX_VALUE, + DEFAULT_STEP, + getter, + setter, + subscriber, + unsubscriber); + } }