File tree Expand file tree Collapse file tree 7 files changed +32
-13
lines changed
src/main/java/io/github/hapjava/characteristics/impl/base Expand file tree Collapse file tree 7 files changed +32
-13
lines changed Original file line number Diff line number Diff line change @@ -183,14 +183,14 @@ 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.
190190 *
191191 * @return a future that will complete with the current value.
192192 */
193- protected abstract CompletableFuture <T > getValue ();
193+ public abstract CompletableFuture <T > getValue ();
194194
195195 /**
196196 * Supplies a default value for the characteristic to send to connected clients when the real
Original file line number Diff line number Diff line change @@ -60,12 +60,12 @@ protected Boolean convert(JsonValue jsonValue) {
6060 }
6161
6262 @ Override
63- protected CompletableFuture <Boolean > getValue () {
63+ public CompletableFuture <Boolean > getValue () {
6464 return getter .isPresent () ? getter .map (booleanGetter -> booleanGetter .get ()).get () : null ;
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
Original file line number Diff line number Diff line change @@ -84,16 +84,35 @@ protected Integer convert(JsonValue jsonValue) {
8484 }
8585 }
8686
87+ /**
88+ * @return the current value of this characteristic, or null if it has no value or can't be
89+ * fetched
90+ */
91+ public CompletableFuture <T > getEnumValue () {
92+ if (!getter .isPresent ()) {
93+ return null ;
94+ }
95+ return getter .get ().get ();
96+ }
97+
8798 @ Override
88- protected CompletableFuture <Integer > getValue () {
99+ public CompletableFuture <Integer > getValue () {
89100 if (!getter .isPresent ()) {
90101 return null ;
91102 }
92103 return getter .get ().get ().thenApply (T ::getCode );
93104 }
94105
106+ public void setValue (T value ) throws Exception {
107+ if (!setter .isPresent ()) {
108+ return ;
109+ }
110+
111+ setter .get ().accept (value );
112+ }
113+
95114 @ Override
96- protected void setValue (Integer value ) throws Exception {
115+ public void setValue (Integer value ) throws Exception {
97116 if (!setter .isPresent ()) {
98117 return ;
99118 }
@@ -102,7 +121,7 @@ protected void setValue(Integer value) throws Exception {
102121 if (validValues != null && value != null ) {
103122 for (T valid : validValues ) {
104123 if (valid .getCode () == value ) {
105- setter . get (). accept (valid );
124+ setValue (valid );
106125 return ;
107126 }
108127 }
Original file line number Diff line number Diff line change @@ -94,7 +94,7 @@ protected Double convert(JsonValue jsonValue) {
9494 * the constructor.
9595 */
9696 @ Override
97- protected final CompletableFuture <Double > getValue () {
97+ public final CompletableFuture <Double > getValue () {
9898 if (!getter .isPresent ()) {
9999 return null ;
100100 }
@@ -129,7 +129,7 @@ protected 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
Original file line number Diff line number Diff line change @@ -71,12 +71,12 @@ protected CompletableFuture<JsonObjectBuilder> makeBuilder(int iid) {
7171 }
7272
7373 @ Override
74- protected CompletableFuture <Integer > getValue () {
74+ public CompletableFuture <Integer > getValue () {
7575 return getter .map (integerGetter -> integerGetter .get ()).orElse (null );
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
Original file line number Diff line number Diff line change @@ -59,7 +59,7 @@ public void setValue(String value) throws Exception {
5959
6060 /** {@inheritDoc} */
6161 @ Override
62- protected CompletableFuture <String > getValue () {
62+ public CompletableFuture <String > getValue () {
6363 return getter .map (stringGetter -> stringGetter .get ()).orElse (null );
6464 }
6565
Original file line number Diff line number Diff line change @@ -68,7 +68,7 @@ public void setValue(String value) throws Exception {
6868
6969 /** {@inheritDoc} */
7070 @ Override
71- protected CompletableFuture <String > getValue () {
71+ public CompletableFuture <String > getValue () {
7272 return getter .map (stringGetter -> stringGetter .get ()).orElse (null );
7373 }
7474
You can’t perform that action at this time.
0 commit comments