Skip to content

Commit

Permalink
Merge remote-tracking branch 'e2/master'
Browse files Browse the repository at this point in the history
Conflicts:
	elektro/src/plugin.py
	epgrefresh/src/EPGRefresh.py
  • Loading branch information
Andy Blackburn committed Aug 25, 2013
2 parents 82c207b + adeaef9 commit 7def28e
Show file tree
Hide file tree
Showing 8 changed files with 108 additions and 138 deletions.
1 change: 0 additions & 1 deletion Makefile.am
Expand Up @@ -40,7 +40,6 @@ SUBDIRS = \
infobartunerstate \
internetradio \
kiddytimer \
lastfm \
letterbox \
mediadownloader \
merlinepg \
Expand Down
98 changes: 29 additions & 69 deletions elektro/src/plugin.py
Expand Up @@ -14,8 +14,8 @@
from __init__ import _

from Screens.InfoBarGenerics import *
# from RecordTimer import *

from RecordTimer import RecordTimerEntry

import calendar
#################
Expand Down Expand Up @@ -43,7 +43,7 @@
# Configuration
from Components.config import configfile, getConfigListEntry, ConfigEnableDisable, \
ConfigYesNo, ConfigText, ConfigClock, ConfigNumber, ConfigSelection, \
config, ConfigSubsection, ConfigSubList, ConfigSubDict, ConfigIP
config, ConfigSubsection, ConfigSubList, ConfigSubDict, ConfigIP, ConfigInteger

# Startup/shutdown notification
from Tools import Notifications
Expand Down Expand Up @@ -76,8 +76,8 @@
debug = False # If set True, plugin will print some additional status info to track logic flow
session = None
ElektroWakeUpTime = -1
elektro_pluginversion = "3.4.5a"
elektrostarttime = 60
elektro_pluginversion = "3.4.5b"
elektrostarttime = 60
elektrosleeptime = 5
elektroShutdownThreshold = 60 * 20
###############################################################################
Expand Down Expand Up @@ -117,13 +117,13 @@
config.plugins.elektro.enable = ConfigEnableDisable(default = False)
config.plugins.elektro.standbyOnBoot = ConfigYesNo(default = False)
config.plugins.elektro.standbyOnManualBoot = ConfigYesNo(default = True)
config.plugins.elektro.standbyOnBootTimeout = ConfigNumber(default = 60)
config.plugins.elektro.nextwakeup = ConfigNumber(default = 0)
config.plugins.elektro.force = ConfigYesNo(default = False)
config.plugins.elektro.dontwakeup = ConfigEnableDisable(default = False)
config.plugins.elektro.holiday = ConfigEnableDisable(default = False)
config.plugins.elektro.hddsleep = ConfigYesNo(default = False)
config.plugins.elektro.IPenable = ConfigYesNo(default = False)
config.plugins.elektro.deepstandby_wakeup_time = ConfigInteger(default = 0)

config.plugins.elektro.NASenable = ConfigSelection(choices = [("false", "no"), ("true", "yes"), ("1", _("yes, Profile 1")), ("2", _("yes, Profile 2"))], default="false")
config.plugins.elektro.NASname = ConfigText(default = "", fixed_size = False, visible_width = 50)
Expand Down Expand Up @@ -190,20 +190,19 @@ def autostart(reason, **kwargs):
def getNextWakeup():
global ElektroWakeUpTime

#it might happen, that session does not exist. I don't know why. :-(
if session is None:
return ElektroWakeUpTime;
wakeuptime = 0

nextTimer = session.nav.RecordTimer.getNextRecordingTime()
print pluginPrintname, "Now:", strftime("%a:%H:%M:%S", gmtime(time()))
if (nextTimer < 1) or (nextTimer > ElektroWakeUpTime):
print pluginPrintname, "Will wake up", strftime("%a:%H:%M:%S", gmtime(ElektroWakeUpTime))
return ElektroWakeUpTime
now = time()
print pluginPrintname, "Now:", strftime("%a:%H:%M:%S", gmtime(now))

