Removing more third-party apps; fixing more bugs.
[smartthings-infrastructure.git] / Switch / Switches.groovy
index 8c57869b54aadf78c3271ebc78409fc401f18cdf..a13030a7d71a216344c9edb2fa50677d4189c5fd 100644 (file)
@@ -26,10 +26,10 @@ public class Switches {
                this.deviceNumbers = deviceNumbers
                this.switches = []
 
-               /*def initLevel = Verify.getIntFromList(30, 50, 70)
+               def initLevel = Verify.getIntFromList(30, 50, 70)
                this.currentLevel = initLevel
                def init = Verify.getBoolean()
-               if (init) {
+               /*if (init) {
                        this.switchState = "off"
                        this.currentSwitch = "off"
                        this.switchLatestValue = "off"
@@ -55,54 +55,57 @@ public class Switches {
        def find(Closure Input) {
                switches.find(Input)
        }
+       def sort(Closure Input) {
+               switches.sort(Input)
+       }
        def collect(Closure Input) {
                switches.collect(Input)
        }
 
        //By Apps
        def setLevel(int level) {
-               switches[0].setLevel(level)
                currentLevel = level
+               switches[0].setLevel(level)
        }
 
        def on() {
-               switches[0].on()
-               switchLatestValue = switchState
+               switchLatestValue = "on"
                switchState = "on"
                currentSwitch = "on"
+               switches[0].on()
        }
 
        def on(LinkedHashMap metaData) {
                def task = timers.runAfter(metaData["delay"]) {
-                       switches[0].on()
-                       switchLatestValue = switchState
+                       switchLatestValue = "on"
                        switchState = "on"
                        currentSwitch = "on"
+                       switches[0].on()
                }
        }
 
        def off() {
-               switches[0].off()
-               switchLatestValue = switchState
+               switchLatestValue = "off"
                switchState = "off"
                currentSwitch = "off"
+               switches[0].off()
        }
 
        def off(LinkedHashMap metaData) {
                def task = timers.runAfter(metaData["delay"]) {
-                       switches[0].off()
-                       switchLatestValue = switchState
+                       switchLatestValue = "off"
                        switchState = "off"
                        currentSwitch = "off"
+                       switches[0].off()
                }
        }
 
        //By Model Checker
        def setValue(LinkedHashMap eventDataMap) {
                if (eventDataMap["value"] != switches[0].switchState) {
+                       this.switchState = eventDataMap["value"]
+                       this.switchLatestValue = eventDataMap["value"]
                        switches[0].setValue(eventDataMap["value"])
-                       this.switchState = switches[0].switchState
-                       this.switchLatestValue = switches[0].switchLatestValue
                        sendEvent(eventDataMap)
                }
        }