]> git.basschouten.com Git - openhab-addons.git/blob
876648493c614efabc1356613844f4aa77a581a0
[openhab-addons.git] /
1 /**
2  * Copyright (c) 2010-2024 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.solax.internal.connectivity.rawdata.local;
14
15 import java.util.Arrays;
16
17 import org.eclipse.jdt.annotation.NonNullByDefault;
18 import org.eclipse.jdt.annotation.Nullable;
19 import org.openhab.binding.solax.internal.connectivity.rawdata.RawDataBean;
20 import org.openhab.binding.solax.internal.util.GsonSupplier;
21
22 import com.google.gson.Gson;
23 import com.google.gson.annotations.SerializedName;
24
25 /**
26  * The {@link LocalConnectRawDataBean} collects the raw data and the specific implementation to return the parsed data.
27  *
28  * @author Konstantin Polihronov - Initial contribution
29  */
30 @NonNullByDefault
31 public class LocalConnectRawDataBean implements RawDataBean {
32
33     private @Nullable String sn;
34     private @Nullable String ver;
35     private int type;
36     @SerializedName("Data")
37     private short @Nullable [] data;
38     @SerializedName("Information")
39     private String @Nullable [] information;
40     private @Nullable String rawData;
41
42     @Override
43     public String toString() {
44         return "LocalConnectRawDataBean [sn=" + sn + ", ver=" + ver + ", type=" + type + ", Information="
45                 + Arrays.toString(information) + ", Data=" + Arrays.toString(data) + "]";
46     }
47
48     public @Nullable String getSn() {
49         return sn;
50     }
51
52     public void setSn(@Nullable String sn) {
53         this.sn = sn;
54     }
55
56     public @Nullable String getVer() {
57         return ver;
58     }
59
60     public void setVer(@Nullable String ver) {
61         this.ver = ver;
62     }
63
64     public int getType() {
65         return type;
66     }
67
68     public void setType(int type) {
69         this.type = type;
70     }
71
72     public short @Nullable [] getData() {
73         return data;
74     }
75
76     public void setData(short @Nullable [] data) {
77         this.data = data;
78     }
79
80     public String @Nullable [] getInformation() {
81         return information;
82     }
83
84     public void setInformation(String @Nullable [] information) {
85         this.information = information;
86     }
87
88     @Override
89     public @Nullable String getRawData() {
90         return rawData;
91     }
92
93     @Override
94     public void setRawData(String rawData) {
95         this.rawData = rawData;
96     }
97
98     public static LocalConnectRawDataBean fromJson(String json) {
99         if (json.isEmpty()) {
100             throw new IllegalArgumentException("JSON payload should not be empty");
101         }
102
103         Gson gson = GsonSupplier.getInstance();
104         LocalConnectRawDataBean deserializedObject = gson.fromJson(json, LocalConnectRawDataBean.class);
105         if (deserializedObject == null) {
106             throw new IllegalStateException("Unexpected null result when deserializing JSON");
107         }
108         deserializedObject.setRawData(json);
109         return deserializedObject;
110     }
111 }