provide wakeupfnc,
[enigma2-plugins.git] / epgrefresh / src / plugin.py
1 # Config
2 from Components.config import config, ConfigEnableDisable, ConfigInteger, ConfigSubsection, ConfigClock
3
4 # Calculate default begin/end
5 from time import time, localtime, mktime
6 now = [x for x in localtime()]
7 now[3] = 20
8 now[4] = 15
9 begin = mktime(now)
10 now[3] = 06
11 now[4] = 30
12 end = mktime(now)
13
14 config.plugins.epgrefresh = ConfigSubsection()
15 config.plugins.epgrefresh.enabled = ConfigEnableDisable(default = False)
16 config.plugins.epgrefresh.begin = ConfigClock(default = begin)
17 config.plugins.epgrefresh.end = ConfigClock(default = end)
18 config.plugins.epgrefresh.interval = ConfigInteger(default = 2, limits=(1, 10))
19 config.plugins.epgrefresh.delay_timespan = ConfigInteger(default = 60, limits=(5, 300))
20 config.plugins.epgrefresh.delay_standby = ConfigInteger(default = 10, limits=(1, 60))
21 config.plugins.epgrefresh.inherit_autotimer = ConfigEnableDisable(default = False)
22 config.plugins.epgrefresh.afterevent = ConfigEnableDisable(default = False)
23 config.plugins.epgrefresh.force = ConfigEnableDisable(default = False)
24 config.plugins.epgrefresh.lastscan = ConfigInteger(default = 0)
25
26 # Plugin
27 from EPGRefresh import epgrefresh
28 from EPGRefreshConfiguration import EPGRefreshConfiguration
29
30 # Plugin definition
31 from Plugins.Plugin import PluginDescriptor
32
33 # Autostart
34 def autostart(reason, **kwargs):
35         if config.plugins.epgrefresh.enabled.value and reason == 0 and kwargs.has_key("session"):
36                 epgrefresh.start(kwargs["session"])
37
38         elif reason == 1:
39                 epgrefresh.stop()
40
41 def getNextWakeup():
42         # Return invalid time if not automatically refreshing
43         if not config.plugins.epgrefresh.enabled.value:
44                 return -1
45         now = localtime()
46         begin = mktime(
47                 (now.tm_year, now.tm_mon, now.tm_mday,
48                 config.plugins.epgrefresh.begin.value[0],
49                 config.plugins.epgrefresh.begin.value[1],
50                 0, now.tm_wday, now.tm_yday, now.tm_isdst)
51         )
52         # todays timespan has not yet begun
53         if begin > time():
54                 return begin
55         # otherwise add 1 day
56         return begin+86400
57
58 # Mainfunction
59 def main(session, **kwargs):
60         epgrefresh.stop()
61         session.openWithCallback(
62                 doneConfiguring,
63                 EPGRefreshConfiguration
64         )
65
66 def doneConfiguring(session, **kwargs):
67         if config.plugins.epgrefresh.enabled.value:
68                 epgrefresh.start(session)
69
70 def Plugins(**kwargs):
71         return [
72                 PluginDescriptor(name="EPGRefresh", description = "Automated EPGRefresher", where = [PluginDescriptor.WHERE_AUTOSTART, PluginDescriptor.WHERE_SESSIONSTART], fnc = autostart, wakeupfnc = getNextWakeup),
73                 PluginDescriptor(name="EPGRefresh", description = "Automated EPGRefresher", where = PluginDescriptor.WHERE_PLUGINMENU, fnc = main)
74         ]