Add a method to SwitchLevel class!
[smartthings-infrastructure.git] / SwitchLevel / SwitchLevels.groovy
index 490e52dc66338184f01c8fef8b3a53a3098d3641..d9d2e267617a05943ffcc70f5eea37e0501cc240 100644 (file)
@@ -2,9 +2,6 @@
 package SwitchLevel
 import Timer.SimulatedTimer
 
-//JPF's Verify API
-import gov.nasa.jpf.vm.Verify
-
 public class SwitchLevels {
        int deviceNumbers       
        List switchLevels
@@ -17,29 +14,36 @@ public class SwitchLevels {
        private String displayName = "switchLevel0"
        private int level = 50
        private int rate = 50
-       private String switchState = "off"
-       private String currentSwitch = "off"
-       private String switchLatestValue = "off"
+       private int hue = 30
+       private int saturation = 70
+       private String switchState = "on"
+       private String currentSwitch = "on"
+       private String switchLatestValue = "on"
 
-       SwitchLevels(Closure sendEvent, int deviceNumbers) {
+       SwitchLevels(Closure sendEvent, int deviceNumbers, boolean init) {
                this.sendEvent = sendEvent
                this.timers = new SimulatedTimer()
                this.deviceNumbers = deviceNumbers
                this.switchLevels = []
 
-               /*def initLevel = Verify.getIntFromList(30, 50, 70)
-               this.level = initLevel
-               def init = Verify.getBoolean()
                if (init) {
+                       this.level = 50
+                       this.rate = 50
+                       this.hue = 30
+                       this.saturation = 70
                        this.switchState = "off"
                        this.currentSwitch = "off"
                        this.switchLatestValue = "off"
                } else {
+                       this.level = 60
+                       this.rate = 60
+                       this.hue = 50
+                       this.saturation = 90
                        this.switchState = "on"
                        this.currentSwitch = "on"
                        this.switchLatestValue = "on"
-               }*/
-               switchLevels.add(new SwitchLevel(sendEvent, id, label, displayName, this.level, this.switchState, this.switchLatestValue))
+               }
+               switchLevels.add(new SwitchLevel(sendEvent, id, label, displayName, this.level, this.hue, this.saturation, this.switchState, this.switchLatestValue))
        }
 
        //Methods for closures
@@ -63,6 +67,21 @@ public class SwitchLevels {
        }
 
        //By Apps
+       def setColor(LinkedHashMap metaData) {
+               if ((this.level != metaData["level"]) || (this.hue != metaData["hue"]) || (this.saturation != metaData["saturation"])) {
+                       this.level = metaData["level"]
+                       this.rate = metaData["level"]
+                       this.hue = metaData["hue"]
+                       this.saturation = metaData["saturation"]
+                       switchLevels[0].setColor(metaData)
+               }
+       }
+       
+       def setLevel(String level) {
+               def newLevel = level.toInteger()
+               setLevel(newLevel)
+       }
+
        def setLevel(int level) {
                if (this.level != level) {
                        switchLevels[0].setLevel(level)
@@ -70,6 +89,14 @@ public class SwitchLevels {
                        this.rate = level
                }
        }
+       
+       def setLevel(long level) {
+               if (this.level != level) {
+                       switchLevels[0].setLevel(level)
+                       this.level = level
+                       this.rate = level
+               }
+       }
 
        def on() {
                switchLatestValue = "on"
@@ -123,6 +150,15 @@ public class SwitchLevels {
                }
        }
 
+       def currentValue(String deviceFeature) {
+               switchLevels[0].currentValue(deviceFeature)
+       }
+       
+       def latestValue(String deviceFeature) {
+               switchLevels[0].latestValue(deviceFeature)
+       }
+       
+
        def getAt(int ix) {
                switchLevels[ix]
        }