]> git.basschouten.com Git - openhab-addons.git/blob
1124a461c5d166f48288fd836ec9a1f801706500
[openhab-addons.git] /
1 /**
2  * Copyright (c) 2010-2020 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             return Integer.parseInt(value);
38         } catch (Exception e) {
39             return UNDEFINED_VALUE;
40         }
41     }
42
43     @Override
44     public State getState() {
45         return new StringType(value);
46     }
47
48     @Override
49     public void refreshValueFrom(BasePoint from) {
50         super.refreshValueFrom(from);
51         if (from instanceof StringPoint) {
52             this.value = ((StringPoint) from).value;
53         }
54     }
55 }