Infrastructure that works for all the locks' group!
[smartthings-infrastructure.git] / Thermostat / Thermostats.groovy
index cc955d17e74849d1c73c6b8c333f8827c6c13180..19f5d6f696ef3f2c486412a8e9c97be7c3430045 100644 (file)
@@ -2,6 +2,9 @@
 package Thermostat
 import Timer.SimulatedTimer
 
+//JPF's Verify API
+import gov.nasa.jpf.vm.Verify
+
 public class Thermostats{
        int deviceNumbers       
        List thermostats        
@@ -35,6 +38,51 @@ public class Thermostats{
                this.deviceNumbers = deviceNumbers
                this.thermostats = []
 
+               def initTemperature = Verify.getIntFromList(60, 66, 70)
+               this.temperature = initTemperature
+               
+               def initCoolingSetpoint = Verify.getIntFromList(70, 80, 90)
+               this.currentCoolingSetpoint = initCoolingSetpoint
+               this.coolingSetpoint = initCoolingSetpoint
+               
+               def initHeatingSetpoint = Verify.getIntFromList(20, 35, 50)
+               this.currentHeatingSetpoint = initHeatingSetpoint
+               this.heatingSetpoint = initHeatingSetpoint
+               
+               def initThermostatSetpoint = Verify.getIntFromList(50, 60, 70)
+               this.thermostatSetpoint = initThermostatSetpoint
+               
+               def initFanMode = Verify.getInt(0,4)
+               if (initFanMode == 0) {
+                       this.thermostatFanMode = "auto"
+               } else if (initFanMode == 1) {
+                       this.thermostatFanMode = "fanCirculate"
+               } else if (initFanMode == 2) {
+                       this.thermostatFanMode = "circulate"
+               } else if (initFanMode == 3) {
+                       this.thermostatFanMode = "fanOn"
+               } else {
+                       this.thermostatFanMode = "on"
+               }
+
+               def initMode = Verify.getInt(0,4)
+               if (initMode == 0) {
+                       this.thermostatMode = "auto"
+                       this.currentThermostatMode = "auto"
+               } else if (initMode == 1) {
+                       this.thermostatMode = "cool"
+                       this.currentThermostatMode = "cool"
+               } else if (initMode == 2) {
+                       this.thermostatMode = "emergencyHeat"
+                       this.currentThermostatMode = "emergencyHeat"
+               } else if (initMode == 3) {
+                       this.thermostatMode = "heat"
+                       this.currentThermostatMode = "heat"
+               } else {
+                       this.thermostatMode = "off"
+                       this.currentThermostatMode = "off"
+               }
+
                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,
@@ -60,15 +108,19 @@ public class Thermostats{
 
        //By Apps
        def setCoolingSetpoint(int coolingSetpoint) {
-               thermostats[0].setCoolingSetpoint(coolingSetpoint)
-               this.currentCoolingSetpoint = coolingSetpoint
-               this.coolingSetpoint = coolingSetpoint
+               if (coolingSetpoint != this.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
+               if (heatingSetpoint != this.heatingSetpoint) {
+                       thermostats[0].setHeatingSetpoint(heatingSetpoint)
+                       this.currentHeatingSetpoint = heatingSetpoint
+                       this.heatingSetpoint = heatingSetpoint
+               }
        }
 
        def setSchedule() {
@@ -76,51 +128,67 @@ public class Thermostats{
        }
 
        def setThermostatFanMode(String thermostatFanMode) {
-               thermostats[0].setThermostatFanMode(thermostatFanMode)
-               this.thermostatFanMode = thermostatFanMode
+               if (thermostatFanMode != this.thermostatFanMode) {
+                       thermostats[0].setThermostatFanMode(thermostatFanMode)
+                       this.thermostatFanMode = thermostatFanMode
+               }
        }
 
        def setThermostatMode(String thermostatMode) {
-               thermostats[0].setThermostatMode(thermostatMode)
-               this.thermostatMode = thermostatMode
-               this.currentThermostatMode = currentThermostatMode
+               if (thermostatMode != this.thermostatMode) {
+                       thermostats[0].setThermostatMode(thermostatMode)
+                       this.thermostatMode = thermostatMode
+                       this.currentThermostatMode = currentThermostatMode
+               }
        }
 
        def cool() {
-               thermostats[0].cool()
-               this.thermostatMode = "cool"
-               this.currentThermostatMode = "cool"
+               if (thermostatMode != "cool") {
+                       thermostats[0].cool()
+                       this.thermostatMode = "cool"
+                       this.currentThermostatMode = "cool"
+               }
        }
 
        def heat() {
-               thermostats[0].heat()
-               this.thermostatMode = "heat"
-               this.currentThermostatMode = "heat"
+               if (thermostatMode != "heat") {
+                       thermostats[0].heat()
+                       this.thermostatMode = "heat"
+                       this.currentThermostatMode = "heat"
+               }
        }
 
        def auto() {
-               thermostats[0].auto()
-               this.thermostatMode = "auto"
-               this.currentThermostatMode = "auto"
+               if (thermostatMode != "auto") {
+                       thermostats[0].auto()
+                       this.thermostatMode = "auto"
+                       this.currentThermostatMode = "auto"
+               }
        }
 
        def off() {
-               thermostats[0].off()
-               this.thermostatMode = "off"
-               this.currentThermostatMode = "off"
+               if (thermostatMode != "off") {
+                       thermostats[0].off()
+                       this.thermostatMode = "off"
+                       this.currentThermostatMode = "off"
+               }
        }
 
        def setClimate(String info, String givenClimateName) {
-               thermostats[0].setClimate(info, givenClimateName)
-               this.climateName = givenClimateName
+               if (givenClimateName != climateName) {
+                       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
+               if ((coolingSetpoint != this.coolingSetpoint) || (heatingSetpoint != this.heatingSetpoint)) {
+                       thermostats[0].setHold(info1, coolingSetpoint, heatingSetpoint, info2, info3)
+                       this.currentCoolingSetpoint = coolingSetpoint
+                       this.coolingSetpoint = coolingSetpoint
+                       this.currentHeatingSetpoint = heatingSetpoint
+                       this.heatingSetpoint = heatingSetpoint
+               }
        }
 
        //By Model Checker