#We have to make sure, that the Box will wake up because of us
# and not because of the timer
print pluginPrintname, "Will wake up due to the next timer", strftime("%a:%H:%M:%S", gmtime(nextTimer))
return nextTimer - 1
if ElektroWakeUpTime > now:
print pluginPrintname, "Will wake up at", strftime("%a:%H:%M:%S", gmtime(ElektroWakeUpTime))
wakeuptime = ElektroWakeUpTime

config.plugins.elektro.deepstandby_wakeup_time.value = wakeuptime
config.plugins.elektro.deepstandby_wakeup_time.save()

return wakeuptime or -1

def Plugins(**kwargs):
if debug:
Expand Down Expand Up @@ -467,8 +466,6 @@ def __init__(self, session, args = 0):
_("Puts the box in standby mode after boot.")),
getConfigListEntry(_("Standby on manual boot"), config.plugins.elektro.standbyOnManualBoot,
_("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.")),
getConfigListEntry(_("Standby on boot screen timeout"), config.plugins.elektro.standbyOnBootTimeout,
_("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.")),
getConfigListEntry(_("Force sleep (even when not in standby)"), config.plugins.elektro.force,
_("Forces deep standby, even when not in standby mode. Scheduled recordings remain unaffected.")),
getConfigListEntry(_("Avoid deep standby when HDD is active, e.g. for FTP"), config.plugins.elektro.hddsleep,
Expand Down Expand Up @@ -575,45 +572,30 @@ def __init__(self,session):
# If we didn't wake up by a timer we don't want to go to sleep any more.
# Unforturnately it is not possible to use getFPWasTimerWakeup()
# Therfore we're checking wheter there is a recording starting within
# the next five min
# the next five min

automatic_wakeup = self.session.nav.wasTimerWakeup() # woken by any timer

self.dontsleep = False

#Let's assume we got woken up manually
timerWakeup = False

#Is a recording already runniong ->woken up by a timer
if self.session.nav.RecordTimer.isRecording():
timerWakeup = True
# Is the next timer within 5 min -> woken up by a timer
if abs(self.session.nav.RecordTimer.getNextRecordingTime() - time()) <= 360:
timerWakeup = True

# Did we wake up by Elektro?
# Let's hope this get's run early enaugh, and this get's run
# before the requested wakeup-time (should be the case)
#
if abs(ElektroWakeUpTime - time()) <= 360:
timerWakeup = True
timerWakeup = automatic_wakeup

# If the was a manual wakeup: Don't go to sleep
if timerWakeup == False:
self.dontsleep = True


#Check whether we should try to sleep:
trysleep = config.plugins.elektro.standbyOnBoot.value

#Don't go to sleep when this was a manual wakeup and the box shouldn't go to standby
if timerWakeup == False and config.plugins.elektro.standbyOnManualBoot.value == False:
if timerWakeup == False and config.plugins.elektro.standbyOnManualBoot.value == False:
trysleep = False


#if waken up by timer and configured ask whether to go to sleep.
if trysleep:
self.TimerStandby = eTimer()
self.TimerStandby.callback.append(self.CheckStandby)
self.TimerStandby.startLongTimer(elektrosleeptime)
print pluginPrintname, "Set up standby timer"
print pluginPrintname, "add standby notification"
Notifications.AddNotificationWithID("Standby", Standby.Standby)

self.TimerSleep = eTimer()
self.TimerSleep.callback.append(self.CheckElektro)
Expand All @@ -632,7 +614,6 @@ def getTime(self):
def getPrintTime(self, secs):
return strftime("%H:%M:%S", gmtime(secs))


# This function converts the time into the relative Timezone where the day starts at "nextday"
# This is done by substracting nextday from the current time. Negative times are corrected using the mod-operator
def getReltime(self, time):
Expand All @@ -642,24 +623,6 @@ def getReltime(self, time):
nextday = self.clkToTime(config.plugins.elektro.nextday2)
return (time - nextday) % (24 * 60 * 60)


def CheckStandby(self):
print pluginPrintname, "Showing Standby Sceen"
try:
self.session.openWithCallback(self.DoElektroStandby,MessageBox,_("Go to Standby now?"),type = MessageBox.TYPE_YESNO,
timeout = config.plugins.elektro.standbyOnBootTimeout.value)
except:
# Couldn't be shown. Restart timer.
print pluginPrintname, "Failed Showing Standby Sceen "
self.TimerStandby.startLongTimer(elektrostarttime)


def DoElektroStandby(self,retval):
if (retval):
#Yes, go to sleep
Notifications.AddNotification(Standby.Standby)


def setNextWakeuptime(self):
# Do not set a wakeup time if
# - Elektro isn't enabled
Expand Down Expand Up @@ -841,17 +804,14 @@ def DoElektroSleep(self,retval):
config.plugins.elektro.profile.save()
self.setNextWakeuptime()
if (retval):
# os.system("wall 'Powermanagent does Deepsleep now'")
# Notifications.AddNotification(TryQuitMainloop,1)
# 1 = Deep Standby -> enigma2:/doc/RETURNCODES

global inTryQuitMainloop
if Standby.inTryQuitMainloop == False:
if not Standby.inTryQuitMainloop:
if config.plugins.elektro.NASenable.value == "true" or config_NASenable:
ret = NASpowerdown(config.plugins.elektro.NASname.value, config.plugins.elektro.NASuser.value, config.plugins.elektro.NASpass.value, config.plugins.elektro.NAScommand.value, config.plugins.elektro.NASport.value)
configfile.save()
self.session.open(Standby.TryQuitMainloop, 1) # <- This might not work reliably
#quitMainloop(1)
if Standby.inStandby:
RecordTimerEntry.TryQuitMainloop()
else:
Notifications.AddNotificationWithID("Shutdown", Standby.TryQuitMainloop, 1)
else:
# Dont try to sleep until next wakeup
self.dontsleep = True
Expand Down
14 changes: 9 additions & 5 deletions epgrefresh/src/EPGRefresh.py
Expand Up @@ -10,6 +10,8 @@
# ...
from ServiceReference import ServiceReference

from RecordTimer import RecordTimerEntry

# Timer
from EPGRefreshTimer import epgrefreshtimer, EPGRefreshTimerEntry, checkTimespan

Expand Down Expand Up @@ -310,11 +312,13 @@ def finish(self, *args, **kwargs):


# shutdown if we're supposed to go to deepstandby and not recording
if not self.forcedScan and config.plugins.epgrefresh.afterevent.value and not Screens.Standby.inTryQuitMainloop:
self.session.open(
Screens.Standby.TryQuitMainloop,
1
)
if not self.forcedScan and config.plugins.epgrefresh.afterevent.value \
and not Screens.Standby.inTryQuitMainloop:

if Screens.Standby.inStandby:
RecordTimerEntry.TryQuitMainloop()
else:
Notifications.AddNotificationWithID("Shutdown", Screens.Standby.TryQuitMainloop, 1)

def refresh(self):
if self.forcedScan:
Expand Down
66 changes: 20 additions & 46 deletions epgrefresh/src/plugin.py
Expand Up @@ -5,7 +5,7 @@

# Config
from Components.config import config, ConfigYesNo, ConfigNumber, \
ConfigSelection, ConfigSubsection, ConfigClock, ConfigYesNo
ConfigSelection, ConfigSubsection, ConfigClock, ConfigYesNo, ConfigInteger

# Calculate default begin/end
from time import time, localtime, mktime
Expand Down Expand Up @@ -42,6 +42,8 @@
)
config.plugins.epgrefresh.show_in_extensionsmenu = ConfigYesNo(default = False)
config.plugins.epgrefresh.show_help = ConfigYesNo(default = True)
config.plugins.epgrefresh.wakeup_time = ConfigInteger(default=-1)


