2 * Copyright (c) 2010-2023 Contributors to the openHAB project
4 * See the NOTICE file(s) distributed with this work for additional
7 * This program and the accompanying materials are made available under the
8 * terms of the Eclipse Public License 2.0 which is available at
9 * http://www.eclipse.org/legal/epl-2.0
11 * SPDX-License-Identifier: EPL-2.0
13 package org.openhab.binding.siemensrds.points;
15 import org.eclipse.jdt.annotation.NonNullByDefault;
16 import org.eclipse.jdt.annotation.Nullable;
17 import org.openhab.core.library.types.QuantityType;
18 import org.openhab.core.types.State;
19 import org.openhab.core.types.UnDefType;
21 import com.google.gson.annotations.SerializedName;
24 * private class a data point where "value" is a nested JSON numeric element
26 * @author Andrew Fiddian-Green - Initial contribution
30 public class NestedNumberPoint extends BasePoint {
32 @SerializedName("value")
33 protected @Nullable NestedNumberValue inner;
37 NestedNumberValue inner = this.inner;
39 Number innerValue = inner.value;
40 if (innerValue != null) {
41 return innerValue.intValue();
44 return UNDEFINED_VALUE;
48 public State getState() {
49 NestedNumberValue inner = this.inner;
51 Number innerValue = inner.value;
52 if (innerValue != null) {
53 return new QuantityType<>(innerValue.doubleValue(), getUnit());
56 return UnDefType.NULL;
60 public int getPresentPriority() {
61 NestedNumberValue inner = this.inner;
62 return inner != null ? inner.presentPriority : UNDEFINED_VALUE;
65 public void setPresentPriority(int value) {
66 NestedNumberValue inner = this.inner;
68 inner.presentPriority = value;
73 public void refreshValueFrom(BasePoint from) {
74 super.refreshValueFrom(from);
75 if (from instanceof NestedNumberPoint point) {
76 NestedNumberValue fromInner = point.inner;
77 NestedNumberValue thisInner = this.inner;
78 if (thisInner != null && fromInner != null) {
79 thisInner.value = fromInner.value;
80 thisInner.presentPriority = fromInner.presentPriority;