use bit operations instead of power
[vuplus_dvbapp] / SleepTimer.py
index 891cd25..221e8f0 100644 (file)
@@ -9,6 +9,10 @@ from Components.config import config, ConfigYesNo, ConfigSelection, ConfigSubsec
 from Screens.MessageBox import MessageBox
 import Screens.Standby
 
+config.SleepTimer = ConfigSubsection()
+config.SleepTimer.ask = ConfigYesNo(default = True)
+config.SleepTimer.action = ConfigSelection(default = "shutdown", choices = [("shutdown", _("shutdown")), ("standby", _("standby"))])
+
 class SleepTimerEntry(timer.TimerEntry):
        def __init__(self, begin):
                timer.TimerEntry.__init__(self, int(begin), int(begin))
@@ -45,29 +49,26 @@ class SleepTimerEntry(timer.TimerEntry):
                if answer is not None:
                        if answer and not Screens.Standby.inStandby:
                                Notifications.AddNotification(Screens.Standby.Standby)
-               
+
 class SleepTimer(timer.Timer):
        def __init__(self):
-               config.SleepTimer = ConfigSubsection()
-               config.SleepTimer.ask = ConfigYesNo(default = True)
-               config.SleepTimer.action = ConfigSelection(default = "shutdown", choices = [("shutdown", _("shutdown")), ("standby", _("standby"))])
-               
                timer.Timer.__init__(self)
                self.defaultTime = 30
-               
+
        def setSleepTime(self, sleeptime):
                self.clear()
                self.addTimerEntry(SleepTimerEntry(time.time() + 60 * sleeptime))
 
        def clear(self):
                self.timer_list = []
-               
+
        def getCurrentSleepTime(self):
-               if (self.getNextRecordingTime() == -1):
-                       return self.defaultTime
-               return int(math.ceil((self.getNextRecordingTime() - time.time()) / 60))
+               llen = len(self.timer_list)
+               idx = 0
+               while idx < llen:
+                       timer = self.timer_list[idx]
+                       return int(math.ceil((timer.begin - time.time()) / 60))
+               return self.defaultTime
 
        def isActive(self):
                return len(self.timer_list) > 0
-       
-       
\ No newline at end of file