Merge branch 'master' of ssh://plrg.eecs.uci.edu/home/git/smartthings-infrastructure
[smartthings-infrastructure.git] / Switch / Switches.groovy
index 8c57869b54aadf78c3271ebc78409fc401f18cdf..5a2754042f05a585db006b4cf0326bcc38e457af 100644 (file)
@@ -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)
                }
        }