Commit #3
[smartthings-infrastructure.git] / Switch / switches.groovy
index 359248d9734b584feddbc65002d28e5acbc6dc43..34ebe8ea09f478c3071deb98fde2602a47fd91bd 100644 (file)
@@ -6,8 +6,10 @@ public class switches {
        private String displayName
        private String currentSwitch
        private String switchLatestValue
+       def Timers
 
        switches(int id, String displayName, String currentSwitch, String switchLatestValue) {
+               this.Timers = new Timer()
                this.id = id
                this.displayName = displayName
                this.currentSwitch = currentSwitch
@@ -21,10 +23,11 @@ public class switches {
        }
 
        def on(LinkedHashMap LHM) {
-               sleep(LHM["delay"])
-               println("the switch with id:$id is on!")
-               this.switchLatestValue = this.currentSwitch
-               this.currentSwitch = "on"
+               def task = Timers.runAfter(LHM["delay"]) {
+                       println("the switch with id:$id is on!")
+                       this.switchLatestValue = this.currentSwitch
+                       this.currentSwitch = "on"
+               }
        }
 
        def off() {
@@ -34,10 +37,11 @@ public class switches {
        }
 
        def off(LinkedHashMap LHM) {
-               sleep(LHM["delay"])
-               println("the switch with id:$id is off!")
-               this.switchLatestValue = this.currentSwitch
-               this.currentSwitch = "off"
+               def task = Timers.runAfter(LHM["delay"]) {
+                       println("the switch with id:$id is off!")
+                       this.switchLatestValue = this.currentSwitch
+                       this.currentSwitch = "off"
+               }
        }
        
        def currentValue(String S) {