From 7a64a1b5d7c35f6976fea6dd6caefb4095967d5d Mon Sep 17 00:00:00 2001 From: Eugen Freiter Date: Sat, 29 Jan 2022 19:20:01 +0100 Subject: [PATCH 1/3] fix rotation speed data type Signed-off-by: Eugen Freiter --- .../AccessoryWithRotationSpeed.java | 4 +-- .../impl/fan/RotationSpeedCharacteristic.java | 34 +++++++++++++++---- 2 files changed, 30 insertions(+), 8 deletions(-) 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..6d61c78cc 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 = 25; 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); + } } From 792099dc3e34c409eca51e397a768cb4921de518 Mon Sep 17 00:00:00 2001 From: Eugen Freiter Date: Sat, 29 Jan 2022 19:22:53 +0100 Subject: [PATCH 2/3] fix rotation speed data type Signed-off-by: Eugen Freiter --- .../characteristics/impl/fan/RotationSpeedCharacteristic.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 6d61c78cc..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 @@ -14,7 +14,7 @@ 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 = 25; + public static final double DEFAULT_STEP = 1; public RotationSpeedCharacteristic( double minValue, From 80c636714dc1cc70ff91102e7f56ee4a87f073a0 Mon Sep 17 00:00:00 2001 From: Eugen Freiter Date: Sat, 29 Jan 2022 19:26:26 +0100 Subject: [PATCH 3/3] update change.md Signed-off-by: Eugen Freiter --- CHANGES.md | 1 + 1 file changed, 1 insertion(+) 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