Adding missing method.
[smartthings-infrastructure.git] / ColorControl / ColorControls.groovy
index 4919ebe463070dc97715f5b96e18678b6aab086f..9b003f6189301780896e68525c7b74ecaf455566 100644 (file)
@@ -2,9 +2,6 @@
 package ColorControl
 import Timer.SimulatedTimer
 
-//JPF's Verify API
-import gov.nasa.jpf.vm.Verify
-
 public class ColorControls {
        private int deviceNumbers
        private List colorControls
@@ -14,8 +11,8 @@ public class ColorControls {
        private String id = "colorControlID0"
        private String label = "colorControl0"
        private String displayName = "colorControl0"
-       private String color = "red"
-       private String currentColor = "red"
+       private String color = "Red"
+       private String currentColor = "Red"
        private String currentSwitch = "on"
        private int level = 50
        private int currentLevel = 50
@@ -24,30 +21,35 @@ public class ColorControls {
        private int saturation = 50
        private int currentSaturation = 50
        private int colorTemperature = 15000
+       private boolean colorChanged = false
        
 
-       ColorControls(Closure sendEvent, int deviceNumbers) {
+       ColorControls(Closure sendEvent, int deviceNumbers, boolean init) {
                this.sendEvent = sendEvent
                this.deviceNumbers = deviceNumbers
                this.colorControls = []
 
-               /*def initHue = Verify.getIntFromList(30, 50)
-               this.hue = initHue
-               def initSat = Verify.getIntFromList(40, 50)
-               this.saturation = initSat
-               def initColor = Verify.getBoolean()
-               if (initColor) {
-                       this.color = "red"
-               } else {
-                       this.color = "blue"
-               }
-               def init = Verify.getBoolean()
                if (init) {
+                       this.level = 20
+                       this.currentLevel = 20
+                       this.hue = 30
+                       this.currentHue = 30
+                       this.saturation = 40
+                       this.currentSaturation = 40
+                       this.colorTemperature = 10000
+                       this.color = "Red"
                        this.currentSwitch = "off"
                } else {
+                       this.level = 50
+                       this.currentLevel = 50
+                       this.hue = 50
+                       this.currentHue = 50
+                       this.saturation = 50
+                       this.currentSaturation = 50
+                       this.colorTemperature = 15000
+                       this.color = "Blue"
                        this.currentSwitch = "on"
-               }*/
-
+               }
                colorControls.add(new ColorControl(sendEvent, id, label, displayName, this.color, this.hue, this.saturation, this.level, this.currentSwitch, this.colorTemperature))
        }
 
@@ -120,36 +122,54 @@ public class ColorControls {
        //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
-                       colorControls[0].setColor(color)                        
+               if (newColor != this.color) {
+                       this.currentColor = newColor
+                       this.color = newColor
+                       colorControls[0].setColor(newColor)
+                       if (this.colorChanged) {
+                               this.colorChanged = false
+                       } else {
+                               this.colorChanged = true
+                       }
+               }
+               def newLevel = metaData.level
+               def newHue = metaData.hue
+               def newSaturation = metaData.saturation
+               if (newLevel != null) {
+                       setLevel(newLevel)
+               }
+               if (newHue != null) {
+                       setHue(newHue)
+               }
+               if (newSaturation != null) {
+                       setSaturation(newSaturation)
                }
        }
 
@@ -192,17 +212,24 @@ public class ColorControls {
                }
        }
 
-       def on(String currentSwitch) {
-               if (currentSwitch != this.currentSwitch) {
-                       this.currentSwitch = currentSwitch
-                       colorControls[0].on(currentSwitch)                      
+       def setColorTemperature(long colorTemperature) {
+               if (colorTemperature != this.colorTemperature) {
+                       this.colorTemperature = colorTemperature
+                       colorControls[0].setColorTemperature(colorTemperature)                  
+               }
+       }
+
+       def on() {
+               if (this.currentSwitch != "on") {
+                       this.currentSwitch = "on"
+                       colorControls[0].on()                   
                }
        }
 
-       def off(String currentSwitch) {
-               if (currentSwitch != this.currentSwitch) {
-                       this.currentSwitch = currentSwitch
-                       colorControls[0].off(currentSwitch)                     
+       def off() {
+               if (this.currentSwitch != "off") {
+                       this.currentSwitch = "off"
+                       colorControls[0].off()
                }
        }