8b075105d0655eccf5d4c749b6d1a7cd12235625
[vuplus_dvbapp] / lib / python / Plugins / SystemPlugins / Fancontrol / plugin.py
1 from Screens.Screen import Screen
2 from Screens.MessageBox import MessageBox
3 from Plugins.Plugin import PluginDescriptor
4 from Components.ActionMap import ActionMap,NumberActionMap
5 from Components.config import config
6 from Components.config import config, getConfigListEntry, ConfigInteger, ConfigSubsection, ConfigSelection
7 from Components.ConfigList import ConfigListScreen
8 from Components.ActionMap import ActionMap
9 from Components.Sources.StaticText import StaticText
10
11
12 config.plugins.fancontrols = ConfigSubsection()
13 config.plugins.fancontrols.standbymode = ConfigSelection(default = "off", choices = [
14         ("off", _("off")), ("on", _("on"))])
15 config.plugins.fancontrols.usetimer = ConfigSelection(default = "off", choices = [
16         ("off", _("no")), ("on", _("yes"))])
17 config.plugins.fancontrols.fanontime = ConfigInteger(default = 1, limits = (1, 100))
18 config.plugins.fancontrols.fanofftime = ConfigInteger(default = 1, limits = (1, 100))
19
20 class FancontrolConfiguration(Screen, ConfigListScreen):
21         skin = """
22                 <screen name="FancontrolConfiguration" position="center,center" size="560,300" title="Fancontrol settings" >
23                         <ePixmap pixmap="skin_default/buttons/red.png" position="0,0" size="140,40" alphatest="on" />
24                         <ePixmap pixmap="skin_default/buttons/green.png" position="140,0" size="140,40" alphatest="on" />
25                         <widget source="key_red" render="Label" position="0,0" zPosition="1" size="140,40" font="Regular;20" halign="center" valign="center" foregroundColor="#ececec" backgroundColor="#9f1313" transparent="1" />
26                         <widget source="key_green" render="Label" position="140,0" zPosition="1" size="140,40" font="Regular;20" halign="center" valign="center" foregroundColor="#ececec" backgroundColor="#1f771f" transparent="1" />
27                         <widget name="config" zPosition="2" position="5,50" size="550,200" scrollbarMode="showOnDemand" transparent="1" />
28                 </screen>"""
29         def __init__(self, session):
30                 Screen.__init__(self, session)
31                 self.session = session
32                 self.standbyEntry = None
33                 self.usetimerEntry = None
34                 self.fanontimeEntry = None
35                 self.fanofftimeEntry = None
36
37                 self["shortcuts"] = ActionMap(["ShortcutActions", "SetupActions" ],
38                 {
39                         "ok": self.keySave,
40                         "cancel": self.keyCancel,
41                         "red": self.keyCancel,
42                         "green": self.keySave,
43                 }, -2)
44
45                 self.list = []
46                 ConfigListScreen.__init__(self, self.list,session = self.session)
47                 self.getFaninfo()
48                 self.createSetup()
49
50                 self["key_red"] = StaticText(_("Close"))
51                 self["key_green"] = StaticText(_("Save"))
52
53         def keyLeft(self):
54                 ConfigListScreen.keyLeft(self)
55                 self.newConfig()
56
57         def keyRight(self):
58                 ConfigListScreen.keyRight(self)
59                 self.newConfig()
60
61         def getFaninfo(self):
62                 try:
63                         fd=open('/proc/stb/system/standby_fan_off','r')
64                         if fd.read() == '0':
65                                 config.plugins.fancontrols.standbymode.value="off"
66                         else:
67                                 config.plugins.fancontrols.standbymode.value="on"
68                         fd.close()
69                         fd=open('/proc/stb/system/use_fan_timer','r')
70                         if fd.read() == '0':
71                                 config.plugins.fancontrols.usetimer.value = "off"
72                         else:
73                                 config.plugins.fancontrols.usetimer.value = "on"
74                         fd.close()
75                         fd=open('/proc/stb/system/fan_on_time','r')
76                         time = int(fd.read())
77                         if time > 0 and time < 101:
78                                 config.plugins.fancontrols.fanontime.value = time
79                         else:
80                                 config.plugins.fancontrols.fanontime.value = 1
81                         fd.close()
82                         fd=open('/proc/stb/system/fan_off_time','r')
83                         time = int(fd.read())
84                         if time > 0 and time < 101:
85                                 config.plugins.fancontrols.fanofftime.value = time
86                         else:
87                                 config.plugins.fancontrols.fanofftime.value = 1
88                         fd.close()
89 #                       print config.plugins.fancontrols.standbymode.value, config.plugins.fancontrols.usetimer.value
90 #                       print   config.plugins.fancontrols.fanontime.value,config.plugins.fancontrols.fanofftime.value
91                 except:
92                         print 'Error read proc of fan'
93         
94
95         def createSetup(self):
96                 self.list = []
97                 self.standbyEntry = getConfigListEntry(_("Standbymode Fan control"), config.plugins.fancontrols.standbymode)
98                 self.usetimerEntry = getConfigListEntry(_("Use Fan timer"), config.plugins.fancontrols.usetimer)
99                 self.fanontimeEntry = getConfigListEntry(_("Fan on time"), config.plugins.fancontrols.fanontime)
100                 self.fanofftimeEntry = getConfigListEntry(_("Fan off time"), config.plugins.fancontrols.fanofftime)
101
102                 self.list.append( self.standbyEntry )
103                 self.list.append( self.usetimerEntry )
104                 if config.plugins.fancontrols.usetimer.value is not "off":
105                         self.list.append( self.fanontimeEntry )
106                         self.list.append( self.fanofftimeEntry )
107
108                 self["config"].list = self.list
109                 self["config"].l.setList(self.list)
110                 if not self.selectionChanged in self["config"].onSelectionChanged:
111                         self["config"].onSelectionChanged.append(self.selectionChanged)
112
113         def newConfig(self):
114                 if self["config"].getCurrent() == self.usetimerEntry:
115                         self.createSetup()
116
117         def selectionChanged(self):
118                 current = self["config"].getCurrent()
119                 print current
120
121         def cancelConfirm(self, result):
122                 if not result:
123                         return
124                 for x in self["config"].list:
125                         x[1].cancel()
126                 self.close()
127
128                         
129         def keyCancel(self):
130                 print "cancel"
131                 if self["config"].isChanged():
132                         self.session.openWithCallback(self.cancelConfirm, MessageBox, _("Really close without saving settings?"))
133                 else:
134                         self.close()
135
136         def keySave(self):
137                 if self["config"].isChanged():
138                         ConfigListScreen.keySave(self)
139                         try:
140                                 fd=open('/proc/stb/system/standby_fan_off','w')
141                                 if config.plugins.fancontrols.standbymode.value is not "off":
142                                         fd.write('1')
143                                 else:
144                                         fd.write('0')
145                                 fd.close()
146                                 fd=open('/proc/stb/system/use_fan_timer','w')
147                                 if config.plugins.fancontrols.usetimer.value is not "off":
148                                         fd.write('1')
149                                         fd.close()
150                                         fd=open('/proc/stb/system/fan_on_time','w')
151                                         fd.write('%s'%config.plugins.fancontrols.fanontime.value)
152                                         fd.close()
153                                         fd=open('/proc/stb/system/fan_off_time','w')
154                                         fd.write('%s'%config.plugins.fancontrols.fanofftime.value)
155                                         fd.close()
156                                 else:
157                                         fd.write('0')
158                                         fd.close()
159                         except:
160                                 print 'Error write proc of fan'
161                 else:
162                         self.close()
163                 
164         
165 def openconfig(session, **kwargs):
166         session.open(FancontrolConfiguration)
167
168 def selSetup(menuid, **kwargs):
169         if menuid != "system":
170                 return [ ]
171
172         return [(_("Fan Control") + "...", openconfig, "fancontrol_config", 70)]
173
174 def Plugins(**kwargs):
175         return PluginDescriptor(name=_("Fan control"), description="Fan Control", where = PluginDescriptor.WHERE_MENU, fnc=selSetup)