]> git.basschouten.com Git - openhab-addons.git/blob
b628d3d374266156f4ff03499c106bf299f01042
[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.StringType;
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 text element
24  *
25  * @author Andrew Fiddian-Green - Initial contribution
26  *
27  */
28 @NonNullByDefault
29 public class StringPoint extends BasePoint {
30
31     @SerializedName("value")
32     private @Nullable String value;
33
34     @Override
35     public int asInt() {
36         try {
37             String value = this.value;
38             if (value != null) {
39                 return Integer.parseInt(value);
40             }
41         } catch (NumberFormatException e) {
42             // default value
43         }
44         return UNDEFINED_VALUE;
45     }
46
47     @Override
48     public State getState() {
49         return new StringType(value);
50     }
51
52     @Override
53     public void refreshValueFrom(BasePoint from) {
54         super.refreshValueFrom(from);
55         if (from instanceof StringPoint) {
56             this.value = ((StringPoint) from).value;
57         }
58     }
59 }