2 * Copyright (c) 2010-2024 Contributors to the openHAB project
4 * See the NOTICE file(s) distributed with this work for additional
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
11 * SPDX-License-Identifier: EPL-2.0
13 package org.openhab.binding.siemenshvac.internal.metadata;
15 import java.util.ArrayList;
16 import java.util.List;
18 import javax.validation.constraints.NotNull;
20 import org.eclipse.jdt.annotation.NonNullByDefault;
21 import org.eclipse.jdt.annotation.Nullable;
22 import org.openhab.binding.siemenshvac.internal.constants.SiemensHvacBindingConstants;
24 import com.google.gson.JsonArray;
25 import com.google.gson.JsonObject;
29 * @author Laurent Arnal - Initial contribution
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;
48 private @NotNull List<SiemensHvacMetadataPointChild> child = List.of();
50 public SiemensHvacMetadataDataPoint() {
51 child = new ArrayList<SiemensHvacMetadataPointChild>();
54 public String getDptType() {
58 public void setDptType(String dptType) {
59 this.dptType = dptType;
62 public List<SiemensHvacMetadataPointChild> getChild() {
66 public void setChild(List<SiemensHvacMetadataPointChild> child) {
70 public String getDptId() {
74 public void setDptId(String dptId) {
78 public int getDptSubKey() {
82 public void setDptSubKey(int dptSubKey) {
83 this.dptSubKey = dptSubKey;
86 public @Nullable String getAddress() {
90 public void setWriteAccess(boolean writeAccess) {
91 this.writeAccess = writeAccess;
94 public boolean getWriteAccess() {
98 public void setAddress(String address) {
99 this.address = address;
102 public @Nullable String getDptUnit() {
106 public void setDptUnit(String dptUnit) {
107 this.dptUnit = dptUnit;
110 public @Nullable String getMaxLength() {
114 public void setMaxLength(String maxLength) {
115 this.maxLength = maxLength;
118 public @Nullable String getDialogType() {
122 public void setDialogType(String dialogType) {
123 this.dialogType = dialogType;
126 public @Nullable String getMin() {
130 public void setMin(String min) {
134 public @Nullable String getMax() {
138 public void setMax(String max) {
142 public @Nullable String getResolution() {
146 public void setResolution(String resolution) {
147 this.resolution = resolution;
150 public @Nullable String getFieldWitdh() {
154 public void setFieldWitdh(String fieldWitdh) {
155 this.fieldWitdh = fieldWitdh;
158 public @Nullable String getDecimalDigits() {
159 return decimalDigits;
162 public void setDecimalDigits(String decimalDigits) {
163 this.decimalDigits = decimalDigits;
166 public Boolean getDetailsResolved() {
167 return detailsResolved;
170 public void setDetailsResolved(Boolean detailsResolved) {
171 this.detailsResolved = detailsResolved;
174 public void resolveDptDetails(JsonObject result) {
175 JsonObject subResultObj = result.getAsJsonObject("Result");
176 JsonObject desc = result.getAsJsonObject("Description");
178 if (subResultObj.has("Success")) {
179 JsonObject error = subResultObj.getAsJsonObject("Error");
180 String errorMsg = "";
182 errorMsg = error.get("Txt").getAsString();
185 if (("datatype not supported").equals(errorMsg)) {
186 detailsResolved = true;
193 this.dptType = desc.get("Type").getAsString();
195 if (SiemensHvacBindingConstants.DPT_TYPE_ENUM.equals(dptType)) {
196 JsonArray enums = desc.getAsJsonArray("Enums");
198 for (Object obj : enums) {
199 JsonObject entry = (JsonObject) obj;
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());
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");
220 child = new ArrayList<SiemensHvacMetadataPointChild>();
222 for (Object obj : buttons) {
223 JsonObject button = (JsonObject) obj;
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());
233 detailsResolved = true;