# convert previous parameters
config.plugins.epgrefresh.background = ConfigYesNo(default = False)
Expand All @@ -55,45 +57,6 @@
config.plugins.epgrefresh.interval.value = 2
config.plugins.epgrefresh.save()

del now, begin, end

#pragma mark - Workaround for unset clock

from enigma import eDVBLocalTimeHandler

def timeCallback(isCallback=True):
"""Time Callback/Autostart management."""
thInstance = eDVBLocalTimeHandler.getInstance()
if isCallback:
# NOTE: this assumes the clock is actually ready when called back
# this may not be true, but we prefer silently dying to waiting forever
thInstance.m_timeUpdated.get().remove(timeCallback)
elif not thInstance.ready():
thInstance.m_timeUpdated.get().append(timeCallback)
return

if config.plugins.epgrefresh.wakeup.value:
now = localtime()
begin = int(mktime(
(now.tm_year, now.tm_mon, now.tm_mday,
config.plugins.epgrefresh.begin.value[0],
config.plugins.epgrefresh.begin.value[1],
0, now.tm_wday, now.tm_yday, now.tm_isdst)
))
# booted +- 10min from begin of timespan
if abs(time() - begin) < 600:
from Screens.MessageBox import MessageBox
from Tools.Notifications import AddNotificationWithCallback
from Tools.BoundFunction import boundFunction
# XXX: we use a notification because this will be suppressed otherwise
AddNotificationWithCallback(
boundFunction(standbyQuestionCallback, epgrefresh.session),
MessageBox,
_("This might have been an automated bootup to refresh the EPG. For this to happen it is recommended to put the receiver to Standby.\nDo you want to do this now?"),
timeout = 15
)
epgrefresh.start()

