Adding missing methods; rearranging initial values.
[smartthings-infrastructure.git] / ColorControl / ColorControl.groovy
index a65afbb78e2630ccdf969b096c611a08cf1335f1..f24d274ad61ed0bf98736a9e1d5679e3378ab099 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"}'])
                }
        }
@@ -120,6 +121,16 @@ public class ColorControl {
                                   displayed: true, linkText: "", isStateChange: false, unit: "", data: '{"info": "info"}'])
                }
        }
+       
+       def setHue(double hue) {
+               if (hue != this.hue) {
+                       this.hue = hue
+                       this.currentHue = 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) {
                if (saturation != this.saturation) {
@@ -130,6 +141,17 @@ public class ColorControl {
                                   displayed: true, linkText: "", isStateChange: false, unit: "", data: '{"info": "info"}'])
                }
        }
+       
+       def setSaturation(double saturation) {
+               if (saturation != this.saturation) {
+                       this.currentSaturation = 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 setLevel(int level) {
                if (level != this.level) {
@@ -141,6 +163,16 @@ public class ColorControl {
                }
        }
 
+       def setLevel(long level) {
+               if (level != this.level) {
+                       this.currentLevel = level
+                       this.level = level
+                       println("The level of the light is changed to $level!")
+                       sendEvent([name: "level", value: "$level", deviceId: this.id, descriptionText: "",
+                                  displayed: true, linkText: "", isStateChange: false, unit: "", data: '{"info": "info"}'])
+               }
+       }
+
        def setColorTemperature(int colorTemperature) {
                if (colorTemperature != this.colorTemperature) {
                        this.colorTemperature = colorTemperature
@@ -156,8 +188,6 @@ public class ColorControl {
                        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"}'])
-                       sendEvent([name: "switch.on", value: "on", deviceId: this.id, descriptionText: "",
-                                  displayed: true, linkText: "", isStateChange: false, unit: "", data: '{"info": "info"}'])
                }
        }
 
@@ -167,8 +197,6 @@ public class ColorControl {
                        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"}'])
-                       sendEvent([name: "switch.off", value: "off", deviceId: this.id, descriptionText: "",
-                                  displayed: true, linkText: "", isStateChange: false, unit: "", data: '{"info": "info"}'])
                }
        }