use magic instead of readable code
[enigma2.git] / timer.py
index c8e7854992418f9cdf1eaaa7c395838e9ad53ec7..c03eb1e78d3fae37087230733ff138cf03377f51 100644 (file)
--- a/timer.py
+++ b/timer.py
@@ -16,6 +16,8 @@ class TimerEntry:
                self.resetRepeated()
                self.backoff = 0
                
+               self.disabled = False
+               
        def resetRepeated(self):
                self.repeated = int(0)
 
@@ -53,6 +55,9 @@ class TimerEntry:
                                print time.strftime("%c", time.localtime(self.end))
                                self.begin += 86400
                                self.end += 86400
+                       
+                       self.timeChanged()
+                       
 
        def __lt__(self, o):
                return self.getNextActivation() < o.getNextActivation()
@@ -102,9 +107,14 @@ class Timer:
                self.lastActivation = time.time()
                
                self.calcNextActivation()
+               self.on_state_change = [ ]
        
        def stateChanged(self, entry):
-               pass
+               for f in self.on_state_change:
+                       f(entry)
+                       
+       def cleanup(self):
+               self.processed_timers = [entry for entry in self.processed_timers if entry.disabled]
        
        def addTimerEntry(self, entry, noRecalc=0):
                entry.processRepeated()
@@ -112,7 +122,7 @@ class Timer:
                # when the timer has not yet started, and is already passed,
                # don't go trough waiting/running/end-states, but sort it
                # right into the processedTimers.
-               if entry.shouldSkip() or entry.state == TimerEntry.StateEnded:
+               if entry.shouldSkip() or entry.state == TimerEntry.StateEnded or (entry.state == TimerEntry.StateWaiting and entry.disabled):
                        print "already passed, skipping"
                        bisect.insort(self.processed_timers, entry)
                        entry.state = TimerEntry.StateEnded
@@ -178,7 +188,7 @@ class Timer:
                        bisect.insort(self.timer_list, w)
                else:
                        # yes. Process repeated, and re-add.
-                       if not w.repeated:
+                       if w.repeated:
                                w.processRepeated()
                                w.state = TimerEntry.StateWaiting
                                self.addTimerEntry(w)