Commit #3
[smartthings-infrastructure.git] / Switch / switching.groovy
index da2f30ce038ff082eb858bf01e57c9765981718c..bc74af6768f576f301a517099b0330c7ca3002bc 100644 (file)
@@ -4,8 +4,10 @@ package Switch
 public class switching{
        List switches
        int count
+       def Timers
 
        switching(int count) {
+               this.Timers = new Timer()
                this.count = count
                if (count == 1) {
                        switches = [new switches(0, "switch0", "off", "off")]
@@ -26,11 +28,13 @@ public class switching{
 
        def on(LinkedHashMap LHM) {
                if (count == 1) {
-                       sleep(LHM["delay"])
-                       switches[0].on()
+                       def task = Timers.runAfter(LHM["delay"]) {
+                               switches[0].on()
+                       }
                } else {
-                       sleep(LHM["delay"])
-                       switches*.on()
+                       def task = Timers.runAfter(LHM["delay"]) {
+                               switches*.on()
+                       }
                }
        }
 
@@ -44,11 +48,13 @@ public class switching{
 
        def off(LinkedHashMap LHM) {
                if (count == 1) {
-                       sleep(LHM["delay"])
-                       switches[0].off()
+                       def task = Timers.runAfter(LHM["delay"]) {
+                               switches[0].off()
+                       }
                } else {
-                       sleep(LHM["delay"])
-                       switches*.off()
+                       def task = Timers.runAfter(LHM["delay"]) {
+                               switches*.off()
+                       }
                }
        }