Commit #10: more classes
[smartthings-infrastructure.git] / Thermostat / Thermostat.groovy
index 720ba8270d078126988a82a9dfb37e5acdbe27be..60c1b90d21e0b0aa15d3cea39756e185c9d913b1 100644 (file)
@@ -57,12 +57,16 @@ public class Thermostat {
                this.coolingSetpoint = coolingSetpoint
                this.currentCoolingSetpoint = currentCoolingSetpoint
                println("Cooling set point for the thermostat with id:$id is changed to $coolingSetpoint!")
+               sendEvent([name: "coolingSetpoint", value: "$coolingSetpoint", deviceId: this.id, descriptionText: "",
+                          displayed: true, linkText: "", isStateChange: false, unit: "", data: [value: "$coolingSetpoint"]])
        }
 
        def setHeatingSetpoint(int heatingSetpoint) {
                this.heatingSetpoint = heatingSetpoint
                this.currentHeatingSetpoint = currentHeatingSetpoint
                println("Heating set point for the thermostat with id:$id is changed to $heatingSetpoint!")
+               sendEvent([name: "heatingSetpoint", value: "$heatingSetpoint", deviceId: this.id, descriptionText: "",
+                          displayed: true, linkText: "", isStateChange: false, unit: "", data: [value: "$heatingSetpoint"]])
        }
 
        def setSchedule() {
@@ -72,36 +76,48 @@ public class Thermostat {
        def setThermostatFanMode(String thermostatFanMode) {
                this.thermostatFanMode = thermostatFanMode
                println("Fan mode of the thermostat with id:$id is changed to $thermostatFanMode!")
+               sendEvent([name: "thermostatFanMode", value: "$thermostatFanMode", deviceId: this.id, descriptionText: "",
+                          displayed: true, linkText: "", isStateChange: false, unit: "", data: [value: "$thermostatFanMode"]])
        }
 
        def setThermostatMode(String thermostatMode) {
                this.thermostatMode = thermostatMode
                this.currentThermostatMode = currentThermostatMode
                println("Mode of the thermostat with id:$id is changed to $thermostatMode!")
+               sendEvent([name: "thermostatMode", value: "$thermostatMode", deviceId: this.id, descriptionText: "",
+                          displayed: true, linkText: "", isStateChange: false, unit: "", data: [value: "$thermostatMode"]])
        }
 
        def cool() {
                this.thermostatMode = "cool"
                this.currentThermostatMode = "cool"
                println("Mode of the thermostat with id:$id is changed to cool!")
+               sendEvent([name: "cool", value: "cool", deviceId: this.id, descriptionText: "",
+                          displayed: true, linkText: "", isStateChange: false, unit: "", data: [value: "cool"]])
        }
 
        def heat() {
                this.thermostatMode = "heat"
                this.currentThermostatMode = "heat"
                println("Mode of the thermostat with id:$id is changed to heat!")
+               sendEvent([name: "heat", value: "heat", deviceId: this.id, descriptionText: "",
+                          displayed: true, linkText: "", isStateChange: false, unit: "", data: [value: "heat"]])
        }
 
        def auto() {
                this.thermostatMode = "auto"
                this.currentThermostatMode = "auto"
                println("Mode of the thermostat with id:$id is changed to auto!")
+               sendEvent([name: "auto", value: "auto", deviceId: this.id, descriptionText: "",
+                          displayed: true, linkText: "", isStateChange: false, unit: "", data: [value: "auto"]])
        }
 
        def off() {
                this.thermostatMode = "off"
                this.currentThermostatMode = "off"
                println("Mode of the thermostat with id:$id is changed to off!")
+               sendEvent([name: "off", value: "off", deviceId: this.id, descriptionText: "",
+                          displayed: true, linkText: "", isStateChange: false, unit: "", data: [value: "off"]])
        }
 
        def setClimate(String info, String givenClimateName) {
@@ -119,10 +135,29 @@ public class Thermostat {
        }
 
        //By Model Checker
-       def setValue(String value) {
-               println("the thermostat with id:$id is $value!")
-               this.thermostatMode = value
-               this.currentThermostatMode = value
+       def setValue(String value, String name) {
+               if (name == "temperature") {
+                       println("the temperature is $value!")
+                       this.temperature = value
+               } else if (name == "heatingSetpoint") {
+                       println("the heating set point of the thermostat with id:$id is $value!")
+                       this.heatingSetpoint = value
+               } else if (name == "coolingSetpoint") {
+                       println("the cooling set point of the thermostat with id:$id is $value!")
+                       this.coolingSetpoint = value
+               } else if (name == "thermostatSetpoint") {
+                       println("the set point of the thermostat with id:$id is $value!")
+                       this.thermostatSetpoint = value
+               } else if (name == "thermostatMode") {
+                       println("the mode of the thermostat with id:$id is $value!")
+                       this.thermostatMode = value
+               } else if (name == "thermostatFanMode") {
+                       println("the fan mode of the thermostat with id:$id is $value!")
+                       this.thermostatFanMode = value
+               } else if (name == "thermostatOperatingState") {
+                       println("the operating state of the thermostat with id:$id is $value!")
+                       this.thermostatOperatingState = value
+               }
        }
 
 }