add new option Wakeup timer
authorDima73 <Dima-73@inbox.lv>
Fri, 2 Oct 2015 16:59:02 +0000 (19:59 +0300)
committerDima73 <Dima-73@inbox.lv>
Fri, 2 Oct 2015 16:59:02 +0000 (19:59 +0300)
-choose for each day required time for wakeup box
-changed the logic  startup to standby for auto boot:
1)timers record/zap goto standby
2)plugins not standby, e.g. epgrefresh/xmlimport
3) wakeup timer and 'Startup to Standby' as 'No, except Wakeup timer'
goto standby

Navigation.py
lib/python/Components/UsageConfig.py
lib/python/Screens/SleepTimerEdit.py
mytest.py

index 90be794..8cf798c 100644 (file)
@@ -35,14 +35,21 @@ class Navigation:
                self.currentlyPlayingService = None
                self.RecordTimer = RecordTimer.RecordTimer()
                self.__wasTimerWakeup = getFPWasTimerWakeup()
+               startup_to_standby = config.usage.startup_to_standby.value
+               wakeup_time_type = config.misc.prev_wakeup_time_type.value
                if self.__wasTimerWakeup:
                        RecordTimer.RecordTimerEntry.setWasInDeepStandby()
                if config.misc.RestartUI.value:
                        config.misc.RestartUI.value = False
                        config.misc.RestartUI.save()
                        configfile.save()
-               elif config.usage.startup_to_standby.value or self.__wasTimerWakeup:
-                       Notifications.AddNotification(Screens.Standby.Standby)
+               elif startup_to_standby == "yes" or self.__wasTimerWakeup and config.misc.prev_wakeup_time.value and ((wakeup_time_type == 0 or wakeup_time_type == 1) or ( wakeup_time_type == 3 and startup_to_standby == "except")):
+                       if not Screens.Standby.inTryQuitMainloop:
+                               Notifications.AddNotification(Screens.Standby.Standby)
+               if config.misc.prev_wakeup_time.value:
+                       config.misc.prev_wakeup_time.value = 0
+                       config.misc.prev_wakeup_time.save()
+                       configfile.save()
 
        def wasTimerWakeup(self):
                return self.__wasTimerWakeup
index 6c5dac4..51aea8a 100644 (file)
@@ -1,5 +1,5 @@
 from Components.Harddisk import harddiskmanager
-from config import ConfigSubsection, ConfigYesNo, config, ConfigSelection, ConfigText, ConfigNumber, ConfigSet, ConfigLocations, ConfigSelectionNumber, ConfigClock, ConfigSlider
+from config import ConfigSubsection, ConfigYesNo, config, ConfigSelection, ConfigText, ConfigNumber, ConfigSet, ConfigLocations, ConfigSelectionNumber, ConfigClock, ConfigSlider, ConfigEnableDisable, ConfigSubDict, ConfigNothing
 from Tools.Directories import resolveFilename, SCOPE_HDD, defaultRecordingLocation
 from enigma import setTunerTypePriorityOrder, setPreferredTuner, setSpinnerOnOff, setEnableTtCachingOnOff, eEnv, eDVBDB, Misc_Options, eBackgroundFileEraser, eServiceEvent
 from Components.NimManager import nimmanager
@@ -119,7 +119,18 @@ def InitUsageConfig():
                ("intermediate", _("Intermediate")),
                ("expert", _("Expert")) ])
 
