Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -183,14 +183,14 @@ public void unsubscribe() {
* @param value the new value to set.
* @throws Exception if the value cannot be set.
*/
protected abstract void setValue(T value) throws Exception;
public abstract void setValue(T value) throws Exception;

/**
* Retrieves the current value of the characteristic.
*
* @return a future that will complete with the current value.
*/
protected abstract CompletableFuture<T> getValue();
public abstract CompletableFuture<T> getValue();

/**
* Supplies a default value for the characteristic to send to connected clients when the real
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,12 +60,12 @@ protected Boolean convert(JsonValue jsonValue) {
}

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

@Override
protected void setValue(Boolean value) throws Exception {
public void setValue(Boolean value) throws Exception {
if (setter.isPresent()) setter.get().accept(value);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,16 +84,35 @@ protected Integer convert(JsonValue jsonValue) {
}
}

/**
* @return the current value of this characteristic, or null if it has no value or can't be
* fetched
*/
public CompletableFuture<T> getEnumValue() {
if (!getter.isPresent()) {
return null;
}
return getter.get().get();
}

@Override
protected CompletableFuture<Integer> getValue() {
public CompletableFuture<Integer> getValue() {
if (!getter.isPresent()) {
return null;
}
return getter.get().get().thenApply(T::getCode);
}

public void setValue(T value) throws Exception {
if (!setter.isPresent()) {
return;
}

setter.get().accept(value);
}

@Override
protected void setValue(Integer value) throws Exception {
public void setValue(Integer value) throws Exception {
if (!setter.isPresent()) {
return;
}
Expand All @@ -102,7 +121,7 @@ protected void setValue(Integer value) throws Exception {
if (validValues != null && value != null) {
for (T valid : validValues) {
if (valid.getCode() == value) {
setter.get().accept(valid);
setValue(valid);
return;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ protected Double convert(JsonValue jsonValue) {
* the constructor.
*/
@Override
protected final CompletableFuture<Double> getValue() {
public final CompletableFuture<Double> getValue() {
if (!getter.isPresent()) {
return null;
}
Expand Down Expand Up @@ -129,7 +129,7 @@ protected final CompletableFuture<Double> getValue() {
}

@Override
protected void setValue(Double value) throws Exception {
public void setValue(Double value) throws Exception {
if (setter.isPresent()) setter.get().accept(value);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,12 +71,12 @@ protected CompletableFuture<JsonObjectBuilder> makeBuilder(int iid) {
}

@Override
protected CompletableFuture<Integer> getValue() {
public CompletableFuture<Integer> getValue() {
return getter.map(integerGetter -> integerGetter.get()).orElse(null);
}

@Override
protected void setValue(Integer value) throws Exception {
public void setValue(Integer value) throws Exception {
if (setter.isPresent()) setter.get().accept(value);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ public void setValue(String value) throws Exception {

/** {@inheritDoc} */
@Override
protected CompletableFuture<String> getValue() {
public CompletableFuture<String> getValue() {
return getter.map(stringGetter -> stringGetter.get()).orElse(null);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ public void setValue(String value) throws Exception {

/** {@inheritDoc} */
@Override
protected CompletableFuture<String> getValue() {
public CompletableFuture<String> getValue() {
return getter.map(stringGetter -> stringGetter.get()).orElse(null);
}

Expand Down