Commit #9: More classes + Extractor with Rahmadi's editions + Fixing some bugs
[smartthings-infrastructure.git] / Thermostat / Thermostats.groovy
index 78386ab904cc5e8cfabbfe5463a888d884846695..994506677a68aa31bb30c8b1227cce9aa22b4eb5 100644 (file)
@@ -26,6 +26,8 @@ public class Thermostats{
        private String thermostatOperatingState = "cooling"
        private String thermostatFanMode = "auto"
        private String thermostatMode = "auto"
+       private String currentThermostatMode = "auto"
+       private String climateName = ""
 
        Thermostats(Closure sendEvent, int deviceNumbers) {
                this.sendEvent = sendEvent
@@ -36,7 +38,7 @@ public class Thermostats{
                thermostats.add(new Thermostat(sendEvent, id, label, displayName, this.temperature, this.currentCoolingSetpoint, 
                                                this.currentHeatingSetpoint, this.coolingSetpoint, this.thermostatSetpoint, this.heatingSetpoint, this.coolingSetpointRange,
                                                this.thermostatSetpointRange, this.heatingSetpointRange, this.supportedThermostatFanModes, this.supportedThermostatModes,
-                                               this.thermostatOperatingState, this.thermostatFanMode,  this.thermostatMode))
+                                               this.thermostatOperatingState, this.thermostatFanMode,  this.thermostatMode, this.climateName))
        }
 
        //Methods for closures
@@ -59,10 +61,14 @@ public class Thermostats{
        //By Apps
        def setCoolingSetpoint(int coolingSetpoint) {
                thermostats[0].setCoolingSetpoint(coolingSetpoint)
+               this.currentCoolingSetpoint = coolingSetpoint
+               this.coolingSetpoint = coolingSetpoint
        }
 
        def setHeatingSetpoint(int heatingSetpoint) {
                thermostats[0].setHeatingSetpoint(heatingSetpoint)
+               this.currentHeatingSetpoint = heatingSetpoint
+               this.heatingSetpoint = heatingSetpoint
        }
 
        def setSchedule() {
@@ -71,15 +77,64 @@ public class Thermostats{
 
        def setThermostatFanMode(String thermostatFanMode) {
                thermostats[0].setThermostatFanMode(thermostatFanMode)
+               this.thermostatFanMode = thermostatFanMode
        }
 
        def setThermostatMode(String thermostatMode) {
                thermostats[0].setThermostatMode(thermostatMode)
+               this.thermostatMode = thermostatMode
+               this.currentThermostatMode = currentThermostatMode
        }
 
+       def cool() {
+               thermostats[0].cool()
+               this.thermostatMode = "cool"
+               this.currentThermostatMode = "cool"
+       }
+
+       def heat() {
+               thermostats[0].heat()
+               this.thermostatMode = "heat"
+               this.currentThermostatMode = "heat"
+       }
+
+       def auto() {
+               thermostats[0].auto()
+               this.thermostatMode = "auto"
+               this.currentThermostatMode = "auto"
+       }
+
+       def off() {
+               thermostats[0].off()
+               this.thermostatMode = "off"
+               this.currentThermostatMode = "off"
+       }
+
+       def setClimate(String info, String givenClimateName) {
+               thermostats[0].setClimate(info, givenClimateName)
+               this.climateName = givenClimateName
+       }
+
+       def setHold(String info1, int coolingSetpoint, int heatingSetpoint, String info2, String info3) {
+               thermostats[0].setHold(info1, coolingSetpoint, heatingSetpoint, info2, info3)
+               this.currentCoolingSetpoint = coolingSetpoint
+               this.coolingSetpoint = coolingSetpoint
+               this.currentHeatingSetpoint = heatingSetpoint
+               this.heatingSetpoint = heatingSetpoint
+       }
+
+       //By Model Checker
+       def setValue(LinkedHashMap eventDataMap) {
+               if (eventDataMap["value"] != thermostats[0].thermostatMode) {
+                       thermostats[0].setValue(eventDataMap["value"])
+                       this.thermostatMode = thermostats[0].thermostatMode
+                       this.currentThermostatMode = thermostats[0].currentThermostatMode
+                       sendEvent(eventDataMap)
+               }
+       }
 
        def getAt(int ix) {
-               locks[ix]
+               thermostats[ix]
        }
 }