-       config.usage.startup_to_standby = ConfigYesNo(default = False)
+       config.usage.startup_to_standby = ConfigSelection(default = "no", choices = [
+               ("no", _("No")),
+               ("yes", _("Yes")),
+               ("except", _("No, except Wakeup timer")) ])
+
+       config.usage.wakeup_menu = ConfigNothing()
+       config.usage.wakeup_enabled = ConfigYesNo(default = False)
+       config.usage.wakeup_day = ConfigSubDict()
+       config.usage.wakeup_time = ConfigSubDict()
+       for i in range(7):
+               config.usage.wakeup_day[i] = ConfigEnableDisable(default = False)
+               config.usage.wakeup_time[i] = ConfigClock(default = ((6 * 60 + 0) * 60))
 
        config.usage.on_long_powerpress = ConfigSelection(default = "show_menu", choices = [
                ("show_menu", _("Show shutdown menu")),
index 77acb59..bb9cfe7 100644 (file)
@@ -7,7 +7,7 @@ from Components.Label import Label
 from Components.Sources.StaticText import StaticText
 from Components.config import config, getConfigListEntry
 from enigma import eEPGCache
-from time import time
+from time import time, localtime, mktime 
 
 class SleepTimerEdit(ConfigListScreen, Screen):
        def __init__(self, session):
@@ -83,10 +83,16 @@ class SleepTimerEdit(ConfigListScreen, Screen):
                                self.list.append(getConfigListEntry(_("End time to ignore shutdown in standby"),
                                        config.usage.standby_to_shutdown_timer_blocktime_end,
                                        _("Specify the end time to ignore the shutdown timer when the receiver is in standby mode")))
+               self.list.append(getConfigListEntry(_("Wakeup timer"),
+                       config.usage.wakeup_menu,
+                       _("Press OK and configure the days and times wakeup receiver from deep standby mode.")))
                self["config"].list = self.list
                self["config"].l.setList(self.list)
 
        def ok(self):
+               if self.getCurrentEntry() == _("Wakeup timer"):
+                       self.session.open(WakeupTimerEdit)
+                       return
                if self["config"].isChanged():
                        for x in self["config"].list:
                                x[1].save()
@@ -145,3 +151,101 @@ class SleepTimerEdit(ConfigListScreen, Screen):
                                        end = start + duration
                                        remaining = end - now
                return remaining + config.recording.margin_after.value * 60
+
+weekdays = [
+       _("Monday"),
+       _("Tuesday"),
+       _("Wednesday"),
+       _("Thursday"),
+       _("Friday"),
+       _("Saturday"),
+       _("Sunday"),
+       ]
+
+class WakeupTimerEdit(ConfigListScreen, Screen):
+       def __init__(self, session):
+               Screen.__init__(self, session)
+               self.skinName = ["WakeupTimerSetup", "Setup"]
+               self.setup_title = _("WakeupTimer Configuration")
+
+               self["key_red"] = StaticText(_("Cancel"))
+               self["key_green"] = StaticText(_("Save"))
+               self["description"] = Label("")
+
+               self.list = []
+               ConfigListScreen.__init__(self, self.list, session = session)
+               self.createSetup()
+
+               self["setupActions"] = ActionMap(["SetupActions", "ColorActions"],
+               {
+                   "green": self.ok,
+                   "red": self.cancel,
+                   "cancel": self.cancel,
+                   "ok": self.ok,
+               }, -2)
+
+               self.onLayoutFinish.append(self.layoutFinished)
+
+       def layoutFinished(self):
+               self.setTitle(self.setup_title)
+
+       def createSetup(self):
+               self.list = []
+               self.list.append(getConfigListEntry(_("Enable wakeup timer"),
+                       config.usage.wakeup_enabled,
+                       _("Note: when enabled, and you do want standby mode after wake up, set option 'Startup to Standby' as 'No, except Wakeup timer'.")))
+               if config.usage.wakeup_enabled.value:
+                       for i in range(7):
+                               self.list.append(getConfigListEntry(weekdays[i], config.usage.wakeup_day[i]))
+                               if config.usage.wakeup_day[i].value:
+                                       self.list.append(getConfigListEntry(_("Wakeup time"), config.usage.wakeup_time[i]))
+               self["config"].list = self.list
+               self["config"].l.setList(self.list)
+
+       def ok(self):
+               if self["config"].isChanged():
+                       for x in self["config"].list:
+                               x[1].save()
+               self.close()
+
+       def cancel(self, answer = None):
+               if answer is None:
+                       if self["config"].isChanged():
+                               self.session.openWithCallback(self.cancel, MessageBox, _("Really close without saving settings?"))
+                       else:
+                               self.close()
+               elif answer:
+                       for x in self["config"].list:
+                               x[1].cancel()
+                       self.close()
+
+       def keyLeft(self):
+               ConfigListScreen.keyLeft(self)
+               self.createSetup()
+
+       def keyRight(self):
+               ConfigListScreen.keyRight(self)
+               self.createSetup()
+
+def isNextWakeupTime():
+       if config.usage.wakeup_enabled.value:
+               wakeup_day, wakeup_time = WakeupDayTimeOfWeek()
+               if wakeup_day == -1:
+                               return -1
+               elif wakeup_day == 0:
+                       return wakeup_time
+               return wakeup_time + (86400 * wakeup_day)
+       return -1
+
+def WakeupDayTimeOfWeek():
+       now = localtime()
+       current_day = int(now.tm_wday)
+       if current_day >= 0:
+               if config.usage.wakeup_day[current_day].value:
+                       wakeup_time = int(mktime((now.tm_year, now.tm_mon, now.tm_mday, config.usage.wakeup_time[current_day].value[0], config.usage.wakeup_time[current_day].value[1], 0, now.tm_wday, now.tm_yday, now.tm_isdst)))
+                       if wakeup_time > time():
+                               return 0, wakeup_time
+               for i in range(1,8):
+                       if config.usage.wakeup_day[(current_day+i)%7].value:
+                               return i, int(mktime((now.tm_year, now.tm_mon, now.tm_mday, config.usage.wakeup_time[(current_day+i)%7].value[0], config.usage.wakeup_time[(current_day+i)%7].value[1], 0, now.tm_wday, now.tm_yday, now.tm_isdst)))
+       return -1, None
index 71d93dc..5098cf7 100644 (file)
--- a/mytest.py
+++ b/mytest.py
@@ -50,6 +50,10 @@ config.misc.startCounter = ConfigInteger(default=0) # number of e2 starts...
 config.misc.standbyCounter = NoSave(ConfigInteger(default=0)) # number of standby
 config.misc.DeepStandby = NoSave(ConfigYesNo(default=False)) # detect deepstandby
 config.misc.RestartUI = ConfigYesNo(default=False) # detect user interface restart
+config.misc.prev_wakeup_time = ConfigInteger(default=0)
+#config.misc.prev_wakeup_time_type is only valid when wakeup_time is not 0
+config.misc.prev_wakeup_time_type = ConfigInteger(default=0)
+# 0 = RecordTimer, 1 = ZapTimer, 2 = Plugins, 3 = WakeupTimer
 config.misc.epgcache_filename = ConfigText(default = "/hdd/epg.dat")
 
 def setEPGCachePath(configElement):
@@ -477,12 +481,14 @@ def runScreenTest():
        profile("wakeup")
        from time import time, strftime, localtime
        from Tools.StbHardware import setFPWakeuptime, getFPWakeuptime, setRTCtime
+       from Screens.SleepTimerEdit import isNextWakeupTime
        #get currentTime
        nowTime = time()
        wakeupList = [
                x for x in ((session.nav.RecordTimer.getNextRecordingTime(), 0),
                                        (session.nav.RecordTimer.getNextZapTime(isWakeup=True), 1),
-                                       (plugins.getNextWakeupTime(), 2))
+                                       (plugins.getNextWakeupTime(), 2),
+                                       (isNextWakeupTime(), 3))
                if x[0] != -1
        ]
        wakeupList.sort()
@@ -498,6 +504,12 @@ def runScreenTest():
                        setRTCtime(nowTime)
                print "set wakeup time to", strftime("%Y/%m/%d %H:%M", localtime(wptime))
                setFPWakeuptime(wptime)
+               config.misc.prev_wakeup_time.value = startTime[0]
+               config.misc.prev_wakeup_time_type.value = startTime[1]
+               config.misc.prev_wakeup_time_type.save()
+       else:
+               config.misc.prev_wakeup_time.value = 0
+       config.misc.prev_wakeup_time.save()
 
        profile("stopService")
        session.nav.stopService()