Skip to content

Commit ec4cd27

Browse files
committed
allow library users to get the value of characteristics themselves
so they can also generically get the value, regardless of how they decided to fulfill it, without having to also keep track themselves
1 parent 331f75b commit ec4cd27

File tree

7 files changed

+18
-7
lines changed

7 files changed

+18
-7
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -190,7 +190,7 @@ public void unsubscribe() {
190190
*
191191
* @return a future that will complete with the current value.
192192
*/
193-
protected abstract CompletableFuture<T> getValue();
193+
public abstract CompletableFuture<T> getValue();
194194

195195
/**
196196
* Supplies a default value for the characteristic to send to connected clients when the real

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ protected Boolean convert(JsonValue jsonValue) {
6060
}
6161

6262
@Override
63-
protected CompletableFuture<Boolean> getValue() {
63+
public CompletableFuture<Boolean> getValue() {
6464
return getter.isPresent() ? getter.map(booleanGetter -> booleanGetter.get()).get() : null;
6565
}
6666

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

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,8 +84,19 @@ protected Integer convert(JsonValue jsonValue) {
8484
}
8585
}
8686

87+
/**
88+
* @return the current value of this characteristic, or null if it has no value or can't be
89+
* fetched
90+
*/
91+
public CompletableFuture<T> getEnumValue() {
92+
if (!getter.isPresent()) {
93+
return null;
94+
}
95+
return getter.get().get();
96+
}
97+
8798
@Override
88-
protected CompletableFuture<Integer> getValue() {
99+
public CompletableFuture<Integer> getValue() {
89100
if (!getter.isPresent()) {
90101
return null;
91102
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ protected Double convert(JsonValue jsonValue) {
9494
* the constructor.
9595
*/
9696
@Override
97-
protected final CompletableFuture<Double> getValue() {
97+
public final CompletableFuture<Double> getValue() {
9898
if (!getter.isPresent()) {
9999
return null;
100100
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ protected CompletableFuture<JsonObjectBuilder> makeBuilder(int iid) {
7171
}
7272

7373
@Override
74-
protected CompletableFuture<Integer> getValue() {
74+
public CompletableFuture<Integer> getValue() {
7575
return getter.map(integerGetter -> integerGetter.get()).orElse(null);
7676
}
7777

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ public void setValue(String value) throws Exception {
5959

6060
/** {@inheritDoc} */
6161
@Override
62-
protected CompletableFuture<String> getValue() {
62+
public CompletableFuture<String> getValue() {
6363
return getter.map(stringGetter -> stringGetter.get()).orElse(null);
6464
}
6565

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ public void setValue(String value) throws Exception {
6868

6969
/** {@inheritDoc} */
7070
@Override
71-
protected CompletableFuture<String> getValue() {
71+
public CompletableFuture<String> getValue() {
7272
return getter.map(stringGetter -> stringGetter.get()).orElse(null);
7373
}
7474

0 commit comments

Comments
 (0)