File tree Expand file tree Collapse file tree 6 files changed +23
-9
lines changed
src/main/java/io/github/hapjava/characteristics/impl/base Expand file tree Collapse file tree 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+
14# HAP-Java 2.0.1
25## Fixes
36* 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) {
125125 try {
126126 setValue (convert (jsonValue ));
127127 } 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 );
129133 }
130134 }
131135
132136 /** {@inheritDoc} */
133137 @ Override
134138 public void supplyValue (JsonObjectBuilder builder ) {
139+ CompletableFuture <T > futureValue = getValue ();
140+
141+ if (futureValue == null ) {
142+ setJsonValue (builder , getDefault ());
143+ return ;
144+ }
145+
135146 try {
136- setJsonValue (builder , getValue () .get ());
147+ setJsonValue (builder , futureValue .get ());
137148 } catch (InterruptedException | ExecutionException e ) {
138149 logger .warn ("Error retrieving value" , e );
139150 setJsonValue (builder , getDefault ());
@@ -143,13 +154,13 @@ public void supplyValue(JsonObjectBuilder builder) {
143154 /** {@inheritDoc} */
144155 @ Override
145156 public void subscribe (HomekitCharacteristicChangeCallback callback ) {
146- subscriber .get () .accept (callback );
157+ subscriber .ifPresent ( s -> s .accept (callback ) );
147158 }
148159
149160 /** {@inheritDoc} */
150161 @ Override
151162 public void unsubscribe () {
152- unsubscriber .get () .run ();
163+ unsubscriber .ifPresent ( u -> u .run () );
153164 }
154165
155166 /**
Original file line number Diff line number Diff line change @@ -130,7 +130,7 @@ protected final CompletableFuture<Double> getValue() {
130130
131131 @ Override
132132 protected void setValue (Double value ) throws Exception {
133- setter .get ().accept (value );
133+ if ( setter . isPresent ()) setter .get ().accept (value );
134134 }
135135
136136 /** {@inheritDoc} */
Original file line number Diff line number Diff line change @@ -77,7 +77,7 @@ protected CompletableFuture<Integer> getValue() {
7777
7878 @ Override
7979 protected void setValue (Integer value ) throws Exception {
80- setter .get ().accept (value );
80+ if ( setter . isPresent ()) setter .get ().accept (value );
8181 }
8282
8383 /** {@inheritDoc} */
Original file line number Diff line number Diff line change @@ -60,7 +60,7 @@ public void setValue(String value) throws Exception {
6060 /** {@inheritDoc} */
6161 @ Override
6262 protected CompletableFuture <String > getValue () {
63- return getter .map (stringGetter -> stringGetter .get ()).get ( );
63+ return getter .map (stringGetter -> stringGetter .get ()).orElse ( null );
6464 }
6565
6666 /** {@inheritDoc} */
Original file line number Diff line number Diff line change @@ -63,13 +63,13 @@ public String convert(JsonValue jsonValue) {
6363 /** {@inheritDoc} */
6464 @ Override
6565 public void setValue (String value ) throws Exception {
66- setter .get ().accept (value );
66+ if ( setter . isPresent ()) setter .get ().accept (value );
6767 }
6868
6969 /** {@inheritDoc} */
7070 @ Override
7171 protected CompletableFuture <String > getValue () {
72- return getter .map (stringGetter -> stringGetter .get ()).get ( );
72+ return getter .map (stringGetter -> stringGetter .get ()).orElse ( null );
7373 }
7474
7575 /** {@inheritDoc} */
You can’t perform that action at this time.
0 commit comments