Adding missing methods etc.
[smartthings-infrastructure.git] / ColorControl / ColorControl.groovy
index c60afb1620e7cbec1bbe659f4e6cbd20b2db40ef..4878c48b9f82c55e43a105068269d29e1b6f02dc 100644 (file)
@@ -66,37 +66,38 @@ public class ColorControl {
        //methods
        def setColor(LinkedHashMap metaData) {
                def hexColor = metaData.hex
+               def newColor
                switch (hexColor) {
                        case "#0000FF":
-                               color = "Blue"
+                               newColor = "Blue"
                                break;
                        case "#00FF00":
-                               color = "Green"
+                               newColor = "Green"
                                break;
                        case "#FFFF00":
-                               color = "Yellow"
+                               newColor = "Yellow"
                                break;
                        case "#FF6000":
-                               color = "Orange"
+                               newColor = "Orange"
                                break;
                        case "#BF7FBF":
-                               color = "Purple"
+                               newColor = "Purple"
                                break;
                        case "#FF5F5F":
-                               color = "Pink"
+                               newColor = "Pink"
                                break;
                        case "#FF0000":
-                               color = "Red"
+                               newColor = "Red"
                                break;
                        default:
-                               color = "Blue"
+                               newColor = "Blue"
                                break;
                }
-               if (color != this.color) {
-                       this.currentColor = color
-                       this.color = color
-                       println("The color of the light is changed to $color!")
-                       sendEvent([name: "color", value: "$color", deviceId: this.id, descriptionText: "",
+               if (newColor != this.color) {
+                       this.currentColor = newColor
+                       this.color = newColor
+                       println("The color of the light is changed to $newColor!")
+                       sendEvent([name: "color", value: "$newColor", deviceId: this.id, descriptionText: "",
                                   displayed: true, linkText: "", isStateChange: false, unit: "", data: '{"info": "info"}'])
                }
        }
@@ -150,24 +151,20 @@ public class ColorControl {
                }
        }
 
-       def on(String currentSwitch) {
-               if (currentSwitch != this.currentSwitch) {
+       def on() {
+               if (this.currentSwitch != "on") {
                        this.currentSwitch = currentSwitch
-                       println("The light is changed to $currentSwitch!")
-                       sendEvent([name: "switch", value: "$currentSwitch", deviceId: this.id, descriptionText: "",
-                                  displayed: true, linkText: "", isStateChange: false, unit: "", data: '{"info": "info"}'])
-                       sendEvent([name: "switch.on", value: "$currentSwitch", deviceId: this.id, descriptionText: "",
+                       println("The light is changed to on!")
+                       sendEvent([name: "switch", value: "on", deviceId: this.id, descriptionText: "",
                                   displayed: true, linkText: "", isStateChange: false, unit: "", data: '{"info": "info"}'])
                }
        }
 
-       def off(String currentSwitch) {
-               if (currentSwitch != this.currentSwitch) {
+       def off() {
+               if (this.currentSwitch != "off") {
                        this.currentSwitch = currentSwitch
-                       println("The light is changed to $currentSwitch!")
-                       sendEvent([name: "switch", value: "$currentSwitch", deviceId: this.id, descriptionText: "",
-                                  displayed: true, linkText: "", isStateChange: false, unit: "", data: '{"info": "info"}'])
-                       sendEvent([name: "switch.off", value: "$currentSwitch", deviceId: this.id, descriptionText: "",
+                       println("The light is changed to off!")
+                       sendEvent([name: "switch", value: "off", deviceId: this.id, descriptionText: "",
                                   displayed: true, linkText: "", isStateChange: false, unit: "", data: '{"info": "info"}'])
                }
        }