Merge branch 'master' of ssh://plrg.eecs.uci.edu/home/git/smartthings-infrastructure
[smartthings-infrastructure.git] / ColorControl / ColorControls.groovy
index 39dfeaa8ab3c8d3a3fb84a4bc269c82a07f0e309..5b29f55e54eb51d83ebe1e13a7d8f0545eeff57b 100644 (file)
@@ -15,10 +15,13 @@ public class ColorControls {
        private String label = "colorControl0"
        private String displayName = "colorControl0"
        private String color = "red"
+       private String currentSwitch = "off"
+       private int level = 50
        private int hue = 50
        private int saturation = 50
+       private int colorTemperature = 15000
        
-               
+
        ColorControls(Closure sendEvent, int deviceNumbers) {
                this.sendEvent = sendEvent
                this.deviceNumbers = deviceNumbers
@@ -37,7 +40,7 @@ public class ColorControls {
                        this.color = "blue"
                }*/
 
-               colorControls.add(new ColorControl(id, label, displayName, this.color, this.hue, this.saturation))
+               colorControls.add(new ColorControl(id, label, displayName, this.color, this.hue, this.saturation, this.level, this.currentSwitch, this.colorTemperature))
        }
 
        //Methods for closures
@@ -53,6 +56,9 @@ public class ColorControls {
        def find(Closure Input) {
                colorControls.find(Input)
        }
+       def sort(Closure Input) {
+               colorControls.sort(Input)
+       }
        def collect(Closure Input) {
                colorControls.collect(Input)
        }
@@ -61,20 +67,38 @@ public class ColorControls {
        def setValue(LinkedHashMap eventDataMap) {
                if (eventDataMap["name"] == "color") {
                        if (eventDataMap["value"] != colorControls[0].color) {
+                               this.color = eventDataMap["value"]
                                colorControls[0].setValue(eventDataMap["value"], "color")
-                               this.color = colorControls[0].color
                                sendEvent(eventDataMap)
                        }       
                } else if (eventDataMap["name"] == "hue") {
-                       if (eventDataMap["value"] != colorControls[0].hue) {
+                       if (eventDataMap["value"].toInteger() != colorControls[0].hue) {
+                               this.hue = eventDataMap["value"].toInteger()
                                colorControls[0].setValue(eventDataMap["value"], "hue")
-                               this.hue = colorControls[0].hue
                                sendEvent(eventDataMap)
                        }
-               } else {
-                       if (eventDataMap["value"] != colorControls[0].saturation) {
+               } else if (eventDataMap["name"] == "saturation") {
+                       if (eventDataMap["value"].toInteger() != colorControls[0].saturation) {
+                               this.saturation = eventDataMap["value"].toInteger()
                                colorControls[0].setValue(eventDataMap["value"], "saturation")
-                               this.saturation = colorControls[0].saturation
+                               sendEvent(eventDataMap)
+                       }
+               } else if (eventDataMap["name"] == "switch") {
+                       if (eventDataMap["value"] != colorControls[0].currentSwitch) {
+                               this.currentSwitch = eventDataMap["value"]
+                               colorControls[0].setValue(eventDataMap["value"], "switch")
+                               sendEvent(eventDataMap)
+                       }
+               } else if (eventDataMap["name"] == "colorTemperature") {
+                       if (eventDataMap["value"].toInteger() != colorControls[0].colorTemperature) {
+                               this.colorTemperature = eventDataMap["value"].toInteger()
+                               colorControls[0].setValue(eventDataMap["value"], "colorTemperature")
+                               sendEvent(eventDataMap)
+                       }
+               } else if (eventDataMap["name"] == "level") {
+                       if (eventDataMap["value"].toInteger() != colorControls[0].level) {
+                               this.level = eventDataMap["value"].toInteger()
+                               colorControls[0].setValue(eventDataMap["value"], "level")
                                sendEvent(eventDataMap)
                        }
                }
@@ -84,29 +108,61 @@ public class ColorControls {
        //methods
        def setColor(String color) {
                if (color != this.color) {
-                       colorControls[0].setColor(color)
                        this.color = color
+                       colorControls[0].setColor(color)                        
                }
        }
 
        def setHue(int hue) {
-               if (hue != this.hue) {          
+               if (hue != this.hue) {
+                       this.hue = hue  
                        colorControls[0].setHue(hue)
-                       this.hue = hue
                }
        }
 
        def setSaturation(int saturation) {
                if (saturation != this.saturation) {
-                       colorControls[0].setSaturation(saturation)
                        this.saturation = saturation
+                       colorControls[0].setSaturation(saturation)                      
                }       
        }
 
+       def setLevel(int level) {
+               if (level != this.level) {
+                       this.level = level
+                       colorControls[0].setLevel(level)
+               }
+       }
+
+       def setColorTemperature(String colorTemperature) {
+               if (colorTemperature != this.colorTemperature) {
+                       this.colorTemperature = colorTemperature
+                       colorControls[0].setColorTemperature(colorTemperature)                  
+               }
+       }
+
+       def on(String currentSwitch) {
+               if (currentSwitch != this.currentSwitch) {
+                       this.currentSwitch = currentSwitch
+                       colorControls[0].on(currentSwitch)                      
+               }
+       }
+
+       def off(String currentSwitch) {
+               if (currentSwitch != this.currentSwitch) {
+                       this.currentSwitch = currentSwitch
+                       colorControls[0].off(currentSwitch)                     
+               }
+       }
+
        def currentValue(String deviceFeature) {
                colorControls[0].currentValue(deviceFeature)
        }
 
+       def latestValue(String deviceFeature) {
+               colorControls[0].latestValue(deviceFeature)
+       }       
+
        def getAt(int ix) {
                colorControls[ix]
        }