Merge remote-tracking branch 'origin/master'
[enigma2-plugins.git] / elektro / src / plugin.py
1 #
2 # Power Save Plugin by gutemine
3 # Rewritten by Morty (morty@gmx.net)
4 # HDD Mod by joergm6
5 #
6 # Deep standby will be called sleep. Normal standby will be named standby!
7 # All calculations are in the local timezone, or in the relative Timezone.
8 # In the relative timezone the day starts at "nextday". If it is before nextday the last day will be used.
9 #
10 #
11
12
13 #from enigma import *
14 from __init__ import _
15
16 from Screens.InfoBarGenerics import *
17 # from RecordTimer import *
18
19
20 import calendar 
21 #################
22
23 # Plugin
24 from Plugins.Plugin import PluginDescriptor
25
26 # GUI (Screens)
27 from Screens.Screen import Screen
28 from Components.ConfigList import ConfigListScreen
29 from Screens.MessageBox import MessageBox
30 from Screens.Console import Console
31 from Screens import Standby 
32
33 # GUI (Summary)
34 # from Screens.Setup import SetupSummary
35
36 # GUI (Components)
37 from Components.ActionMap import ActionMap
38 from Components.Button import Button
39 from Components.Language import language
40 from Components.Harddisk import harddiskmanager
41 from Components.Sources.StaticText import StaticText
42
43 # Configuration
44 from Components.config import getConfigListEntry, ConfigEnableDisable, \
45         ConfigYesNo, ConfigText, ConfigClock, ConfigNumber, ConfigSelection, \
46         config, ConfigSubsection, ConfigSubList, ConfigSubDict
47
48 # Startup/shutdown notification
49 from Tools import Notifications
50
51 import os
52 # Timer, etc
53
54 #import time
55 from time import localtime, asctime, time, gmtime
56 # import datetime
57 # import codecs
58
59
60 # Enigma system functions
61 from enigma import quitMainloop, eTimer
62
63
64 # import Wakeup?!
65 from Tools.DreamboxHardware import getFPWasTimerWakeup
66
67 ###############################################################################
68
69 # Globals
70 pluginPrintname = "[Elektro]"
71 debug = False # If set True, plugin will print some additional status info to track logic flow
72 session = None
73 ElektroWakeUpTime = -1
74 elektro_pluginversion = "3.4.2"
75 elektro_readme = "/usr/lib/enigma2/python/Plugins/Extensions/Elektro/readme.txt"
76 elektro_readme_de  = "/usr/lib/enigma2/python/Plugins/Extensions/Elektro/readme-de.txt"
77 elektrostarttime = 60 
78 elektrosleeptime = 5
79 elektroShutdownThreshold = 60 * 20
80 ###############################################################################
81
82 #Configuration
83 if debug:
84         print pluginPrintname, "Setting config defaults"
85 config.plugins.elektro = ConfigSubsection()
86 config.plugins.elektro.nextday = ConfigClock(default = ((6 * 60 + 0) * 60) )
87
88 config.plugins.elektro.sleep = ConfigSubDict()
89 for i in range(7):
90         config.plugins.elektro.sleep[i] = ConfigClock(default = ((1 * 60 + 0) * 60) )
91
92 config.plugins.elektro.wakeup = ConfigSubDict()
93 for i in range(7):
94         config.plugins.elektro.wakeup[i] = ConfigClock(default = ((9 * 60 + 0) * 60) )
95
96 config.plugins.elektro.name = ConfigText(default = _("Elektro Power Save"), fixed_size = False, visible_width = 20)
97 config.plugins.elektro.description = ConfigText(default = _("Automatically shut down to deep standby"), fixed_size = False, visible_width = 80)
98 config.plugins.elektro.menu = ConfigSelection(default = "plugin", choices = [("plugin", _("Plugin menu")), ("extensions", _("Extensions menu"))])
99 config.plugins.elektro.enable = ConfigEnableDisable(default = False)
100 config.plugins.elektro.standbyOnBoot = ConfigYesNo(default = False)
101 config.plugins.elektro.standbyOnManualBoot = ConfigYesNo(default = True)
102 config.plugins.elektro.standbyOnBootTimeout = ConfigNumber(default = 60)
103 config.plugins.elektro.nextwakeup = ConfigNumber(default = 0)
104 config.plugins.elektro.force = ConfigYesNo(default = False)
105 config.plugins.elektro.dontwakeup = ConfigEnableDisable(default = False)
106 config.plugins.elektro.holiday =  ConfigEnableDisable(default = False)
107 config.plugins.elektro.hddsleep =  ConfigYesNo(default = False)
108
109
110
111 weekdays = [
112         _("Monday"),
113         _("Tuesday"),
114         _("Wednesday"),
115         _("Thursday"),
116         _("Friday"),
117         _("Saturday"),
118         _("Sunday"),
119         ]
120
121
122 #global ElektroWakeUpTime
123 ElektroWakeUpTime = -1
124
125 def autostart(reason, **kwargs):
126         global session  
127         if reason == 0 and kwargs.has_key("session"):
128                 session = kwargs["session"]
129                 session.open(DoElektro)
130
131 def getNextWakeup():
132         global ElektroWakeUpTime
133         
134         #it might happen, that session does not exist. I don't know why. :-(
135         if session is None:
136                 return ElektroWakeUpTime;
137         
138         nextTimer = session.nav.RecordTimer.getNextRecordingTime()
139         print pluginPrintname, "Now:", strftime("%a:%H:%M:%S",  gmtime(time()))
140         if (nextTimer < 1) or (nextTimer > ElektroWakeUpTime):
141                 print pluginPrintname, "Will wake up", strftime("%a:%H:%M:%S",  gmtime(ElektroWakeUpTime))
142                 return ElektroWakeUpTime
143         
144         #We have to make sure, that the Box will wake up because of us
145         # and not because of the timer
146         print pluginPrintname, "Will wake up due to the next timer", strftime("%a:%H:%M:%S",  gmtime(nextTimer))
147         return nextTimer - 1
148            
149         
150         
151         
152 def Plugins(**kwargs):
153         if debug:
154                 print pluginPrintname, "Setting entry points"
155         list = [
156                 PluginDescriptor(
157                         name = config.plugins.elektro.name.value, 
158                         description = config.plugins.elektro.description.value + " "  + _("Ver.") + " " + elektro_pluginversion, 
159                         where = [
160                                 PluginDescriptor.WHERE_SESSIONSTART, 
161                                 PluginDescriptor.WHERE_AUTOSTART
162                         ], 
163                         fnc = autostart, 
164                         wakeupfnc = getNextWakeup)
165                 ]
166         if config.plugins.elektro.menu.value == "plugin":
167                 list.append (PluginDescriptor(
168                         name = config.plugins.elektro.name.value, 
169                         description = config.plugins.elektro.description.value + " "  + _("Ver.") + " " + elektro_pluginversion, 
170                         where = PluginDescriptor.WHERE_PLUGINMENU, 
171                         icon = "elektro.png", 
172                         fnc=main)
173                 )
174         else:
175                 list.append (PluginDescriptor(
176                         name = config.plugins.elektro.name.value, 
177                         description = config.plugins.elektro.description.value + " "  + _("Ver.") + " " + elektro_pluginversion, 
178                         where = PluginDescriptor.WHERE_EXTENSIONSMENU, 
179                         fnc=main)
180                 )               
181         
182         return list
183
184         
185 def main(session,**kwargs):
186         try:    
187                 session.open(Elektro)
188         except:
189                 print pluginPrintname, "Pluginexecution failed"
190
191 class Elektro(ConfigListScreen,Screen):
192         skin = """
193                 <screen name ="Elektro" position="center,center" size="630,480" title="Elektro Power Save" >
194                         <widget name="key_red" position="4,5" size="140,40" valign="center" halign="center" zPosition="4"  foregroundColor="white" font="Regular;18" transparent="1"/> 
195                         <widget name="key_green" position="165,5" size="140,40" valign="center" halign="center" zPosition="4"  foregroundColor="white" font="Regular;18" transparent="1"/> 
196                         <widget name="key_yellow" position="325,5" size="140,40" valign="center" halign="center" zPosition="4"  foregroundColor="white" font="Regular;18" transparent="1"/>
197                         
198                         <ePixmap name="red"    position="5,5"   zPosition="2" size="140,40" pixmap="skin_default/buttons/red.png" transparent="1" alphatest="on" />
199                         <ePixmap name="green"  position="165,5" zPosition="2" size="140,40" pixmap="skin_default/buttons/green.png" transparent="1" alphatest="on" />
200                         <ePixmap name="yellow" position="325,5" zPosition="2" size="140,40" pixmap="skin_default/buttons/yellow.png" transparent="1" alphatest="on" /> 
201                         
202                         <widget name="config" position="5,50" size="620,275" scrollbarMode="showOnDemand" />            
203                          
204                         <ePixmap pixmap="skin_default/div-h.png" position="0,330" zPosition="1" size="630,2" />
205                         <widget source="help" render="Label" position="5,335" size="620,153" font="Regular;21" />                                       
206                 </screen>""" 
207                                         
208                 
209         def __init__(self, session, args = 0):
210                 self.session = session
211                 Screen.__init__(self, session)
212                 if debug:
213                         print pluginPrintname, "Displays config screen"                 
214
215                 self.onChangedEntry = []
216                 
217                 self.list = [   
218                         getConfigListEntry(_("Show in"), config.plugins.elektro.menu,
219                                 _("Specify whether plugin shall show up in plugin menu or extensions menu (needs GUI restart)")),
220                         getConfigListEntry(_("Name"), config.plugins.elektro.name,
221                                 _("Specify plugin name to be used in menu (needs GUI restart).")),
222                         getConfigListEntry(_("Description"), config.plugins.elektro.description,
223                                 _("Specify plugin description to be used in menu (needs GUI restart).")),               
224                         getConfigListEntry(_("Enable Elektro Power Save"),config.plugins.elektro.enable,
225                                 _("Unless this is enabled, this plugin won't run automatically.")),                                                     
226                         getConfigListEntry(_("Standby on boot"), config.plugins.elektro.standbyOnBoot,
227                                 _("Puts the box in standby mode after boot.")),
228                         getConfigListEntry(_("Standby on manual boot"), config.plugins.elektro.standbyOnManualBoot,
229                                 _("Whether to put the box in standby when booted manually. On manual boot the box will not go to standby before the next deep standby interval starts, even if this option is set. This option is only active if 'Standby on boot' option is set, too.")),
230                         getConfigListEntry(_("Standby on boot screen timeout"), config.plugins.elektro.standbyOnBootTimeout,
231                                 _("Specify how long to show the standby query on boot screen. This value can be set to ensure the box does not shut down to deep standby again too fast when in standby mode.")),
232                         getConfigListEntry(_("Force sleep (even when not in standby)"), config.plugins.elektro.force,
233                                 _("Forces deep standby, even when not in standby mode. Scheduled recordings remain unaffected.")),
234                         getConfigListEntry(_("Avoid deep standby when HDD is active, e.g. for FTP"), config.plugins.elektro.hddsleep,
235                                 _("Wait for the HDD to enter sleep mode. Depending on the configuration this can prevent the box entirely from entering deep standby mode.")),
236                         getConfigListEntry(_("Don't wake up"), config.plugins.elektro.dontwakeup,
237                                 _("Do not wake up at the end of next deep standby interval.")),
238                         getConfigListEntry(_("Holiday mode (experimental)"), config.plugins.elektro.holiday,
239                                 _("The box always enters deep standby mode, except for recording.")),
240                         getConfigListEntry(_("Next day starts at"), config.plugins.elektro.nextday,
241                                 _("If the box is supposed to enter deep standby e.g. monday night at 1 AM, it actually is already tuesday. To enable this anyway, differing next day start time can be specified here.")),
242                         ]               
243                                 
244                 for i in range(7):
245                         self.list.append(getConfigListEntry(weekdays[i] + ": "  + _("Wakeup"), config.plugins.elektro.wakeup[i], " "))
246                         self.list.append(getConfigListEntry(weekdays[i] + ": "  + _("Sleep"), config.plugins.elektro.sleep[i], " "))
247                         
248                 ConfigListScreen.__init__(self, self.list, session = session, on_change = self.changed)
249                 
250                 def selectionChanged():
251                         if self["config"].current:
252                                 self["config"].current[1].onDeselect(self.session)
253                         self["config"].current = self["config"].getCurrent()
254                         if self["config"].current:
255                                 self["config"].current[1].onSelect(self.session)
256                         for x in self["config"].onSelectionChanged:
257                                 x()
258                                 
259                 self["config"].selectionChanged = selectionChanged
260                 self["config"].onSelectionChanged.append(self.configHelp)
261                 
262                 self["key_red"] = Button(_("Cancel"))
263                 self["key_green"] = Button(_("Ok"))
264                 self["key_yellow"] = Button(_("Help"))
265                 self["help"] = StaticText()
266                 
267                 self["setupActions"] = ActionMap(["SetupActions", "ColorActions"],
268                 {
269                         "red": self.keyCancel,
270                         "green": self.keySave,
271                         "yellow": self.help,
272                         "save": self.keySave,
273                         "cancel": self.keyCancel,
274                         "ok": self.keySave,
275                 }, -2)
276                 
277                 # Trigger change
278                 self.changed()
279
280                 self.onLayoutFinish.append(self.setCustomTitle)
281
282         def setCustomTitle(self):
283                 self.setTitle(config.plugins.elektro.name.value + " "  + _("Ver.") + " " + elektro_pluginversion)
284
285         def configHelp(self):
286                 cur = self["config"].getCurrent()
287                 self["help"].text = cur[2]
288
289         def changed(self):
290                 for x in self.onChangedEntry:
291                         try:
292                                 x()
293                         except Exception:
294                                 pass    
295                         
296         def getCurrentEntry(self):
297                 return self["config"].getCurrent()[0]
298
299         def getCurrentValue(self):
300                 return str(self["config"].getCurrent()[1].getText())
301                 
302         def help(self):
303                 if language.getLanguage()[:2] == "de":
304                         self.session.open(Console,_("Showing Elektro readme.txt"),["cat %s" % elektro_readme_de])
305                 else:
306                         self.session.open(Console,_("Showing Elektro readme.txt"),["cat %s" % elektro_readme])
307
308 class DoElektro(Screen):
309         skin = """ <screen position="center,center" size="300,300" title="Elektro Plugin Menu" > </screen>"""
310         
311         def __init__(self,session):
312                 Screen.__init__(self,session)
313                 
314                 print pluginPrintname, "Starting up Version", elektro_pluginversion
315                 
316                 self.session = session
317                 
318                 # Make sure wakeup time is set.
319                 self.setNextWakeuptime()
320                 
321                 # If we didn't wake up by a timer we don't want to go to sleep any more.
322                 # Unforturnately it is not possible to use getFPWasTimerWakeup()
323                 # Therfore we're checking wheter there is a recording starting within
324                 # the next five min             
325                 self.dontsleep = False
326                 
327                 #Let's assume we got woken up manually
328                 timerWakeup = False
329                 
330                 #Is a recording already runniong ->woken up by a timer
331                 if self.session.nav.RecordTimer.isRecording():
332                         timerWakeup = True
333                 # Is the next timer within 5 min -> woken up by a timer 
334                 if abs(self.session.nav.RecordTimer.getNextRecordingTime() - time()) <= 360:
335                         timerWakeup = True
336                         
337                 # Did we wake up by Elektro?
338                 # Let's hope this get's run early enaugh, and this get's run
339                 # before the requested wakeup-time (should be the case)
340                 #
341                 if abs(ElektroWakeUpTime - time()) <= 360:
342                         timerWakeup = True      
343                         
344                 # If the was a manual wakeup: Don't go to sleep 
345                 if timerWakeup == False:
346                         self.dontsleep = True
347                 
348                 
349                 #Check whether we should try to sleep:
350                 trysleep = config.plugins.elektro.standbyOnBoot.value
351                 
352                 #Don't go to sleep when this was a manual wakeup and the box shouldn't go to standby
353                 if timerWakeup == False and     config.plugins.elektro.standbyOnManualBoot.value == False:
354                         trysleep = False
355                         
356         
357                 #if waken up by timer and configured ask whether to go to sleep.
358                 if trysleep:
359                         self.TimerStandby = eTimer()
360                         self.TimerStandby.callback.append(self.CheckStandby)
361                         self.TimerStandby.startLongTimer(elektrosleeptime)
362                         print pluginPrintname, "Set up standby timer"
363
364                 self.TimerSleep = eTimer()
365                 self.TimerSleep.callback.append(self.CheckElektro)
366                 self.TimerSleep.startLongTimer(elektrostarttime)
367                 print pluginPrintname, "Set up sleep timer"             
368                 if debug:
369                         print pluginPrintname, "Translation test:", _("Standby on boot")
370                 
371         def clkToTime(self, clock):
372                 return ( (clock.value[0]) * 60 + (int)(clock.value[1]) )  * 60
373                 
374         def getTime(self):
375                 ltime = localtime();
376                 return ( (int)(ltime.tm_hour) * 60 + (int)(ltime.tm_min) ) * 60
377         
378         def getPrintTime(self, secs):
379                 return strftime("%H:%M:%S", gmtime(secs))
380
381         
382         # This function converts the time into the relative Timezone where the day starts at "nextday"
383         # This is done by substracting nextday from the current time. Negative times are corrected using the mod-operator
384         def getReltime(self, time):
385                 nextday = self.clkToTime(config.plugins.elektro.nextday)
386                 return (time - nextday) %  (24 * 60 * 60)
387                 
388         
389         def CheckStandby(self):
390                 print pluginPrintname, "Showing Standby Sceen"
391                 try:
392                         self.session.openWithCallback(self.DoElektroStandby,MessageBox,_("Go to Standby now?"),type = MessageBox.TYPE_YESNO,
393                                         timeout = config.plugins.elektro.standbyOnBootTimeout.value)            
394                 except:
395                         # Couldn't be shown. Restart timer.
396                         print pluginPrintname, "Failed Showing Standby Sceen "
397                         self.TimerStandby.startLongTimer(elektrostarttime)
398
399
400         def DoElektroStandby(self,retval):
401                 if (retval):
402                         #Yes, go to sleep
403                         Notifications.AddNotification(Standby.Standby)
404                 
405
406                         
407         def setNextWakeuptime(self):
408                 # Do not set a wakeup time if
409                 #  - Elektro isn't enabled
410                 #  - Elektro shouldn't wake up
411                 #  - Holiday mode is turned on
412                 if ((config.plugins.elektro.enable.value == False) 
413                       or (config.plugins.elektro.dontwakeup.value == True)
414                       or config.plugins.elektro.holiday.value == True): 
415                         global ElektroWakeUpTime
416                         ElektroWakeUpTime = -1
417                         return
418                         
419                 time_s = self.getTime()
420                 ltime = localtime()
421                 
422                 #print pluginPrintname, "Nextday:", time.ctime(self.clkToTime(config.plugins.elektro.nextday))
423                 # If it isn't past next-day time we need yesterdays settings
424                 if time_s < self.clkToTime(config.plugins.elektro.nextday):
425                         day = (ltime.tm_wday - 1) % 7
426                 else:
427                         day = ltime.tm_wday
428                 
429                 #Check whether we wake up today or tomorrow
430                 # Relative Time is needed for this
431                 time_s = self.getReltime(time_s)
432                 wakeuptime = self.getReltime(self.clkToTime(config.plugins.elektro.wakeup[day]))
433                 
434                 # Lets see if we already woke up today
435                 if wakeuptime < time_s:
436                         #yes we did -> Next wakeup is tomorrow
437                         if debug:                       
438                                 print pluginPrintname, "Wakeup tomorrow"
439                         day = (day + 1) % 7
440                         wakeuptime = self.getReltime(self.clkToTime(config.plugins.elektro.wakeup[day]))
441                 
442                 # Tomorrow we'll wake up erly-> Add a full day.
443                 if wakeuptime < time_s:
444                         wakeuptime = wakeuptime + 24 * 60 * 60
445                 
446                 # The next wakeup will be in wakupin seconds
447                 wakeupin = wakeuptime - time_s
448                 
449                 # Now add this to the current time to get the wakeuptime
450                 wakeuptime = (int)(time()) + wakeupin
451                 
452                 #Write everything to the global variable
453                 ElektroWakeUpTime = wakeuptime
454                         
455                         
456         def CheckElektro(self):
457                 # first set the next wakeuptime - it would be much better to call that function on sleep. This will be a todo!
458                 self.setNextWakeuptime()
459         
460                 #convert to seconds
461                 time_s = self.getTime()
462                 ltime = localtime()
463                 
464                 print pluginPrintname, "Testtime;", self.getPrintTime(2 * 60 * 60)
465                 
466                 #Which day is it? The next day starts at nextday
467                 if debug:
468                         print pluginPrintname, "wday 1:", str(ltime.tm_wday)
469                 if time_s < self.clkToTime(config.plugins.elektro.nextday):
470                         day = (ltime.tm_wday - 1) % 7
471                 else:
472                         day = ltime.tm_wday
473                 if debug:       
474                         print pluginPrintname, "wday 2:", str(day)
475                 
476                 #Let's get the day
477                 wakeuptime = self.clkToTime(config.plugins.elektro.wakeup[day])
478                 sleeptime = self.clkToTime(config.plugins.elektro.sleep[day])
479                 print pluginPrintname, "Current time:", self.getPrintTime(time_s)
480                 print pluginPrintname, "Wakeup time:", self.getPrintTime(wakeuptime)
481                 print pluginPrintname, "Sleep time:", self.getPrintTime(sleeptime)
482                 
483                 #convert into relative Times
484                 time_s = self.getReltime(time_s)
485                 wakeuptime  = self.getReltime(wakeuptime)
486                 sleeptime = self.getReltime(sleeptime)
487                 
488                 if debug:
489                         print pluginPrintname, "Current Rel-time:", self.getPrintTime(time_s)
490                         print pluginPrintname, "Wakeup Rel-time:", self.getPrintTime(wakeuptime)
491                         print pluginPrintname, "Sleep Rel-time:", self.getPrintTime(sleeptime)
492                 
493                 
494                 #let's see if we should be sleeping
495                 trysleep = False
496                 if time_s < (wakeuptime - elektroShutdownThreshold): # Wakeup is in the future -> sleep!
497                         trysleep = True
498                         print pluginPrintname, "Wakeup!", str(time_s), " <", str(wakeuptime)
499                 if sleeptime < time_s : #Sleep is in the past -> sleep!
500                         trysleep = True
501                         print pluginPrintname, "Sleep:", str(sleeptime), " <", str(time_s)
502                 
503                 #We are not tying to go to sleep anymore -> maybe go to sleep again the next time
504                 if trysleep == False:
505                         self.dontsleep = False
506                 
507                 #The User aborted to got to sleep -> Don't go to sleep.
508                 if self.dontsleep:
509                         trysleep = False
510                         
511                 # If we are in holydaymode we should try to got to sleep anyway
512                 # This should be set after self.dontsleep has been handled
513                 if config.plugins.elektro.holiday.value:
514                         trysleep = True
515                 
516                 # We are not enabled -> Dont go to sleep (This could have been catched earlier!)
517                 if config.plugins.elektro.enable.value == False:
518                         trysleep = False
519                 
520                 # Only go to sleep if we are in standby or sleep is forced by settings
521                 if  not ((Standby.inStandby) or (config.plugins.elektro.force.value == True) ):
522                         trysleep = False
523                 
524                 # No Sleep while recording
525                 if self.session.nav.RecordTimer.isRecording():
526                         trysleep = False
527                 
528                 # No Sleep on HDD running - joergm6
529                 if (config.plugins.elektro.hddsleep.value == True) and (harddiskmanager.HDDCount() > 0):
530                         hddlist = harddiskmanager.HDDList()
531                         if not hddlist[0][1].isSleeping():
532                                 trysleep = False
533                 
534                 # Will there be a recording in a short while?
535                 nextRecTime = self.session.nav.RecordTimer.getNextRecordingTime()
536                 if  (nextRecTime > 0) and (nextRecTime - (int)(time()) <  elektroShutdownThreshold):
537                         trysleep = False
538                         
539                 # Looks like there really is a reason to go to sleep -> Lets try it!
540                 if trysleep:
541                         #self.();
542                         try:
543                                 self.session.openWithCallback(self.DoElektroSleep, MessageBox, _("Go to sleep now?"),type = MessageBox.TYPE_YESNO,timeout = 60) 
544                         except:
545                                 #reset the timer and try again
546                                 self.TimerSleep.startLongTimer(elektrostarttime) 
547                                 
548                 #set Timer, which calls this function again.
549                 self.TimerSleep.startLongTimer(elektrostarttime) 
550                 
551                 
552
553
554         def DoElektroSleep(self,retval):
555                 if (retval):
556                         # os.system("wall 'Powermanagent does Deepsleep now'")
557                         #  Notifications.AddNotification(TryQuitMainloop,1)
558                         # 1 = Deep Standby -> enigma2:/doc/RETURNCODES
559                         
560                         global inTryQuitMainloop
561                         if Standby.inTryQuitMainloop == False:
562                                 self.session.open(Standby.TryQuitMainloop, 1) # <- This might not work reliably
563                                 #quitMainloop(1)
564                 else:
565                         # Dont try to sleep until next wakeup
566                         self.dontsleep = True
567                         #Start the timer again
568                         self.TimerSleep.startLongTimer(elektrostarttime) 
569