Skip to content

Commit b402771

Browse files
committed
allow setting values directly via characteristics
1 parent ec4cd27 commit b402771

File tree

5 files changed

+14
-6
lines changed

5 files changed

+14
-6
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
@@ -183,7 +183,7 @@ public void unsubscribe() {
183183
* @param value the new value to set.
184184
* @throws Exception if the value cannot be set.
185185
*/
186-
protected abstract void setValue(T value) throws Exception;
186+
public abstract void setValue(T value) throws Exception;
187187

188188
/**
189189
* Retrieves the current value of the characteristic.

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
@@ -65,7 +65,7 @@ public CompletableFuture<Boolean> getValue() {
6565
}
6666

6767
@Override
68-
protected void setValue(Boolean value) throws Exception {
68+
public void setValue(Boolean value) throws Exception {
6969
if (setter.isPresent()) setter.get().accept(value);
7070
}
7171

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

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -103,8 +103,16 @@ public CompletableFuture<Integer> getValue() {
103103
return getter.get().get().thenApply(T::getCode);
104104
}
105105

106+
public void setValue(T value) throws Exception {
107+
if (!setter.isPresent()) {
108+
return;
109+
}
110+
111+
setter.get().accept(value);
112+
}
113+
106114
@Override
107-
protected void setValue(Integer value) throws Exception {
115+
public void setValue(Integer value) throws Exception {
108116
if (!setter.isPresent()) {
109117
return;
110118
}
@@ -113,7 +121,7 @@ protected void setValue(Integer value) throws Exception {
113121
if (validValues != null && value != null) {
114122
for (T valid : validValues) {
115123
if (valid.getCode() == value) {
116-
setter.get().accept(valid);
124+
setValue(valid);
117125
return;
118126
}
119127
}

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
@@ -129,7 +129,7 @@ public final CompletableFuture<Double> getValue() {
129129
}
130130

131131
@Override
132-
protected void setValue(Double value) throws Exception {
132+
public void setValue(Double value) throws Exception {
133133
if (setter.isPresent()) setter.get().accept(value);
134134
}
135135

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
@@ -76,7 +76,7 @@ public CompletableFuture<Integer> getValue() {
7676
}
7777

7878
@Override
79-
protected void setValue(Integer value) throws Exception {
79+
public void setValue(Integer value) throws Exception {
8080
if (setter.isPresent()) setter.get().accept(value);
8181
}
8282

0 commit comments

Comments
 (0)