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.nest.internal.wwn.dto;
15 import static org.openhab.core.library.unit.ImperialUnits.FAHRENHEIT;
16 import static org.openhab.core.library.unit.SIUnits.CELSIUS;
18 import java.util.Date;
20 import javax.measure.Unit;
21 import javax.measure.quantity.Temperature;
23 import com.google.gson.annotations.SerializedName;
26 * Gson class to encapsulate the data for the WWN thermostat.
28 * @author David Bennett - Initial contribution
29 * @author Wouter Born - Add equals and hashCode methods
31 public class WWNThermostat extends BaseWWNDevice {
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;
68 public Unit<Temperature> getTemperatureUnit() {
69 if ("C".equals(temperatureScale)) {
71 } else if ("F".equals(temperatureScale)) {
78 public Double getTargetTemperature() {
79 if (getTemperatureUnit() == CELSIUS) {
80 return targetTemperatureC;
81 } else if (getTemperatureUnit() == FAHRENHEIT) {
82 return targetTemperatureF;
88 public Double getTargetTemperatureHigh() {
89 if (getTemperatureUnit() == CELSIUS) {
90 return targetTemperatureHighC;
91 } else if (getTemperatureUnit() == FAHRENHEIT) {
92 return targetTemperatureHighF;
98 public Double getTargetTemperatureLow() {
99 if (getTemperatureUnit() == CELSIUS) {
100 return targetTemperatureLowC;
101 } else if (getTemperatureUnit() == FAHRENHEIT) {
102 return targetTemperatureLowF;
108 public Mode getMode() {
112 public Double getEcoTemperatureHigh() {
113 if (getTemperatureUnit() == CELSIUS) {
114 return ecoTemperatureHighC;
115 } else if (getTemperatureUnit() == FAHRENHEIT) {
116 return ecoTemperatureHighF;
122 public Double getEcoTemperatureLow() {
123 if (getTemperatureUnit() == CELSIUS) {
124 return ecoTemperatureLowC;
125 } else if (getTemperatureUnit() == FAHRENHEIT) {
126 return ecoTemperatureLowF;
132 public Boolean isLocked() {
136 public Double getLockedTempMax() {
137 if (getTemperatureUnit() == CELSIUS) {
138 return lockedTempMaxC;
139 } else if (getTemperatureUnit() == FAHRENHEIT) {
140 return lockedTempMaxF;
146 public Double getLockedTempMin() {
147 if (getTemperatureUnit() == CELSIUS) {
148 return lockedTempMinC;
149 } else if (getTemperatureUnit() == FAHRENHEIT) {
150 return lockedTempMinF;
156 public Boolean isCanCool() {
160 public Boolean isCanHeat() {
164 public Boolean isUsingEmergencyHeat() {
165 return isUsingEmergencyHeat;
168 public Boolean isHasFan() {
172 public Boolean isFanTimerActive() {
173 return fanTimerActive;
176 public Date getFanTimerTimeout() {
177 return fanTimerTimeout;
180 public Boolean isHasLeaf() {
184 public Mode getPreviousHvacMode() {
185 return previousHvacMode;
188 public State getHvacState() {
192 public Boolean isSunlightCorrectionEnabled() {
193 return sunlightCorrectionEnabled;
196 public Boolean isSunlightCorrectionActive() {
197 return sunlightCorrectionActive;
200 public Integer getFanTimerDuration() {
201 return fanTimerDuration;
204 public Integer getTimeToTarget() {
205 return parseTimeToTarget(timeToTarget);
209 * Turns the time to target string into a real value.
211 static Integer parseTimeToTarget(String timeToTarget) {
212 if (timeToTarget == null) {
214 } else if (timeToTarget.startsWith("~") || timeToTarget.startsWith("<") || timeToTarget.startsWith(">")) {
215 return Integer.valueOf(timeToTarget.substring(1));
217 return Integer.valueOf(timeToTarget);
220 public String getWhereName() {
224 public Double getAmbientTemperature() {
225 if (getTemperatureUnit() == CELSIUS) {
226 return ambientTemperatureC;
227 } else if (getTemperatureUnit() == FAHRENHEIT) {
228 return ambientTemperatureF;
234 public Integer getHumidity() {
239 @SerializedName("heat")
241 @SerializedName("cool")
243 @SerializedName("heat-cool")
245 @SerializedName("eco")
247 @SerializedName("off")
252 @SerializedName("heating")
254 @SerializedName("cooling")
256 @SerializedName("off")
261 public boolean equals(Object obj) {
265 if (obj == null || !super.equals(obj)) {
268 if (getClass() != obj.getClass()) {
271 WWNThermostat other = (WWNThermostat) obj;
272 if (ambientTemperatureC == null) {
273 if (other.ambientTemperatureC != null) {
276 } else if (!ambientTemperatureC.equals(other.ambientTemperatureC)) {
279 if (ambientTemperatureF == null) {
280 if (other.ambientTemperatureF != null) {
283 } else if (!ambientTemperatureF.equals(other.ambientTemperatureF)) {
286 if (canCool == null) {
287 if (other.canCool != null) {
290 } else if (!canCool.equals(other.canCool)) {
293 if (canHeat == null) {
294 if (other.canHeat != null) {
297 } else if (!canHeat.equals(other.canHeat)) {
300 if (ecoTemperatureHighC == null) {
301 if (other.ecoTemperatureHighC != null) {
304 } else if (!ecoTemperatureHighC.equals(other.ecoTemperatureHighC)) {
307 if (ecoTemperatureHighF == null) {
308 if (other.ecoTemperatureHighF != null) {
311 } else if (!ecoTemperatureHighF.equals(other.ecoTemperatureHighF)) {
314 if (ecoTemperatureLowC == null) {
315 if (other.ecoTemperatureLowC != null) {
318 } else if (!ecoTemperatureLowC.equals(other.ecoTemperatureLowC)) {
321 if (ecoTemperatureLowF == null) {
322 if (other.ecoTemperatureLowF != null) {
325 } else if (!ecoTemperatureLowF.equals(other.ecoTemperatureLowF)) {
328 if (fanTimerActive == null) {
329 if (other.fanTimerActive != null) {
332 } else if (!fanTimerActive.equals(other.fanTimerActive)) {
335 if (fanTimerDuration == null) {
336 if (other.fanTimerDuration != null) {
339 } else if (!fanTimerDuration.equals(other.fanTimerDuration)) {
342 if (fanTimerTimeout == null) {
343 if (other.fanTimerTimeout != null) {
346 } else if (!fanTimerTimeout.equals(other.fanTimerTimeout)) {
349 if (hasFan == null) {
350 if (other.hasFan != null) {
353 } else if (!hasFan.equals(other.hasFan)) {
356 if (hasLeaf == null) {
357 if (other.hasLeaf != null) {
360 } else if (!hasLeaf.equals(other.hasLeaf)) {
363 if (humidity == null) {
364 if (other.humidity != null) {
367 } else if (!humidity.equals(other.humidity)) {
370 if (hvacMode != other.hvacMode) {
373 if (hvacState != other.hvacState) {
376 if (isLocked == null) {
377 if (other.isLocked != null) {
380 } else if (!isLocked.equals(other.isLocked)) {
383 if (isUsingEmergencyHeat == null) {
384 if (other.isUsingEmergencyHeat != null) {
387 } else if (!isUsingEmergencyHeat.equals(other.isUsingEmergencyHeat)) {
390 if (lockedTempMaxC == null) {
391 if (other.lockedTempMaxC != null) {
394 } else if (!lockedTempMaxC.equals(other.lockedTempMaxC)) {
397 if (lockedTempMaxF == null) {
398 if (other.lockedTempMaxF != null) {
401 } else if (!lockedTempMaxF.equals(other.lockedTempMaxF)) {
404 if (lockedTempMinC == null) {
405 if (other.lockedTempMinC != null) {
408 } else if (!lockedTempMinC.equals(other.lockedTempMinC)) {
411 if (lockedTempMinF == null) {
412 if (other.lockedTempMinF != null) {
415 } else if (!lockedTempMinF.equals(other.lockedTempMinF)) {
418 if (previousHvacMode != other.previousHvacMode) {
421 if (sunlightCorrectionActive == null) {
422 if (other.sunlightCorrectionActive != null) {
425 } else if (!sunlightCorrectionActive.equals(other.sunlightCorrectionActive)) {
428 if (sunlightCorrectionEnabled == null) {
429 if (other.sunlightCorrectionEnabled != null) {
432 } else if (!sunlightCorrectionEnabled.equals(other.sunlightCorrectionEnabled)) {
435 if (targetTemperatureC == null) {
436 if (other.targetTemperatureC != null) {
439 } else if (!targetTemperatureC.equals(other.targetTemperatureC)) {
442 if (targetTemperatureF == null) {
443 if (other.targetTemperatureF != null) {
446 } else if (!targetTemperatureF.equals(other.targetTemperatureF)) {
449 if (targetTemperatureHighC == null) {
450 if (other.targetTemperatureHighC != null) {
453 } else if (!targetTemperatureHighC.equals(other.targetTemperatureHighC)) {
456 if (targetTemperatureHighF == null) {
457 if (other.targetTemperatureHighF != null) {
460 } else if (!targetTemperatureHighF.equals(other.targetTemperatureHighF)) {
463 if (targetTemperatureLowC == null) {
464 if (other.targetTemperatureLowC != null) {
467 } else if (!targetTemperatureLowC.equals(other.targetTemperatureLowC)) {
470 if (targetTemperatureLowF == null) {
471 if (other.targetTemperatureLowF != null) {
474 } else if (!targetTemperatureLowF.equals(other.targetTemperatureLowF)) {
477 if (temperatureScale == null) {
478 if (other.temperatureScale != null) {
481 } else if (!temperatureScale.equals(other.temperatureScale)) {
484 if (timeToTarget == null) {
485 if (other.timeToTarget != null) {
488 } else if (!timeToTarget.equals(other.timeToTarget)) {
491 if (whereName == null) {
492 if (other.whereName != null) {
495 } else if (!whereName.equals(other.whereName)) {
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());
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())
570 return builder.toString();