enigma2 20130114 (master) -> 20130216 (master)
[enigma2.git] / usr / lib / enigma2 / python / Plugins / SystemPlugins / HdmiCec / plugin.py
1 from Components.config import config, ConfigSubsection, ConfigEnableDisable
2 from Components.HdmiCec import hdmi_cec
3 from Plugins.Plugin import PluginDescriptor
4
5 from CecConfig import CecConfig
6
7 config.plugins.cec = ConfigSubsection()
8 config.plugins.cec.sendpower = ConfigEnableDisable(default=True)
9 config.plugins.cec.receivepower = ConfigEnableDisable(default=False)
10
11 class Cec(object):
12         session = None
13
14         def __receivedStandby(self):
15                 if config.plugins.cec.receivepower.value:
16                         from Screens.Standby import Standby, inStandby
17                         if not inStandby and self.session.current_dialog and self.session.current_dialog.ALLOW_SUSPEND and self.session.in_exec:
18                                 self.session.open(Standby)
19
20         def __receivedNowActive(self):
21                 if config.plugins.cec.receivepower.value:
22                         from Screens.Standby import inStandby
23                         if inStandby != None:
24                                 inStandby.Power()
25
26         def __init__(self):
27                 config.misc.standbyCounter.addNotifier(self._onStandby, initial_call = False)
28                 hdmi_cec.instance.receivedStandby.get().append(self.__receivedStandby)
29                 hdmi_cec.instance.isNowActive.get().append(self.__receivedNowActive)
30
31         def powerOn(self):
32                 if config.plugins.cec.sendpower.value:
33                         print "[Cec] power on"
34                         hdmi_cec.otp_source_enable()
35
36         def powerOff(self):
37                 if config.plugins.cec.sendpower.value:
38                         print "[Cec] power off"
39                         hdmi_cec.otp_source_disable()
40
41         def _onStandby(self, element):
42                 from Screens.Standby import inStandby
43                 inStandby.onClose.append(self.powerOn)
44                 self.powerOff()
45
46 cec = Cec()
47
48 def autostart(reason, **kwargs):
49         session = kwargs.get('session', None)
50         if session is not None:
51                 cec.session = session
52         if reason == 0:
53                 if session is not None:
54                         #only send cec power on if it hasn been a record-timer issued poweron
55                         if not session.nav.wasTimerWakeup() or session.nav.RecordTimer.getNextRecordingTime() > session.nav.RecordTimer.getNextZapTime():
56                                 cec.powerOn()
57         else:
58                 cec.powerOff()
59
60 def conf(session, **kwargs):
61         session.open(CecConfig)
62
63 def menu(menuid, **kwargs):
64         if menuid == "system":
65                 return [(_("HDMI CEC"), conf, "hdmi_cec", None)]
66         else:
67                 return []
68
69 def Plugins(**kwargs):
70         return [
71                 PluginDescriptor(where = [PluginDescriptor.WHERE_SESSIONSTART, PluginDescriptor.WHERE_AUTOSTART] , fnc = autostart),
72                 PluginDescriptor(name = "HDMI CEC", description = "Configure HDMI CEC", where = PluginDescriptor.WHERE_MENU, needsRestart = True, fnc = menu)
73                 ]