]> git.basschouten.com Git - openhab-addons.git/blob
17a2f6ef7a57eff6e05b771312169f98cfc584ec
[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.DecimalType;
18 import org.openhab.core.types.State;
19
20 import com.google.gson.annotations.SerializedName;
21
22 /**
23  * private class a data point where "value" is a JSON numeric element
24  *
25  * @author Andrew Fiddian-Green - Initial contribution
26  *
27  */
28 @NonNullByDefault
29 public class NumberPoint extends BasePoint {
30
31     @SerializedName("value")
32     private @Nullable Number value;
33
34     @Override
35     public int asInt() {
36         Number value = this.value;
37         return value != null ? value.intValue() : UNDEFINED_VALUE;
38     }
39
40     @Override
41     public State getState() {
42         Number value = this.value;
43         return value != null ? new DecimalType(value.doubleValue()) : new DecimalType(UNDEFINED_VALUE);
44     }
45
46     @Override
47     public void refreshValueFrom(BasePoint from) {
48         super.refreshValueFrom(from);
49         if (from instanceof NumberPoint point) {
50             this.value = point.value;
51         }
52     }
53 }