]> git.basschouten.com Git - openhab-addons.git/blob
cb1c7b08ebe31a99e00afd9aafce74baf4ada123
[openhab-addons.git] /
1 /**
2  * Copyright (c) 2010-2023 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.digitalstrom.internal.lib.climate.jsonresponsecontainer.impl;
14
15 import java.text.DateFormat;
16 import java.text.ParseException;
17 import java.text.SimpleDateFormat;
18 import java.util.Date;
19
20 import org.openhab.binding.digitalstrom.internal.lib.climate.jsonresponsecontainer.BaseTemperatureControl;
21 import org.openhab.binding.digitalstrom.internal.lib.serverconnection.constants.JSONApiResponseKeysEnum;
22
23 import com.google.gson.JsonObject;
24
25 /**
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.
29  *
30  * @author Michael Ochel - Initial contribution
31  * @author Matthias Siegele - Initial contribution
32  */
33 public class TemperatureControlStatus extends BaseTemperatureControl {
34
35     DateFormat formatter = new SimpleDateFormat("yyyy-MM-dd'T'hh:mm:ss");
36
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;
45
46     /**
47      * Creates a new {@link TemperatureControlStatus} through the {@link JsonObject} which will be returned by an
48      * apartment call.
49      *
50      * @param jObject must not be null
51      */
52     public TemperatureControlStatus(JsonObject jObject) {
53         super(jObject);
54         init(jObject);
55     }
56
57     /**
58      * Creates a new {@link TemperatureControlStatus} through the {@link JsonObject} which will be returned by a zone
59      * call.<br>
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.
62      *
63      * @param jObject must not be null
64      * @param zoneID must not be null
65      * @param zoneName can be null
66      */
67     public TemperatureControlStatus(JsonObject jObject, Integer zoneID, String zoneName) {
68         super(jObject, zoneID, zoneName);
69         init(jObject);
70     }
71
72     private void init(JsonObject jObject) {
73         if (isNotSetOff()) {
74             if (jObject.get(JSONApiResponseKeysEnum.CONTROL_STATE.getKey()) != null) {
75                 this.controlState = jObject.get(JSONApiResponseKeysEnum.CONTROL_STATE.getKey()).getAsShort();
76             }
77             if (jObject.get(JSONApiResponseKeysEnum.OPERATION_MODE.getKey()) != null) {
78                 this.operationMode = jObject.get(JSONApiResponseKeysEnum.OPERATION_MODE.getKey()).getAsShort();
79             }
80             if (jObject.get(JSONApiResponseKeysEnum.TEMPERATION_VALUE.getKey()) != null) {
81                 this.temperature = jObject.get(JSONApiResponseKeysEnum.TEMPERATION_VALUE.getKey()).getAsFloat();
82             }
83             if (jObject.get(JSONApiResponseKeysEnum.NOMINAL_VALUE.getKey()) != null) {
84                 this.nominalValue = jObject.get(JSONApiResponseKeysEnum.NOMINAL_VALUE.getKey()).getAsFloat();
85             }
86             if (jObject.get(JSONApiResponseKeysEnum.CONTROL_VALUE.getKey()) != null) {
87                 this.controlValue = jObject.get(JSONApiResponseKeysEnum.CONTROL_VALUE.getKey()).getAsFloat();
88             }
89             if (jObject.get(JSONApiResponseKeysEnum.TEMPERATION_VALUE_TIME.getKey()) != null) {
90                 this.temperatureTime = jObject.get(JSONApiResponseKeysEnum.TEMPERATION_VALUE_TIME.getKey())
91                         .getAsString();
92             }
93             if (jObject.get(JSONApiResponseKeysEnum.NOMINAL_VALUE_TIME.getKey()) != null) {
94                 this.nominalValueTime = jObject.get(JSONApiResponseKeysEnum.NOMINAL_VALUE_TIME.getKey()).getAsString();
95             }
96             if (jObject.get(JSONApiResponseKeysEnum.CONTROL_VALUE_TIME.getKey()) != null) {
97                 this.controlValueTime = jObject.get(JSONApiResponseKeysEnum.CONTROL_VALUE_TIME.getKey()).getAsString();
98             }
99         }
100     }
101
102     /**
103      * Returns the controleState for heating of the zone.
104      *
105      * @return the controlState
106      */
107     public Short getControlState() {
108         return controlState;
109     }
110
111     /**
112      * Returns the operationMode for heating of the zone.
113      *
114      * @return the operationMode
115      */
116     public Short getOperationMode() {
117         return operationMode;
118     }
119
120     /**
121      * Returns the current temperature of the zone.
122      *
123      * @return the temperature
124      */
125     public Float getTemperature() {
126         return temperature;
127     }
128
129     /**
130      * Returns the timestamp when the temperature was read out as {@link Date}.
131      *
132      * @return the temperatureTime
133      * @throws ParseException see {@link DateFormat#parse(String)}
134      */
135     public Date getTemperatureTimeAsDate() throws ParseException {
136         return formatter.parse(temperatureTime);
137     }
138
139     /**
140      * Returns the timestamp when the temperature was read out as {@link String}.
141      *
142      * @return the temperatureTime
143      */
144     public String getTemperatureTimeAsString() {
145         return temperatureTime;
146     }
147
148     /**
149      * Returns the nominal value for heating of the zone.
150      *
151      * @return the nominalValue
152      */
153     public Float getNominalValue() {
154         return nominalValue;
155     }
156
157     /**
158      * Returns the timestamp as {@link Date} for the nominal value of the zone.
159      *
160      * @return the nominalValueTime
161      * @throws ParseException see {@link DateFormat#parse(String)}
162      */
163     public Date getNominalValueTimeAsDate() throws ParseException {
164         return formatter.parse(nominalValueTime);
165     }
166
167     /**
168      * Returns the timestamp as {@link String} for the nominal value of the zone.
169      *
170      * @return the nominalValueTime
171      */
172     public String getNominalValueTimeAsString() {
173         return nominalValueTime;
174     }
175
176     /**
177      * Returns the control value for heating of the zone.
178      *
179      * @return the controlValue
180      */
181     public Float getControlValue() {
182         return controlValue;
183     }
184
185     /**
186      * Returns timestamp as {@link Date} for the control value for heating of the zone.
187      *
188      * @return the controlValueTime
189      * @throws ParseException see {@link DateFormat#parse(String)}
190      */
191     public Date getControlValueTimeAsDate() throws ParseException {
192         return formatter.parse(controlValueTime);
193     }
194
195     /**
196      * Returns timestamp as {@link String} for the control value for heating of the zone.
197      *
198      * @return the controlValueTime
199      */
200     public String getControlValueTimeAsString() {
201         return controlValueTime;
202     }
203
204     /*
205      * (non-Javadoc)
206      *
207      * @see java.lang.Object#toString()
208      */
209     @Override
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 + "]";
215     }
216 }