2 * Copyright (c) 2010-2023 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.digitalstrom.internal.lib.climate.jsonresponsecontainer.impl;
15 import java.util.Iterator;
17 import org.openhab.binding.digitalstrom.internal.lib.climate.jsonresponsecontainer.BaseSensorValues;
18 import org.openhab.binding.digitalstrom.internal.lib.climate.jsonresponsecontainer.ZoneIdentifier;
19 import org.openhab.binding.digitalstrom.internal.lib.serverconnection.constants.JSONApiResponseKeysEnum;
21 import com.google.gson.JsonArray;
22 import com.google.gson.JsonElement;
23 import com.google.gson.JsonObject;
26 * The {@link SensorValues} acts as container for the digitalSTROM json-method <i>getSensorValues</i>. So the
27 * {@link SensorValues} contains all {@link CachedSensorValue}s of a zone.
29 * @author Michael Ochel - Initial contribution
30 * @author Matthias Siegele - Initial contribution
32 public class SensorValues extends BaseSensorValues implements ZoneIdentifier {
34 private Integer zoneID;
35 private String zoneName;
38 * Creates a new {@link SensorValues} through the {@link JsonObject} that will be returned by an apartment call.
40 * @param jObject must not be null
42 public SensorValues(JsonObject jObject) {
43 if (jObject.get(JSONApiResponseKeysEnum.ID.getKey()) != null) {
44 this.zoneID = jObject.get(JSONApiResponseKeysEnum.ID.getKey()).getAsInt();
46 if (jObject.get(JSONApiResponseKeysEnum.NAME.getKey()) != null) {
47 this.zoneName = jObject.get(JSONApiResponseKeysEnum.NAME.getKey()).getAsString();
53 * Creates a new {@link SensorValues} through the {@link JsonObject} which will be returned by a zone call.
54 * Because of zone calls does not include a zoneID or zoneName in the json response, the zoneID and zoneName have to
55 * be handed over the constructor.
57 * @param jObject must not be null
58 * @param zoneID must not be null
59 * @param zoneName can be null
61 public SensorValues(JsonObject jObject, Integer zoneID, String zoneName) {
63 this.zoneName = zoneName;
67 private void init(JsonObject jObject) {
68 if (jObject.get(JSONApiResponseKeysEnum.VALUES.getKey()).isJsonArray()) {
69 JsonArray jArray = jObject.get(JSONApiResponseKeysEnum.VALUES.getKey()).getAsJsonArray();
70 if (jArray.size() != 0) {
71 Iterator<JsonElement> iter = jArray.iterator();
72 while (iter.hasNext()) {
73 JsonObject cachedSensorValue = iter.next().getAsJsonObject();
74 super.addSensorValue(cachedSensorValue, false);
83 * @see java.lang.Object#toString()
86 public String toString() {
87 return "SensorValues [zoneID=" + zoneID + ", zoneName=" + zoneName + ", " + super.toString() + "]";
91 public Integer getZoneID() {
96 public String getZoneName() {