@@ -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
/**
@@ -181,7 +192,7 @@ public void unsubscribe() {
181
192
*
182
193
* @return a sensible default value.
183
194
*/
184
- protected abstract T getDefault ();
195
+ public abstract T getDefault ();
185
196
186
197
/**
187
198
* Writes the value key to the serialized characteristic
0 commit comments