]> git.basschouten.com Git - openhab-addons.git/blob
51b4a8e4f17f45b6113c1f5bae3857c53ad967ce
[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.siemenshvac.internal.metadata;
14
15 import java.util.ArrayList;
16 import java.util.List;
17
18 import javax.validation.constraints.NotNull;
19
20 import org.eclipse.jdt.annotation.NonNullByDefault;
21 import org.eclipse.jdt.annotation.Nullable;
22 import org.openhab.binding.siemenshvac.internal.constants.SiemensHvacBindingConstants;
23
24 import com.google.gson.JsonArray;
25 import com.google.gson.JsonObject;
26
27 /**
28  *
29  * @author Laurent Arnal - Initial contribution
30  */
31 @NonNullByDefault
32 public class SiemensHvacMetadataDataPoint extends SiemensHvacMetadata {
33     private String dptId = "-1";
34     private String dptType = "";
35     private @Nullable String dptUnit = null;
36     private @Nullable String min = null;
37     private @Nullable String max = null;
38     private @Nullable String resolution = null;
39     private @Nullable String fieldWitdh = null;
40     private @Nullable String decimalDigits = null;
41     private boolean detailsResolved = false;
42     private @Nullable String dialogType = null;
43     private @Nullable String maxLength = null;
44     private @Nullable String address = null;
45     private int dptSubKey = -1;
46     private boolean writeAccess = false;
47
48     private @NotNull List<SiemensHvacMetadataPointChild> child = List.of();
49
50     public SiemensHvacMetadataDataPoint() {
51         child = new ArrayList<SiemensHvacMetadataPointChild>();
52     }
53
54     public String getDptType() {
55         return dptType;
56     }
57
58     public void setDptType(String dptType) {
59         this.dptType = dptType;
60     }
61
62     public List<SiemensHvacMetadataPointChild> getChild() {
63         return child;
64     }
65
66     public void setChild(List<SiemensHvacMetadataPointChild> child) {
67         this.child = child;
68     }
69
70     public String getDptId() {
71         return dptId;
72     }
73
74     public void setDptId(String dptId) {
75         this.dptId = dptId;
76     }
77
78     public int getDptSubKey() {
79         return dptSubKey;
80     }
81
82     public void setDptSubKey(int dptSubKey) {
83         this.dptSubKey = dptSubKey;
84     }
85
86     public @Nullable String getAddress() {
87         return address;
88     }
89
90     public void setWriteAccess(boolean writeAccess) {
91         this.writeAccess = writeAccess;
92     }
93
94     public boolean getWriteAccess() {
95         return writeAccess;
96     }
97
98     public void setAddress(String address) {
99         this.address = address;
100     }
101
102     public @Nullable String getDptUnit() {
103         return dptUnit;
104     }
105
106     public void setDptUnit(String dptUnit) {
107         this.dptUnit = dptUnit;
108     }
109
110     public @Nullable String getMaxLength() {
111         return maxLength;
112     }
113
114     public void setMaxLength(String maxLength) {
115         this.maxLength = maxLength;
116     }
117
118     public @Nullable String getDialogType() {
119         return dialogType;
120     }
121
122     public void setDialogType(String dialogType) {
123         this.dialogType = dialogType;
124     }
125
126     public @Nullable String getMin() {
127         return min;
128     }
129
130     public void setMin(String min) {
131         this.min = min;
132     }
133
134     public @Nullable String getMax() {
135         return max;
136     }
137
138     public void setMax(String max) {
139         this.max = max;
140     }
141
142     public @Nullable String getResolution() {
143         return resolution;
144     }
145
146     public void setResolution(String resolution) {
147         this.resolution = resolution;
148     }
149
150     public @Nullable String getFieldWitdh() {
151         return fieldWitdh;
152     }
153
154     public void setFieldWitdh(String fieldWitdh) {
155         this.fieldWitdh = fieldWitdh;
156     }
157
158     public @Nullable String getDecimalDigits() {
159         return decimalDigits;
160     }
161
162     public void setDecimalDigits(String decimalDigits) {
163         this.decimalDigits = decimalDigits;
164     }
165
166     public Boolean getDetailsResolved() {
167         return detailsResolved;
168     }
169
170     public void setDetailsResolved(Boolean detailsResolved) {
171         this.detailsResolved = detailsResolved;
172     }
173
174     public void resolveDptDetails(JsonObject result) {
175         JsonObject subResultObj = result.getAsJsonObject("Result");
176         JsonObject desc = result.getAsJsonObject("Description");
177
178         if (subResultObj.has("Success")) {
179             JsonObject error = subResultObj.getAsJsonObject("Error");
180             String errorMsg = "";
181             if (error != null) {
182                 errorMsg = error.get("Txt").getAsString();
183             }
184
185             if (("datatype not supported").equals(errorMsg)) {
186                 detailsResolved = true;
187                 return;
188             }
189
190         }
191
192         if (desc != null) {
193             this.dptType = desc.get("Type").getAsString();
194
195             if (SiemensHvacBindingConstants.DPT_TYPE_ENUM.equals(dptType)) {
196                 JsonArray enums = desc.getAsJsonArray("Enums");
197
198                 for (Object obj : enums) {
199                     JsonObject entry = (JsonObject) obj;
200
201                     SiemensHvacMetadataPointChild ch = new SiemensHvacMetadataPointChild();
202                     ch.setText(entry.get("Text").getAsString());
203                     ch.setValue(entry.get("Value").getAsString());
204                     ch.setIsActive(entry.get("IsCurrentValue").getAsString());
205                     child.add(ch);
206                 }
207             } else if (SiemensHvacBindingConstants.DPT_TYPE_NUMERIC.equals(dptType)) {
208                 this.dptUnit = desc.get("Unit").getAsString();
209                 this.min = desc.get("Min").getAsString();
210                 this.max = desc.get("Max").getAsString();
211                 this.resolution = desc.get("Resolution").getAsString();
212                 this.fieldWitdh = desc.get("FieldWitdh").getAsString();
213                 this.decimalDigits = desc.get("DecimalDigits").getAsString();
214             } else if (SiemensHvacBindingConstants.DPT_TYPE_STRING.equals(dptType)) {
215                 this.dialogType = desc.get("DialogType").getAsString();
216                 this.maxLength = desc.get("MaxLength").getAsString();
217             } else if (SiemensHvacBindingConstants.DPT_TYPE_RADIO.equals(dptType)) {
218                 JsonArray buttons = desc.getAsJsonArray("Buttons");
219
220                 child = new ArrayList<SiemensHvacMetadataPointChild>();
221
222                 for (Object obj : buttons) {
223                     JsonObject button = (JsonObject) obj;
224
225                     SiemensHvacMetadataPointChild ch = new SiemensHvacMetadataPointChild();
226                     ch.setOpt0(button.get("TextOpt0").getAsString());
227                     ch.setOpt1(button.get("TextOpt1").getAsString());
228                     ch.setIsActive(button.get("IsActive").getAsString());
229                     child.add(ch);
230                 }
231             }
232
233             detailsResolved = true;
234         }
235     }
236 }