Merge branch 'master' of ssh://plrg.eecs.uci.edu/home/git/smartthings-infrastructure
[smartthings-infrastructure.git] / RelaySwitch / RelaySwitches.groovy
index d9615e2f8a64110f92506ee0b6999f2517e06a7d..e7b6e0080bd68b95e0d4a67f3cb214165e9076d0 100644 (file)
@@ -51,6 +51,9 @@ public class RelaySwitches {
        def find(Closure Input) {
                relaySwitches.find(Input)
        }
+       def sort(Closure Input) {
+               relaySwitches.sort(Input)
+       }
        def collect(Closure Input) {
                relaySwitches.collect(Input)
        }
@@ -58,40 +61,40 @@ public class RelaySwitches {
        //By Apps
        def on() {
                if (switchState != "on") {
-                       relaySwitches[0].on()
-                       switchLatestValue = switchState
+                       switchLatestValue = "on"
                        switchState = "on"
                        currentSwitch = "on"
+                       relaySwitches[0].on()
                }
        }
 
        def on(LinkedHashMap metaData) {
                if (switchState != "on") {
                        def task = timers.runAfter(metaData["delay"]) {
-                               relaySwitches[0].on()
-                               switchLatestValue = switchState
+                               switchLatestValue = "on"
                                switchState = "on"
                                currentSwitch = "on"
+                               relaySwitches[0].on()
                        }
                }
        }
 
        def off() {
                if (switchState != "off") {
-                       relaySwitches[0].off()
-                       switchLatestValue = switchState
+                       switchLatestValue = "off"
                        switchState = "off"
                        currentSwitch = "off"
+                       relaySwitches[0].off()
                }
        }
 
        def off(LinkedHashMap metaData) {
                if (switchState != "off") {
                        def task = timers.runAfter(metaData["delay"]) {
-                               relaySwitches[0].off()
-                               switchLatestValue = switchState
+                               switchLatestValue = "off"
                                switchState = "off"
                                currentSwitch = "off"
+                               relaySwitches[0].off()
                        }
                }
        }
@@ -99,9 +102,9 @@ public class RelaySwitches {
        //By Model Checker
        def setValue(LinkedHashMap eventDataMap) {
                if (eventDataMap["value"] != relaySwitches[0].switchState) {
+                       this.switchState = eventDataMap["value"]
+                       this.switchLatestValue = eventDataMap["value"]
                        relaySwitches[0].setValue(eventDataMap["value"])
-                       this.switchState = relaySwitches[0].switchState
-                       this.switchLatestValue = relaySwitches[0].switchLatestValue
                        sendEvent(eventDataMap)
                }
        }