#pragma mark - Help
try:
from Plugins.SystemPlugins.MPHelp import registerHelp, XMLHelpReader
Expand All @@ -116,19 +79,21 @@ def timeCallback(isCallback=True):
from Components.PluginComponent import plugins
from Plugins.Plugin import PluginDescriptor

def standbyQuestionCallback(session, res = None):
if res:
from Screens.Standby import Standby
session.open(Standby)

# Autostart
def autostart(reason, **kwargs):
if reason == 0 and "session" in kwargs:
session = kwargs["session"]
epgrefresh.session = session

if config.plugins.epgrefresh.enabled.value:
timeCallback(isCallback=False)
# check if box was woken up by a timer, if so, check if epgrefresh set this timer
if session.nav.wasTimerWakeup() and config.misc.prev_wakeup_time.value == config.plugins.epgrefresh.wakeup_time.value:
# if box is not in idle mode, do that
from Screens.Standby import Standby, inStandby
if not inStandby:
from Tools import Notifications
Notifications.AddNotificationWithID("Standby", Standby)
epgrefresh.start()

elif reason == 1:
epgrefresh.stop()
Expand All @@ -138,6 +103,7 @@ def getNextWakeup():
if not config.plugins.epgrefresh.enabled.value or \
not config.plugins.epgrefresh.wakeup.value:

setConfigWakeupTime(-1)
return -1

now = localtime()
Expand All @@ -147,12 +113,20 @@ def getNextWakeup():
config.plugins.epgrefresh.begin.value[1],
0, now.tm_wday, now.tm_yday, now.tm_isdst)
))

# todays timespan has not yet begun
if begin > time():
setConfigWakeupTime(begin)
return begin

# otherwise add 1 day
setConfigWakeupTime(begin+86400)
return begin+86400

def setConfigWakeupTime(value):
config.plugins.epgrefresh.wakeup_time.value = value
config.plugins.epgrefresh.save()

# Mainfunction
def main(session, **kwargs):
epgrefresh.stop()
Expand Down
6 changes: 3 additions & 3 deletions startuptostandby/src/plugin.py
@@ -1,7 +1,7 @@
# -*- coding: iso-8859-1 -*-
from Plugins.Plugin import PluginDescriptor
from Components.config import config, ConfigSubsection, ConfigEnableDisable
from Screens.Standby import Standby
from Screens.Standby import Standby, inStandby
from StartupToStandbyConfiguration import StartupToStandbyConfiguration
from Tools import Notifications

Expand All @@ -15,8 +15,8 @@ def main(session, **kwargs):
# sessionstart
def sessionstart(reason, session = None):
print "[StartupToStandby] autostart"
if config.plugins.startuptostandby.enabled.value and reason == 0:
Notifications.AddNotification(Standby)
if config.plugins.startuptostandby.enabled.value and reason == 0 and not inStandby:
Notifications.AddNotificationWithID("Standby", Standby)

def Plugins(path, **kwargs):
return [PluginDescriptor(name="StartupToStandby", description="Startup To Standby", where = PluginDescriptor.WHERE_PLUGINMENU, fnc = main, needsRestart = False),
Expand Down

0 comments on commit 7def28e

Please sign in to comment.