Improvements and new methods
[smartthings-infrastructure.git] / Methods / schedule.groovy
index be935b8efdda6196c475c14a7b732699194f0ab5..f4fcf24cc318f2eeebd4d666a5612bb836666948 100644 (file)
@@ -1,11 +1,11 @@
 /////////////////////////////////////////////////////////////////////
 ////schedule(time, nameOfFunction as String)
 def schedule(String time, String nameOfFunction) {
-       def _inputTime = time.split(':')
+       /*def _inputTime = time.split(':')
        Date date = new Date()  
        def _currentTime = date.format("HH:mm:ss").split(':')
 
-       //Convert input time and current time to minutes
+       Convert input time and current time to minutes
        def inputTime = Integer.parseInt(_inputTime[0])*3600+Integer.parseInt(_inputTime[1])*60
        def currentTime = Integer.parseInt(_currentTime[0])*3600+Integer.parseInt(_currentTime[1])*60+Integer.parseInt(_currentTime[2])
        def delay
@@ -15,20 +15,25 @@ def schedule(String time, String nameOfFunction) {
        } else {
                delay = inputTime-currentTime
        }
-
        timersFuncList.add(nameOfFunction)
        timersList.add(new SimulatedTimer())
-       def task = timersList[timersFuncList.indexOf(nameOfFunction)].runAfter(delay*1000) {
+       def task = timersList[timersFuncList.indexOf(nameOfFunction)].runAfter(delay*1000*0) {
                "$nameOfFunction"()
-       }
+       }*/
+       "$nameOfFunction"()
+}
+/////////////////////////////////////////////////////////////////////
+////schedule(Date, nameOfFunction as String)
+def schedule(Date date, String nameOfFunction) {
+       "$nameOfFunction"()
 }
 ////schedule(time, nameOfFunction as Closure)
 def schedule(String time, Closure nameOfFunction) {
-       def _inputTime = time.split(':')
+       /*def _inputTime = time.split(':')
        Date date = new Date()  
        def _currentTime = date.format("HH:mm:ss").split(':')
 
-       //Convert input time and current time to minutes
+       Convert input time and current time to minutes
        def inputTime = Integer.parseInt(_inputTime[0])*3600+Integer.parseInt(_inputTime[1])*60
        def currentTime = Integer.parseInt(_currentTime[0])*3600+Integer.parseInt(_currentTime[1])*60+Integer.parseInt(_currentTime[2])
        def delay
@@ -41,10 +46,11 @@ def schedule(String time, Closure nameOfFunction) {
 
        if (timersFuncList.contains(nameOfFunction)) {
                timersList[timersFuncList.indexOf(nameOfFunction)].cancel()
-               def task = timersList[timersFuncList.indexOf(nameOfFunction)].runAfter(delay*seconds, nameOfFunction)
+               def task = timersList[timersFuncList.indexOf(nameOfFunction)].runAfter(0, nameOfFunction)
        } else {
                timersFuncList.add(nameOfFunction)
                timersList.add(new SimulatedTimer())
-               def task = timersList[timersFuncList.indexOf(nameOfFunction)].runAfter(delay*seconds, nameOfFunction)
-       }
+               def task = timersList[timersFuncList.indexOf(nameOfFunction)].runAfter(0, nameOfFunction)
+       }*/
+       nameOfFunction()
 }