]> git.basschouten.com Git - openhab-addons.git/blob
d29af323b6a842732a3725094de4d1a0775f3a4e
[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.nest.internal.wwn.dto;
14
15 import static org.openhab.core.library.unit.ImperialUnits.FAHRENHEIT;
16 import static org.openhab.core.library.unit.SIUnits.CELSIUS;
17
18 import java.util.Date;
19
20 import javax.measure.Unit;
21 import javax.measure.quantity.Temperature;
22
23 import com.google.gson.annotations.SerializedName;
24
25 /**
26  * Gson class to encapsulate the data for the WWN thermostat.
27  *
28  * @author David Bennett - Initial contribution
29  * @author Wouter Born - Add equals and hashCode methods
30  */
31 public class WWNThermostat extends BaseWWNDevice {
32
33     private Boolean canCool;
34     private Boolean canHeat;
35     private Boolean isUsingEmergencyHeat;
36     private Boolean hasFan;
37     private Boolean fanTimerActive;
38     private Date fanTimerTimeout;
39     private Boolean hasLeaf;
40     private String temperatureScale;
41     private Double ambientTemperatureC;
42     private Double ambientTemperatureF;
43     private Integer humidity;
44     private Double targetTemperatureC;
45     private Double targetTemperatureF;
46     private Double targetTemperatureHighC;
47     private Double targetTemperatureHighF;
48     private Double targetTemperatureLowC;
49     private Double targetTemperatureLowF;
50     private Mode hvacMode;
51     private Mode previousHvacMode;
52     private State hvacState;
53     private Double ecoTemperatureHighC;
54     private Double ecoTemperatureHighF;
55     private Double ecoTemperatureLowC;
56     private Double ecoTemperatureLowF;
57     private Boolean isLocked;
58     private Double lockedTempMaxC;
59     private Double lockedTempMaxF;
60     private Double lockedTempMinC;
61     private Double lockedTempMinF;
62     private Boolean sunlightCorrectionEnabled;
63     private Boolean sunlightCorrectionActive;
64     private Integer fanTimerDuration;
65     private String timeToTarget;
66     private String whereName;
67
68     public Unit<Temperature> getTemperatureUnit() {
69         if ("C".equals(temperatureScale)) {
70             return CELSIUS;
71         } else if ("F".equals(temperatureScale)) {
72             return FAHRENHEIT;
73         } else {
74             return null;
75         }
76     }
77
78     public Double getTargetTemperature() {
79         if (getTemperatureUnit() == CELSIUS) {
80             return targetTemperatureC;
81         } else if (getTemperatureUnit() == FAHRENHEIT) {
82             return targetTemperatureF;
83         } else {
84             return null;
85         }
86     }
87
88     public Double getTargetTemperatureHigh() {
89         if (getTemperatureUnit() == CELSIUS) {
90             return targetTemperatureHighC;
91         } else if (getTemperatureUnit() == FAHRENHEIT) {
92             return targetTemperatureHighF;
93         } else {
94             return null;
95         }
96     }
97
98     public Double getTargetTemperatureLow() {
99         if (getTemperatureUnit() == CELSIUS) {
100             return targetTemperatureLowC;
101         } else if (getTemperatureUnit() == FAHRENHEIT) {
102             return targetTemperatureLowF;
103         } else {
104             return null;
105         }
106     }
107
108     public Mode getMode() {
109         return hvacMode;
110     }
111
112     public Double getEcoTemperatureHigh() {
113         if (getTemperatureUnit() == CELSIUS) {
114             return ecoTemperatureHighC;
115         } else if (getTemperatureUnit() == FAHRENHEIT) {
116             return ecoTemperatureHighF;
117         } else {
118             return null;
119         }
120     }
121
122     public Double getEcoTemperatureLow() {
123         if (getTemperatureUnit() == CELSIUS) {
124             return ecoTemperatureLowC;
125         } else if (getTemperatureUnit() == FAHRENHEIT) {
126             return ecoTemperatureLowF;
127         } else {
128             return null;
129         }
130     }
131
132     public Boolean isLocked() {
133         return isLocked;
134     }
135
136     public Double getLockedTempMax() {
137         if (getTemperatureUnit() == CELSIUS) {
138             return lockedTempMaxC;
139         } else if (getTemperatureUnit() == FAHRENHEIT) {
140             return lockedTempMaxF;
141         } else {
142             return null;
143         }
144     }
145
146     public Double getLockedTempMin() {
147         if (getTemperatureUnit() == CELSIUS) {
148             return lockedTempMinC;
149         } else if (getTemperatureUnit() == FAHRENHEIT) {
150             return lockedTempMinF;
151         } else {
152             return null;
153         }
154     }
155
156     public Boolean isCanCool() {
157         return canCool;
158     }
159
160     public Boolean isCanHeat() {
161         return canHeat;
162     }
163
164     public Boolean isUsingEmergencyHeat() {
165         return isUsingEmergencyHeat;
166     }
167
168     public Boolean isHasFan() {
169         return hasFan;
170     }
171
172     public Boolean isFanTimerActive() {
173         return fanTimerActive;
174     }
175
176     public Date getFanTimerTimeout() {
177         return fanTimerTimeout;
178     }
179
180     public Boolean isHasLeaf() {
181         return hasLeaf;
182     }
183
184     public Mode getPreviousHvacMode() {
185         return previousHvacMode;
186     }
187
188     public State getHvacState() {
189         return hvacState;
190     }
191
192     public Boolean isSunlightCorrectionEnabled() {
193         return sunlightCorrectionEnabled;
194     }
195
196     public Boolean isSunlightCorrectionActive() {
197         return sunlightCorrectionActive;
198     }
199
200     public Integer getFanTimerDuration() {
201         return fanTimerDuration;
202     }
203
204     public Integer getTimeToTarget() {
205         return parseTimeToTarget(timeToTarget);
206     }
207
208     /*
209      * Turns the time to target string into a real value.
210      */
211     static Integer parseTimeToTarget(String timeToTarget) {
212         if (timeToTarget == null) {
213             return null;
214         } else if (timeToTarget.startsWith("~") || timeToTarget.startsWith("<") || timeToTarget.startsWith(">")) {
215             return Integer.valueOf(timeToTarget.substring(1));
216         }
217         return Integer.valueOf(timeToTarget);
218     }
219
220     public String getWhereName() {
221         return whereName;
222     }
223
224     public Double getAmbientTemperature() {
225         if (getTemperatureUnit() == CELSIUS) {
226             return ambientTemperatureC;
227         } else if (getTemperatureUnit() == FAHRENHEIT) {
228             return ambientTemperatureF;
229         } else {
230             return null;
231         }
232     }
233
234     public Integer getHumidity() {
235         return humidity;
236     }
237
238     public enum Mode {
239         @SerializedName("heat")
240         HEAT,
241         @SerializedName("cool")
242         COOL,
243         @SerializedName("heat-cool")
244         HEAT_COOL,
245         @SerializedName("eco")
246         ECO,
247         @SerializedName("off")
248         OFF
249     }
250
251     public enum State {
252         @SerializedName("heating")
253         HEATING,
254         @SerializedName("cooling")
255         COOLING,
256         @SerializedName("off")
257         OFF
258     }
259
260     @Override
261     public boolean equals(Object obj) {
262         if (this == obj) {
263             return true;
264         }
265         if (obj == null || !super.equals(obj)) {
266             return false;
267         }
268         if (getClass() != obj.getClass()) {
269             return false;
270         }
271         WWNThermostat other = (WWNThermostat) obj;
272         if (ambientTemperatureC == null) {
273             if (other.ambientTemperatureC != null) {
274                 return false;
275             }
276         } else if (!ambientTemperatureC.equals(other.ambientTemperatureC)) {
277             return false;
278         }
279         if (ambientTemperatureF == null) {
280             if (other.ambientTemperatureF != null) {
281                 return false;
282             }
283         } else if (!ambientTemperatureF.equals(other.ambientTemperatureF)) {
284             return false;
285         }
286         if (canCool == null) {
287             if (other.canCool != null) {
288                 return false;
289             }
290         } else if (!canCool.equals(other.canCool)) {
291             return false;
292         }
293         if (canHeat == null) {
294             if (other.canHeat != null) {
295                 return false;
296             }
297         } else if (!canHeat.equals(other.canHeat)) {
298             return false;
299         }
300         if (ecoTemperatureHighC == null) {
301             if (other.ecoTemperatureHighC != null) {
302                 return false;
303             }
304         } else if (!ecoTemperatureHighC.equals(other.ecoTemperatureHighC)) {
305             return false;
306         }
307         if (ecoTemperatureHighF == null) {
308             if (other.ecoTemperatureHighF != null) {
309                 return false;
310             }
311         } else if (!ecoTemperatureHighF.equals(other.ecoTemperatureHighF)) {
312             return false;
313         }
314         if (ecoTemperatureLowC == null) {
315             if (other.ecoTemperatureLowC != null) {
316                 return false;
317             }
318         } else if (!ecoTemperatureLowC.equals(other.ecoTemperatureLowC)) {
319             return false;
320         }
321         if (ecoTemperatureLowF == null) {
322             if (other.ecoTemperatureLowF != null) {
323                 return false;
324             }
325         } else if (!ecoTemperatureLowF.equals(other.ecoTemperatureLowF)) {
326             return false;
327         }
328         if (fanTimerActive == null) {
329             if (other.fanTimerActive != null) {
330                 return false;
331             }
332         } else if (!fanTimerActive.equals(other.fanTimerActive)) {
333             return false;
334         }
335         if (fanTimerDuration == null) {
336             if (other.fanTimerDuration != null) {
337                 return false;
338             }
339         } else if (!fanTimerDuration.equals(other.fanTimerDuration)) {
340             return false;
341         }
342         if (fanTimerTimeout == null) {
343             if (other.fanTimerTimeout != null) {
344                 return false;
345             }
346         } else if (!fanTimerTimeout.equals(other.fanTimerTimeout)) {
347             return false;
348         }
349         if (hasFan == null) {
350             if (other.hasFan != null) {
351                 return false;
352             }
353         } else if (!hasFan.equals(other.hasFan)) {
354             return false;
355         }
356         if (hasLeaf == null) {
357             if (other.hasLeaf != null) {
358                 return false;
359             }
360         } else if (!hasLeaf.equals(other.hasLeaf)) {
361             return false;
362         }
363         if (humidity == null) {
364             if (other.humidity != null) {
365                 return false;
366             }
367         } else if (!humidity.equals(other.humidity)) {
368             return false;
369         }
370         if (hvacMode != other.hvacMode) {
371             return false;
372         }
373         if (hvacState != other.hvacState) {
374             return false;
375         }
376         if (isLocked == null) {
377             if (other.isLocked != null) {
378                 return false;
379             }
380         } else if (!isLocked.equals(other.isLocked)) {
381             return false;
382         }
383         if (isUsingEmergencyHeat == null) {
384             if (other.isUsingEmergencyHeat != null) {
385                 return false;
386             }
387         } else if (!isUsingEmergencyHeat.equals(other.isUsingEmergencyHeat)) {
388             return false;
389         }
390         if (lockedTempMaxC == null) {
391             if (other.lockedTempMaxC != null) {
392                 return false;
393             }
394         } else if (!lockedTempMaxC.equals(other.lockedTempMaxC)) {
395             return false;
396         }
397         if (lockedTempMaxF == null) {
398             if (other.lockedTempMaxF != null) {
399                 return false;
400             }
401         } else if (!lockedTempMaxF.equals(other.lockedTempMaxF)) {
402             return false;
403         }
404         if (lockedTempMinC == null) {
405             if (other.lockedTempMinC != null) {
406                 return false;
407             }
408         } else if (!lockedTempMinC.equals(other.lockedTempMinC)) {
409             return false;
410         }
411         if (lockedTempMinF == null) {
412             if (other.lockedTempMinF != null) {
413                 return false;
414             }
415         } else if (!lockedTempMinF.equals(other.lockedTempMinF)) {
416             return false;
417         }
418         if (previousHvacMode != other.previousHvacMode) {
419             return false;
420         }
421         if (sunlightCorrectionActive == null) {
422             if (other.sunlightCorrectionActive != null) {
423                 return false;
424             }
425         } else if (!sunlightCorrectionActive.equals(other.sunlightCorrectionActive)) {
426             return false;
427         }
428         if (sunlightCorrectionEnabled == null) {
429             if (other.sunlightCorrectionEnabled != null) {
430                 return false;
431             }
432         } else if (!sunlightCorrectionEnabled.equals(other.sunlightCorrectionEnabled)) {
433             return false;
434         }
435         if (targetTemperatureC == null) {
436             if (other.targetTemperatureC != null) {
437                 return false;
438             }
439         } else if (!targetTemperatureC.equals(other.targetTemperatureC)) {
440             return false;
441         }
442         if (targetTemperatureF == null) {
443             if (other.targetTemperatureF != null) {
444                 return false;
445             }
446         } else if (!targetTemperatureF.equals(other.targetTemperatureF)) {
447             return false;
448         }
449         if (targetTemperatureHighC == null) {
450             if (other.targetTemperatureHighC != null) {
451                 return false;
452             }
453         } else if (!targetTemperatureHighC.equals(other.targetTemperatureHighC)) {
454             return false;
455         }
456         if (targetTemperatureHighF == null) {
457             if (other.targetTemperatureHighF != null) {
458                 return false;
459             }
460         } else if (!targetTemperatureHighF.equals(other.targetTemperatureHighF)) {
461             return false;
462         }
463         if (targetTemperatureLowC == null) {
464             if (other.targetTemperatureLowC != null) {
465                 return false;
466             }
467         } else if (!targetTemperatureLowC.equals(other.targetTemperatureLowC)) {
468             return false;
469         }
470         if (targetTemperatureLowF == null) {
471             if (other.targetTemperatureLowF != null) {
472                 return false;
473             }
474         } else if (!targetTemperatureLowF.equals(other.targetTemperatureLowF)) {
475             return false;
476         }
477         if (temperatureScale == null) {
478             if (other.temperatureScale != null) {
479                 return false;
480             }
481         } else if (!temperatureScale.equals(other.temperatureScale)) {
482             return false;
483         }
484         if (timeToTarget == null) {
485             if (other.timeToTarget != null) {
486                 return false;
487             }
488         } else if (!timeToTarget.equals(other.timeToTarget)) {
489             return false;
490         }
491         if (whereName == null) {
492             if (other.whereName != null) {
493                 return false;
494             }
495         } else if (!whereName.equals(other.whereName)) {
496             return false;
497         }
498         return true;
499     }
500
501     @Override
502     public int hashCode() {
503         final int prime = 31;
504         int result = super.hashCode();
505         result = prime * result + ((ambientTemperatureC == null) ? 0 : ambientTemperatureC.hashCode());
506         result = prime * result + ((ambientTemperatureF == null) ? 0 : ambientTemperatureF.hashCode());
507         result = prime * result + ((canCool == null) ? 0 : canCool.hashCode());
508         result = prime * result + ((canHeat == null) ? 0 : canHeat.hashCode());
509         result = prime * result + ((ecoTemperatureHighC == null) ? 0 : ecoTemperatureHighC.hashCode());
510         result = prime * result + ((ecoTemperatureHighF == null) ? 0 : ecoTemperatureHighF.hashCode());
511         result = prime * result + ((ecoTemperatureLowC == null) ? 0 : ecoTemperatureLowC.hashCode());
512         result = prime * result + ((ecoTemperatureLowF == null) ? 0 : ecoTemperatureLowF.hashCode());
513         result = prime * result + ((fanTimerActive == null) ? 0 : fanTimerActive.hashCode());
514         result = prime * result + ((fanTimerDuration == null) ? 0 : fanTimerDuration.hashCode());
515         result = prime * result + ((fanTimerTimeout == null) ? 0 : fanTimerTimeout.hashCode());
516         result = prime * result + ((hasFan == null) ? 0 : hasFan.hashCode());
517         result = prime * result + ((hasLeaf == null) ? 0 : hasLeaf.hashCode());
518         result = prime * result + ((humidity == null) ? 0 : humidity.hashCode());
519         result = prime * result + ((hvacMode == null) ? 0 : hvacMode.hashCode());
520         result = prime * result + ((hvacState == null) ? 0 : hvacState.hashCode());
521         result = prime * result + ((isLocked == null) ? 0 : isLocked.hashCode());
522         result = prime * result + ((isUsingEmergencyHeat == null) ? 0 : isUsingEmergencyHeat.hashCode());
523         result = prime * result + ((lockedTempMaxC == null) ? 0 : lockedTempMaxC.hashCode());
524         result = prime * result + ((lockedTempMaxF == null) ? 0 : lockedTempMaxF.hashCode());
525         result = prime * result + ((lockedTempMinC == null) ? 0 : lockedTempMinC.hashCode());
526         result = prime * result + ((lockedTempMinF == null) ? 0 : lockedTempMinF.hashCode());
527         result = prime * result + ((previousHvacMode == null) ? 0 : previousHvacMode.hashCode());
528         result = prime * result + ((sunlightCorrectionActive == null) ? 0 : sunlightCorrectionActive.hashCode());
529         result = prime * result + ((sunlightCorrectionEnabled == null) ? 0 : sunlightCorrectionEnabled.hashCode());
530         result = prime * result + ((targetTemperatureC == null) ? 0 : targetTemperatureC.hashCode());
531         result = prime * result + ((targetTemperatureF == null) ? 0 : targetTemperatureF.hashCode());
532         result = prime * result + ((targetTemperatureHighC == null) ? 0 : targetTemperatureHighC.hashCode());
533         result = prime * result + ((targetTemperatureHighF == null) ? 0 : targetTemperatureHighF.hashCode());
534         result = prime * result + ((targetTemperatureLowC == null) ? 0 : targetTemperatureLowC.hashCode());
535         result = prime * result + ((targetTemperatureLowF == null) ? 0 : targetTemperatureLowF.hashCode());
536         result = prime * result + ((temperatureScale == null) ? 0 : temperatureScale.hashCode());
537         result = prime * result + ((timeToTarget == null) ? 0 : timeToTarget.hashCode());
538         result = prime * result + ((whereName == null) ? 0 : whereName.hashCode());
539         return result;
540     }
541
542     @Override
543     public String toString() {
544         StringBuilder builder = new StringBuilder();
545         builder.append("Thermostat [canCool=").append(canCool).append(", canHeat=").append(canHeat)
546                 .append(", isUsingEmergencyHeat=").append(isUsingEmergencyHeat).append(", hasFan=").append(hasFan)
547                 .append(", fanTimerActive=").append(fanTimerActive).append(", fanTimerTimeout=").append(fanTimerTimeout)
548                 .append(", hasLeaf=").append(hasLeaf).append(", temperatureScale=").append(temperatureScale)
549                 .append(", ambientTemperatureC=").append(ambientTemperatureC).append(", ambientTemperatureF=")
550                 .append(ambientTemperatureF).append(", humidity=").append(humidity).append(", targetTemperatureC=")
551                 .append(targetTemperatureC).append(", targetTemperatureF=").append(targetTemperatureF)
552                 .append(", targetTemperatureHighC=").append(targetTemperatureHighC).append(", targetTemperatureHighF=")
553                 .append(targetTemperatureHighF).append(", targetTemperatureLowC=").append(targetTemperatureLowC)
554                 .append(", targetTemperatureLowF=").append(targetTemperatureLowF).append(", hvacMode=").append(hvacMode)
555                 .append(", previousHvacMode=").append(previousHvacMode).append(", hvacState=").append(hvacState)
556                 .append(", ecoTemperatureHighC=").append(ecoTemperatureHighC).append(", ecoTemperatureHighF=")
557                 .append(ecoTemperatureHighF).append(", ecoTemperatureLowC=").append(ecoTemperatureLowC)
558                 .append(", ecoTemperatureLowF=").append(ecoTemperatureLowF).append(", isLocked=").append(isLocked)
559                 .append(", lockedTempMaxC=").append(lockedTempMaxC).append(", lockedTempMaxF=").append(lockedTempMaxF)
560                 .append(", lockedTempMinC=").append(lockedTempMinC).append(", lockedTempMinF=").append(lockedTempMinF)
561                 .append(", sunlightCorrectionEnabled=").append(sunlightCorrectionEnabled)
562                 .append(", sunlightCorrectionActive=").append(sunlightCorrectionActive).append(", fanTimerDuration=")
563                 .append(fanTimerDuration).append(", timeToTarget=").append(timeToTarget).append(", whereName=")
564                 .append(whereName).append(", getId()=").append(getId()).append(", getName()=").append(getName())
565                 .append(", getDeviceId()=").append(getDeviceId()).append(", getLastConnection()=")
566                 .append(getLastConnection()).append(", isOnline()=").append(isOnline()).append(", getNameLong()=")
567                 .append(getNameLong()).append(", getSoftwareVersion()=").append(getSoftwareVersion())
568                 .append(", getStructureId()=").append(getStructureId()).append(", getWhereId()=").append(getWhereId())
569                 .append("]");
570         return builder.toString();
571     }
572 }