File tree 6 files changed +23
-9
lines changed
src/main/java/io/github/hapjava/characteristics/impl/base
6 files changed +23
-9
lines changed Original file line number Diff line number Diff line change
1
+ # HAP-Java 2.0.2
2
+ * Various minor stability issues for after an accessory has been removed.
3
+
1
4
# HAP-Java 2.0.1
2
5
## Fixes
3
6
* Log accessory names instead of futures. [ #150 ] ( https://github.com/hap-java/HAP-Java/issues/150 )
Original file line number Diff line number Diff line change @@ -125,15 +125,26 @@ public final void setValue(JsonValue jsonValue) {
125
125
try {
126
126
setValue (convert (jsonValue ));
127
127
} catch (Exception e ) {
128
- logger .warn ("Error while setting JSON value" , e );
128
+ logger .warn (
129
+ "Error while setting JSON value {} for characteristic {}" ,
130
+ jsonValue ,
131
+ getClass ().getName (),
132
+ e );
129
133
}
130
134
}
131
135
132
136
/** {@inheritDoc} */
133
137
@ Override
134
138
public void supplyValue (JsonObjectBuilder builder ) {
139
+ CompletableFuture <T > futureValue = getValue ();
140
+
141
+ if (futureValue == null ) {
142
+ setJsonValue (builder , getDefault ());
143
+ return ;
144
+ }
145
+
135
146
try {
136
- setJsonValue (builder , getValue () .get ());
147
+ setJsonValue (builder , futureValue .get ());
137
148
} catch (InterruptedException | ExecutionException e ) {
138
149
logger .warn ("Error retrieving value" , e );
139
150
setJsonValue (builder , getDefault ());
@@ -143,13 +154,13 @@ public void supplyValue(JsonObjectBuilder builder) {
143
154
/** {@inheritDoc} */
144
155
@ Override
145
156
public void subscribe (HomekitCharacteristicChangeCallback callback ) {
146
- subscriber .get () .accept (callback );
157
+ subscriber .ifPresent ( s -> s .accept (callback ) );
147
158
}
148
159
149
160
/** {@inheritDoc} */
150
161
@ Override
151
162
public void unsubscribe () {
152
- unsubscriber .get () .run ();
163
+ unsubscriber .ifPresent ( u -> u .run () );
153
164
}
154
165
155
166
/**
Original file line number Diff line number Diff line change @@ -130,7 +130,7 @@ protected final CompletableFuture<Double> getValue() {
130
130
131
131
@ Override
132
132
protected void setValue (Double value ) throws Exception {
133
- setter .get ().accept (value );
133
+ if ( setter . isPresent ()) setter .get ().accept (value );
134
134
}
135
135
136
136
/** {@inheritDoc} */
Original file line number Diff line number Diff line change @@ -77,7 +77,7 @@ protected CompletableFuture<Integer> getValue() {
77
77
78
78
@ Override
79
79
protected void setValue (Integer value ) throws Exception {
80
- setter .get ().accept (value );
80
+ if ( setter . isPresent ()) setter .get ().accept (value );
81
81
}
82
82
83
83
/** {@inheritDoc} */
Original file line number Diff line number Diff line change @@ -60,7 +60,7 @@ public void setValue(String value) throws Exception {
60
60
/** {@inheritDoc} */
61
61
@ Override
62
62
protected CompletableFuture <String > getValue () {
63
- return getter .map (stringGetter -> stringGetter .get ()).get ( );
63
+ return getter .map (stringGetter -> stringGetter .get ()).orElse ( null );
64
64
}
65
65
66
66
/** {@inheritDoc} */
Original file line number Diff line number Diff line change @@ -63,13 +63,13 @@ public String convert(JsonValue jsonValue) {
63
63
/** {@inheritDoc} */
64
64
@ Override
65
65
public void setValue (String value ) throws Exception {
66
- setter .get ().accept (value );
66
+ if ( setter . isPresent ()) setter .get ().accept (value );
67
67
}
68
68
69
69
/** {@inheritDoc} */
70
70
@ Override
71
71
protected CompletableFuture <String > getValue () {
72
- return getter .map (stringGetter -> stringGetter .get ()).get ( );
72
+ return getter .map (stringGetter -> stringGetter .get ()).orElse ( null );
73
73
}
74
74
75
75
/** {@inheritDoc} */
You can’t perform that action at this time.
0 commit comments