a minor bug in schedule method!
[smartthings-infrastructure.git] / Methods / schedule.groovy
1 /////////////////////////////////////////////////////////////////////
2 ////schedule(time, nameOfFunction as String)
3 def schedule(String time, String nameOfFunction) {
4         //def _inputTime = time.split(':')
5         //Date date = new Date()        
6         //def _currentTime = date.format("HH:mm:ss").split(':')
7
8         //Convert input time and current time to minutes
9         //def inputTime = Integer.parseInt(_inputTime[0])*3600+Integer.parseInt(_inputTime[1])*60
10         //def currentTime = Integer.parseInt(_currentTime[0])*3600+Integer.parseInt(_currentTime[1])*60+Integer.parseInt(_currentTime[2])
11         //def delay
12
13         //if (inputTime < currentTime) {
14         //      delay = 24*60*60-inputTime+currentTime
15         //} else {
16         //      delay = inputTime-currentTime
17         //}
18         timersFuncList.add(nameOfFunction)
19         timersList.add(new SimulatedTimer())
20         def task = timersList[timersFuncList.indexOf(nameOfFunction)].runAfter(/*delay*1000*0*/0) {
21                 "$nameOfFunction"()
22         }
23 }
24 ////schedule(time, nameOfFunction as Closure)
25 def schedule(String time, Closure nameOfFunction) {
26         //def _inputTime = time.split(':')
27         //Date date = new Date()        
28         //def _currentTime = date.format("HH:mm:ss").split(':')
29
30         //Convert input time and current time to minutes
31         //def inputTime = Integer.parseInt(_inputTime[0])*3600+Integer.parseInt(_inputTime[1])*60
32         //def currentTime = Integer.parseInt(_currentTime[0])*3600+Integer.parseInt(_currentTime[1])*60+Integer.parseInt(_currentTime[2])
33         //def delay
34
35         //if (inputTime < currentTime) {
36         //      delay = 24*60*60-inputTime+currentTime
37         //} else {
38         //      delay = inputTime-currentTime
39         //}
40
41         if (timersFuncList.contains(nameOfFunction)) {
42                 timersList[timersFuncList.indexOf(nameOfFunction)].cancel()
43                 def task = timersList[timersFuncList.indexOf(nameOfFunction)].runAfter(/*delay*0*/0, nameOfFunction0)
44         } else {
45                 timersFuncList.add(nameOfFunction)
46                 timersList.add(new SimulatedTimer())
47                 def task = timersList[timersFuncList.indexOf(nameOfFunction)].runAfter(/*delay*0*/0, nameOfFunction)
48         }
49 }