Skip to content

Commit 915efec

Browse files
authored
Merge pull request #156 from yfre/fix_rotation_speed_type
Fix rotation speed type
2 parents e5935c7 + 80c6367 commit 915efec

File tree

3 files changed

+31
-8
lines changed

3 files changed

+31
-8
lines changed

CHANGES.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
# HAP-Java 2.0.1
22
## Fixes
33
* Log accessory names instead of futures. [#150](https://github.com/hap-java/HAP-Java/issues/150)
4+
* Fix rotation speed data type (BREAKING API CHANGE). According to HAP specification it must be float
45

56
# HAP-Java 2.0.0
67
* major refactoring to support optional characteristics

src/main/java/io/github/hapjava/accessories/optionalcharacteristic/AccessoryWithRotationSpeed.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ public interface AccessoryWithRotationSpeed {
1111
*
1212
* @return a future that will contain the speed, expressed as an integer between 0 and 100.
1313
*/
14-
CompletableFuture<Integer> getRotationSpeed();
14+
CompletableFuture<Double> getRotationSpeed();
1515

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

2525
/**
2626
* Subscribes to changes in the rotation speed.

src/main/java/io/github/hapjava/characteristics/impl/fan/RotationSpeedCharacteristic.java

Lines changed: 28 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,30 +3,52 @@
33
import io.github.hapjava.characteristics.EventableCharacteristic;
44
import io.github.hapjava.characteristics.ExceptionalConsumer;
55
import io.github.hapjava.characteristics.HomekitCharacteristicChangeCallback;
6-
import io.github.hapjava.characteristics.impl.base.IntegerCharacteristic;
6+
import io.github.hapjava.characteristics.impl.base.FloatCharacteristic;
77
import java.util.Optional;
88
import java.util.concurrent.CompletableFuture;
99
import java.util.function.Consumer;
1010
import java.util.function.Supplier;
1111

1212
/** This characteristic describes the rotation speed of a fan. */
13-
public class RotationSpeedCharacteristic extends IntegerCharacteristic
13+
public class RotationSpeedCharacteristic extends FloatCharacteristic
1414
implements EventableCharacteristic {
15+
public static final double DEFAULT_MIN_VALUE = 0;
16+
public static final double DEFAULT_MAX_VALUE = 100;
17+
public static final double DEFAULT_STEP = 1;
1518

1619
public RotationSpeedCharacteristic(
17-
Supplier<CompletableFuture<Integer>> getter,
18-
ExceptionalConsumer<Integer> setter,
20+
double minValue,
21+
double maxValue,
22+
double minStep,
23+
Supplier<CompletableFuture<Double>> getter,
24+
ExceptionalConsumer<Double> setter,
1925
Consumer<HomekitCharacteristicChangeCallback> subscriber,
2026
Runnable unsubscriber) {
2127
super(
2228
"00000029-0000-1000-8000-0026BB765291",
2329
"Rotation Speed",
24-
0,
25-
100,
30+
minValue,
31+
maxValue,
32+
minStep,
2633
"%",
2734
Optional.of(getter),
2835
Optional.of(setter),
2936
Optional.of(subscriber),
3037
Optional.of(unsubscriber));
3138
}
39+
40+
public RotationSpeedCharacteristic(
41+
Supplier<CompletableFuture<Double>> getter,
42+
ExceptionalConsumer<Double> setter,
43+
Consumer<HomekitCharacteristicChangeCallback> subscriber,
44+
Runnable unsubscriber) {
45+
this(
46+
DEFAULT_MIN_VALUE,
47+
DEFAULT_MAX_VALUE,
48+
DEFAULT_STEP,
49+
getter,
50+
setter,
51+
subscriber,
52+
unsubscriber);
53+
}
3254
}

0 commit comments

Comments
 (0)