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.text.DateFormat;
16 import java.text.ParseException;
17 import java.text.SimpleDateFormat;
18 import java.util.Date;
20 import org.openhab.binding.digitalstrom.internal.lib.climate.jsonresponsecontainer.BaseTemperatureControl;
21 import org.openhab.binding.digitalstrom.internal.lib.serverconnection.constants.JSONApiResponseKeysEnum;
23 import com.google.gson.JsonObject;
26 * The {@link TemperatureControlStatus} acts as container for the digitalSTROM json-method
27 * <i>getTemperatureControlStatus</i>. So the {@link TemperatureControlStatus} contains all heating
28 * control status information of a zone.
30 * @author Michael Ochel - Initial contribution
31 * @author Matthias Siegele - Initial contribution
33 public class TemperatureControlStatus extends BaseTemperatureControl {
35 DateFormat formatter = new SimpleDateFormat("yyyy-MM-dd'T'hh:mm:ss");
37 private Short controlState;
38 private Short operationMode;
39 private Float temperature;
40 private String temperatureTime;
41 private Float nominalValue;
42 private String nominalValueTime;
43 private Float controlValue;
44 private String controlValueTime;
47 * Creates a new {@link TemperatureControlStatus} through the {@link JsonObject} which will be returned by an
50 * @param jObject must not be null
52 public TemperatureControlStatus(JsonObject jObject) {
58 * Creates a new {@link TemperatureControlStatus} through the {@link JsonObject} which will be returned by a zone
60 * Because of zone calls does not include a zoneID or zoneName in the json response, the zoneID and zoneName have to
61 * be handed over the constructor.
63 * @param jObject must not be null
64 * @param zoneID must not be null
65 * @param zoneName can be null
67 public TemperatureControlStatus(JsonObject jObject, Integer zoneID, String zoneName) {
68 super(jObject, zoneID, zoneName);
72 private void init(JsonObject jObject) {
74 if (jObject.get(JSONApiResponseKeysEnum.CONTROL_STATE.getKey()) != null) {
75 this.controlState = jObject.get(JSONApiResponseKeysEnum.CONTROL_STATE.getKey()).getAsShort();
77 if (jObject.get(JSONApiResponseKeysEnum.OPERATION_MODE.getKey()) != null) {
78 this.operationMode = jObject.get(JSONApiResponseKeysEnum.OPERATION_MODE.getKey()).getAsShort();
80 if (jObject.get(JSONApiResponseKeysEnum.TEMPERATION_VALUE.getKey()) != null) {
81 this.temperature = jObject.get(JSONApiResponseKeysEnum.TEMPERATION_VALUE.getKey()).getAsFloat();
83 if (jObject.get(JSONApiResponseKeysEnum.NOMINAL_VALUE.getKey()) != null) {
84 this.nominalValue = jObject.get(JSONApiResponseKeysEnum.NOMINAL_VALUE.getKey()).getAsFloat();
86 if (jObject.get(JSONApiResponseKeysEnum.CONTROL_VALUE.getKey()) != null) {
87 this.controlValue = jObject.get(JSONApiResponseKeysEnum.CONTROL_VALUE.getKey()).getAsFloat();
89 if (jObject.get(JSONApiResponseKeysEnum.TEMPERATION_VALUE_TIME.getKey()) != null) {
90 this.temperatureTime = jObject.get(JSONApiResponseKeysEnum.TEMPERATION_VALUE_TIME.getKey())
93 if (jObject.get(JSONApiResponseKeysEnum.NOMINAL_VALUE_TIME.getKey()) != null) {
94 this.nominalValueTime = jObject.get(JSONApiResponseKeysEnum.NOMINAL_VALUE_TIME.getKey()).getAsString();
96 if (jObject.get(JSONApiResponseKeysEnum.CONTROL_VALUE_TIME.getKey()) != null) {
97 this.controlValueTime = jObject.get(JSONApiResponseKeysEnum.CONTROL_VALUE_TIME.getKey()).getAsString();
103 * Returns the controleState for heating of the zone.
105 * @return the controlState
107 public Short getControlState() {
112 * Returns the operationMode for heating of the zone.
114 * @return the operationMode
116 public Short getOperationMode() {
117 return operationMode;
121 * Returns the current temperature of the zone.
123 * @return the temperature
125 public Float getTemperature() {
130 * Returns the timestamp when the temperature was read out as {@link Date}.
132 * @return the temperatureTime
133 * @throws ParseException see {@link DateFormat#parse(String)}
135 public Date getTemperatureTimeAsDate() throws ParseException {
136 return formatter.parse(temperatureTime);
140 * Returns the timestamp when the temperature was read out as {@link String}.
142 * @return the temperatureTime
144 public String getTemperatureTimeAsString() {
145 return temperatureTime;
149 * Returns the nominal value for heating of the zone.
151 * @return the nominalValue
153 public Float getNominalValue() {
158 * Returns the timestamp as {@link Date} for the nominal value of the zone.
160 * @return the nominalValueTime
161 * @throws ParseException see {@link DateFormat#parse(String)}
163 public Date getNominalValueTimeAsDate() throws ParseException {
164 return formatter.parse(nominalValueTime);
168 * Returns the timestamp as {@link String} for the nominal value of the zone.
170 * @return the nominalValueTime
172 public String getNominalValueTimeAsString() {
173 return nominalValueTime;
177 * Returns the control value for heating of the zone.
179 * @return the controlValue
181 public Float getControlValue() {
186 * Returns timestamp as {@link Date} for the control value for heating of the zone.
188 * @return the controlValueTime
189 * @throws ParseException see {@link DateFormat#parse(String)}
191 public Date getControlValueTimeAsDate() throws ParseException {
192 return formatter.parse(controlValueTime);
196 * Returns timestamp as {@link String} for the control value for heating of the zone.
198 * @return the controlValueTime
200 public String getControlValueTimeAsString() {
201 return controlValueTime;
207 * @see java.lang.Object#toString()
210 public String toString() {
211 return "TemperatureControlStatus [controlMode=" + controlMode + ", controlState=" + controlState
212 + ", operationMode=" + operationMode + ", temperature=" + temperature + ", temperatureTime="
213 + temperatureTime + ", nominalValue=" + nominalValue + ", nominalValueTime=" + nominalValueTime
214 + ", controlValue=" + controlValue + ", controlValueTime=" + controlValueTime + "]";