Fixing bugs in infrastructure
[smartthings-infrastructure.git] / ColorControl / ColorControls.groovy
index d96b978d774579c4f7efcb2519d86d8b4adb9985..d17f9e4333f94e02c8fb85fb361b0b0bee28afea 100644 (file)
 //Create a class for color control
 package ColorControl
-import Timer.SimulatedTimer
+import SmartThing.SmartThings
 
-//JPF's Verify API
-import gov.nasa.jpf.vm.Verify
-
-public class ColorControls {
-       private int deviceNumbers
-       private List colorControls
-       def sendEvent
-
-       //For one device(We cannot have obj.id)-> We should have obj[0].id
-       private String id = "colorControlID0"
-       private String label = "colorControl0"
-       private String displayName = "colorControl0"
-       private String color = "red"
-       private int hue = 50
-       private int saturation = 50
+public class ColorControls extends SmartThings {
+       List colorControls = new ArrayList()
        
-               
-       ColorControls(Closure sendEvent, int deviceNumbers) {
-               this.sendEvent = sendEvent
-               this.deviceNumbers = deviceNumbers
-               this.colorControls = []
+       ColorControls(Closure sendEvent, boolean init) {
+               // Only initialize one time since we only have one device for each capability
+               colorControls = smartThings
+
+               // Initialization
+               String id = "colorControlID0"
+               String label = "colorControl"
+               String displayName = "light"
+               String color
+               Integer hue
+               Integer saturation
 
-               def initHue = Verify.getIntFromList(30, 50, 70)
-               this.hue = initHue
-               def initSat = Verify.getIntFromList(40, 50, 60)
-               this.saturation = initSat
-               def init = Verify.getInt(0,2)
-               if (init == 0) {
-                       this.color = "red"
-               } else if (init == 1) {
-                       this.color = "green"
-               } else {
-                       this.color = "blue"
+               if (init) {
+                       color = "Red"
+                       hue = 30
+                       saturation = 40
+               } else {                
+                       color = "Blue"
+                       hue = 50
+                       saturation = 50
                }
 
-               colorControls.add(new ColorControl(id, label, displayName, this.color, this.hue, this.saturation))
+               colorControls.add(new ColorControl(sendEvent, id, label, displayName, color, hue,
+                                                  saturation))
        }
 
-       //Methods for closures
-       def count(Closure Input) {
-               colorControls.count(Input)
-       }
-       def size() {
-               colorControls.size()
-       }
-       def each(Closure Input) {
-               colorControls.each(Input)
-       }
-       def find(Closure Input) {
-               colorControls.find(Input)
-       }
-       def collect(Closure Input) {
-               colorControls.collect(Input)
+       // Methods to set values
+       def setColor(LinkedHashMap metaData) {
+               colorControls[0].setColor(metaData)
        }
 
-       //By model checker
-       def setValue(LinkedHashMap eventDataMap) {
-               if (eventDataMap["name"] == "color") {
-                       if (eventDataMap["value"] != colorControls[0].color) {
-                               colorControls[0].setValue(eventDataMap["value"], "color")
-                               this.color = colorControls[0].color
-                               sendEvent(eventDataMap)
-                       }       
-               } else if (eventDataMap["name"] == "hue") {
-                       if (eventDataMap["value"] != colorControls[0].hue) {
-                               colorControls[0].setValue(eventDataMap["value"], "hue")
-                               this.hue = colorControls[0].hue
-                               sendEvent(eventDataMap)
-                       }
-               } else {
-                       if (eventDataMap["value"] != colorControls[0].saturation) {
-                               colorControls[0].setValue(eventDataMap["value"], "saturation")
-                               this.saturation = colorControls[0].saturation
-                               sendEvent(eventDataMap)
-                       }
-               }
-       }
-
-
-       //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) {          
-                       colorControls[0].setHue(hue)
-                       this.hue = hue
-               }
+               colorControls[0].setHue(hue)
+       }
+       
+       def setHue(double hue) {
+               colorControls[0].setHue((int) hue)
        }
 
        def setSaturation(int saturation) {
-               if (saturation != this.saturation) {
-                       colorControls[0].setSaturation(saturation)
-                       this.saturation = saturation
-               }       
+               colorControls[0].setSaturation(saturation)      
+       }
+       
+       def setSaturation(double saturation) {
+               colorControls[0].setSaturation((int) saturation)
        }
 
-       def currentValue(String deviceFeature) {
-               colorControls[0].currentValue(deviceFeature)
+       def on() {
+               colorControls[0].on()
        }
 
-       def getAt(int ix) {
-               colorControls[ix]
+       def off() {
+               colorControls[0].off()
        }
 }