Infrastructure that works for all the locks' group!
[smartthings-infrastructure.git] / ColorControl / ColorControl.groovy
index 1c2665c2a6357e04de5a0b8a4f38dd087ad84bc1..ac80290ee4c192311e17ee3fd1756b0ea3227eb8 100644 (file)
@@ -22,13 +22,13 @@ public class ColorControl {
        
        //By model checker
        def setValue(String value, String name) {
-               if (name == "color") {
+               if ((name == "color") && (value != this.color)) {
                        this.color = value
                        println("the color of the light is changed to $value!")
-               } else if (name == "hue") {
+               } else if ((name == "hue") && (value != this.hue)) {
                        this.hue = value.toInteger()
                        println("The hue level of the light is changed to $value!")
-               } else {
+               } else if (value != this.saturation) {
                        this.saturation = value.toInteger()
                        println("The saturation level of the light is changed to $value!")
                }
@@ -36,24 +36,30 @@ public class ColorControl {
 
        //methods
        def setColor(String color) {
-               this.color = color
-               println("The color of the light is changed to $color!")
-               sendEvent([name: "color", value: "$color", deviceId: this.id, descriptionText: "",
-                          displayed: true, linkText: "", isStateChange: false, unit: "", data: [value: "$color"]]) 
+               if (color != this.color) {
+                       this.color = color
+                       println("The color of the light is changed to $color!")
+                       sendEvent([name: "color", value: "$color", deviceId: this.id, descriptionText: "",
+                                  displayed: true, linkText: "", isStateChange: false, unit: "", data: '{"info": "info"}'])
+               }
        }
 
        def setHue(int hue) {
-               this.hue = hue
-               println("The hue level of the light is changed to $hue!")
-               sendEvent([name: "hue", value: "$hue", deviceId: this.id, descriptionText: "",
-                          displayed: true, linkText: "", isStateChange: false, unit: "", data: [value: "$hue"]]) 
+               if (hue != this.hue) {
+                       this.hue = hue
+                       println("The hue level of the light is changed to $hue!")
+                       sendEvent([name: "hue", value: "$hue", deviceId: this.id, descriptionText: "",
+                                  displayed: true, linkText: "", isStateChange: false, unit: "", data: '{"info": "info"}'])
+               }
        }
 
        def setSaturation(int saturation) {
-               this.saturation = saturation
-               println("The saturation level of the light is changed to $saturation!")
-               sendEvent([name: "saturation", value: "$saturation", deviceId: this.id, descriptionText: "",
-                          displayed: true, linkText: "", isStateChange: false, unit: "", data: [value: "$saturation"]]) 
+               if (saturation != this.saturation) {
+                       this.saturation = saturation
+                       println("The saturation level of the light is changed to $saturation!")
+                       sendEvent([name: "saturation", value: "$saturation", deviceId: this.id, descriptionText: "",
+                                  displayed: true, linkText: "", isStateChange: false, unit: "", data: '{"info": "info"}'])
+               }
        }
 
        def currentValue(String deviceFeature) {