]> git.basschouten.com Git - openhab-addons.git/blob
186a2f29b64f898b181f774f138629530b1b3b47
[openhab-addons.git] /
1 /**
2  * Copyright (c) 2010-2023 Contributors to the openHAB project
3  *
4  * See the NOTICE file(s) distributed with this work for additional
5  * information.
6  *
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
10  *
11  * SPDX-License-Identifier: EPL-2.0
12  */
13 package org.openhab.binding.siemensrds.points;
14
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;
20
21 import com.google.gson.annotations.SerializedName;
22
23 /**
24  * private class a data point where "value" is a nested JSON numeric element
25  *
26  * @author Andrew Fiddian-Green - Initial contribution
27  *
28  */
29 @NonNullByDefault
30 public class NestedNumberPoint extends BasePoint {
31
32     @SerializedName("value")
33     protected @Nullable NestedNumberValue inner;
34
35     @Override
36     public int asInt() {
37         NestedNumberValue inner = this.inner;
38         if (inner != null) {
39             Number innerValue = inner.value;
40             if (innerValue != null) {
41                 return innerValue.intValue();
42             }
43         }
44         return UNDEFINED_VALUE;
45     }
46
47     @Override
48     public State getState() {
49         NestedNumberValue inner = this.inner;
50         if (inner != null) {
51             Number innerValue = inner.value;
52             if (innerValue != null) {
53                 return new QuantityType<>(innerValue.doubleValue(), getUnit());
54             }
55         }
56         return UnDefType.NULL;
57     }
58
59     @Override
60     public int getPresentPriority() {
61         NestedNumberValue inner = this.inner;
62         return inner != null ? inner.presentPriority : UNDEFINED_VALUE;
63     }
64
65     public void setPresentPriority(int value) {
66         NestedNumberValue inner = this.inner;
67         if (inner != null) {
68             inner.presentPriority = value;
69         }
70     }
71
72     @Override
73     public void refreshValueFrom(BasePoint from) {
74         super.refreshValueFrom(from);
75         if (from instanceof NestedNumberPoint) {
76             NestedNumberValue fromInner = ((NestedNumberPoint) from).inner;
77             NestedNumberValue thisInner = this.inner;
78             if (thisInner != null && fromInner != null) {
79                 thisInner.value = fromInner.value;
80                 thisInner.presentPriority = fromInner.presentPriority;
81             }
82         }
83     }
84 }