Skip to content

Commit 8bac5bb

Browse files
authored
Merge pull request #182 from ccutrer/programmable-switch-event
improve ProgrammableSwitchEvent
2 parents 7dfc8c4 + 77db50c commit 8bac5bb

File tree

4 files changed

+26
-4
lines changed

4 files changed

+26
-4
lines changed

CHANGES.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
# HAP-Java 2.0.6
2+
* Several methods allowing library users to manipulate characteristics themselves
3+
* Allow library users to provider their own implementation of AccessoryInformationService
4+
* Fix ProgrammableSwitchEventEnum that has an incorrect value
5+
16
# HAP-Java 2.0.5
27
* Implement List-Pairings method. Compatibility with new Home infrastructure from iOS 16.2?
38

src/main/java/io/github/hapjava/characteristics/impl/base/EnumCharacteristic.java

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ public abstract class EnumCharacteristic<T extends CharacteristicEnum>
2626
extends BaseCharacteristic<Integer> {
2727

2828
private final T[] validValues;
29-
Optional<Supplier<CompletableFuture<T>>> getter;
29+
protected Optional<Supplier<CompletableFuture<T>>> getter;
3030
protected Optional<ExceptionalConsumer<T>> setter;
3131

3232
/**
@@ -100,7 +100,16 @@ public CompletableFuture<Integer> getValue() {
100100
if (!getter.isPresent()) {
101101
return null;
102102
}
103-
return getter.get().get().thenApply(T::getCode);
103+
return getter
104+
.get()
105+
.get()
106+
.thenApply(
107+
e -> {
108+
if (e == null) {
109+
return null;
110+
}
111+
return e.getCode();
112+
});
104113
}
105114

106115
public void setValue(T value) throws Exception {

src/main/java/io/github/hapjava/characteristics/impl/common/ProgrammableSwitchEnum.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
public enum ProgrammableSwitchEnum implements CharacteristicEnum {
1010
SINGLE_PRESS(0),
1111
DOUBLE_PRESS(1),
12-
LONG_PRESS(3);
12+
LONG_PRESS(2);
1313

1414
private static final Map<Integer, ProgrammableSwitchEnum> reverse;
1515

src/main/java/io/github/hapjava/characteristics/impl/common/ProgrammableSwitchEventCharacteristic.java

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,18 @@ public ProgrammableSwitchEventCharacteristic(
2121
Supplier<CompletableFuture<ProgrammableSwitchEnum>> getter,
2222
Consumer<HomekitCharacteristicChangeCallback> subscriber,
2323
Runnable unsubscriber) {
24+
this(ProgrammableSwitchEnum.values(), getter, subscriber, unsubscriber);
25+
}
26+
27+
public ProgrammableSwitchEventCharacteristic(
28+
ProgrammableSwitchEnum[] validValues,
29+
Supplier<CompletableFuture<ProgrammableSwitchEnum>> getter,
30+
Consumer<HomekitCharacteristicChangeCallback> subscriber,
31+
Runnable unsubscriber) {
2432
super(
2533
"00000073-0000-1000-8000-0026BB765291",
2634
"Switch Event",
27-
ProgrammableSwitchEnum.values(),
35+
validValues,
2836
Optional.of(getter),
2937
Optional.empty(),
3038
Optional.of(subscriber),

0 commit comments

Comments
 (0)