Skip to content

Commit 68a4d63

Browse files
author
Andy Lintner
committed
Fix for new Homekit restriction on write-only characteristics not
exposing a value.
1 parent b3a4abb commit 68a4d63

File tree

2 files changed

+13
-1
lines changed

2 files changed

+13
-1
lines changed

src/main/java/com/beowulfe/hap/characteristics/BaseCharacteristic.java

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,13 @@ public void supplyValue(JsonObjectBuilder builder) {
151151
*/
152152
protected abstract T getDefault();
153153

154-
private void setJsonValue(JsonObjectBuilder builder, T value) {
154+
/**
155+
* Writes the value key to the serialized characteristic
156+
*
157+
* @param builder The JSON builder to add the value to
158+
* @param value The value to add
159+
*/
160+
protected void setJsonValue(JsonObjectBuilder builder, T value) {
155161
//I don't like this - there should really be a way to construct a disconnected JSONValue...
156162
if (value instanceof Boolean) {
157163
builder.add("value", (Boolean) value);

src/main/java/com/beowulfe/hap/characteristics/WriteOnlyBooleanCharacteristic.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
import java.util.concurrent.CompletableFuture;
44

5+
import javax.json.JsonObjectBuilder;
6+
57
/**
68
* A characteristic that provides a boolean that can only be written to, not read.
79
*
@@ -27,4 +29,8 @@ public WriteOnlyBooleanCharacteristic(String type, String description) {
2729
@Override
2830
protected final CompletableFuture<Boolean> getValue() { return CompletableFuture.completedFuture(false); }
2931

32+
@Override
33+
protected final void setJsonValue(JsonObjectBuilder builder, Boolean value) {
34+
//Do nothing - non-readable characteristics cannot have a value key set
35+
}
3036
}

0 commit comments

Comments
 (0)