ac8f1055243e366bb8bd76732af379d2d3817dcd
[openblackhole/openblackhole-enigma2.git] / lib / python / Plugins / SystemPlugins / TempFanControl / plugin.py
1 from Components.ActionMap import ActionMap
2 from Components.Sensors import sensors
3 from Components.Sources.Sensor import SensorSource
4 from Components.Sources.StaticText import StaticText
5 from Components.ConfigList import ConfigListScreen
6 from Components.config import getConfigListEntry
7
8 from Screens.Screen import Screen
9
10 from Plugins.Plugin import PluginDescriptor
11 from Components.FanControl import fancontrol
12
13 class TempFanControl(Screen, ConfigListScreen):
14         skin = """
15                 <screen position="center,center" size="570,420" title="Temperature and fan control" >
16                         <ePixmap pixmap="skin_default/buttons/red.png" position="0,0" size="140,40" alphatest="on" />
17                         <ePixmap pixmap="skin_default/buttons/green.png" position="140,0" size="140,40" alphatest="on" />
18                         <ePixmap pixmap="skin_default/buttons/yellow.png" position="280,0" size="140,40" alphatest="on" />
19                         <ePixmap pixmap="skin_default/buttons/blue.png" position="420,0" size="140,40" alphatest="on" />
20                         <widget source="red" render="Label" position="0,0" zPosition="1" size="140,40" font="Regular;20" halign="center" valign="center" backgroundColor="#9f1313" transparent="1" />
21                         <widget source="green" render="Label" position="140,0" zPosition="1" size="140,40" font="Regular;20" halign="center" valign="center" backgroundColor="#1f771f" transparent="1" />
22                         <widget source="yellow" render="Label" position="280,0" zPosition="1" size="140,40" font="Regular;20" halign="center" valign="center" backgroundColor="#a08500" transparent="1" />
23                         <widget source="blue" render="Label" position="420,0" zPosition="1" size="140,40" font="Regular;20" halign="center" valign="center" backgroundColor="#18188b" transparent="1" />
24
25                         <widget name="config" position="10,50" size="550,120" scrollbarMode="showOnDemand" />
26
27                         <widget source="SensorTempText0" render="Label" position="10,150" zPosition="1" size="90,40" font="Regular;20" halign="left" valign="top" backgroundColor="#9f1313" transparent="1" />
28                         <widget source="SensorTemp0" render="Label" position="100,150" zPosition="1" size="100,20" font="Regular;19" halign="right">
29                                 <convert type="SensorToText"></convert>
30                         </widget>
31                         <widget source="SensorTempText1" render="Label" position="10,170" zPosition="1" size="90,40" font="Regular;20" halign="left" valign="top" backgroundColor="#9f1313" transparent="1" />
32                         <widget source="SensorTemp1" render="Label" position="100,170" zPosition="1" size="100,20" font="Regular;19" halign="right">
33                                 <convert type="SensorToText"></convert>
34                         </widget>
35                         <widget source="SensorTempText2" render="Label" position="10,190" zPosition="1" size="90,40" font="Regular;20" halign="left" valign="top" backgroundColor="#9f1313" transparent="1" />
36                         <widget source="SensorTemp2" render="Label" position="100,190" zPosition="1" size="100,20" font="Regular;19" halign="right">
37                                 <convert type="SensorToText"></convert>
38                         </widget>
39                         <widget source="SensorTempText3" render="Label" position="10,210" zPosition="1" size="90,40" font="Regular;20" halign="left" valign="top" backgroundColor="#9f1313" transparent="1" />
40                         <widget source="SensorTemp3" render="Label" position="100,210" zPosition="1" size="100,20" font="Regular;19" halign="right">
41                                 <convert type="SensorToText"></convert>
42                         </widget>
43                         <widget source="SensorTempText4" render="Label" position="10,230" zPosition="1" size="90,40" font="Regular;20" halign="left" valign="top" backgroundColor="#9f1313" transparent="1" />
44                         <widget source="SensorTemp4" render="Label" position="100,230" zPosition="1" size="100,20" font="Regular;19" halign="right">
45                                 <convert type="SensorToText"></convert>
46                         </widget>
47                         <widget source="SensorTempText5" render="Label" position="10,250" zPosition="1" size="90,40" font="Regular;20" halign="left" valign="top" backgroundColor="#9f1313" transparent="1" />
48                         <widget source="SensorTemp5" render="Label" position="100,250" zPosition="1" size="100,20" font="Regular;19" halign="right">
49                                 <convert type="SensorToText"></convert>
50                         </widget>
51                         <widget source="SensorTempText6" render="Label" position="10,270" zPosition="1" size="90,40" font="Regular;20" halign="left" valign="top" backgroundColor="#9f1313" transparent="1" />
52                         <widget source="SensorTemp6" render="Label" position="100,270" zPosition="1" size="100,20" font="Regular;19" halign="right">
53                                 <convert type="SensorToText"></convert>
54                         </widget>
55                         <widget source="SensorTempText7" render="Label" position="10,290" zPosition="1" size="90,40" font="Regular;20" halign="left" valign="top" backgroundColor="#9f1313" transparent="1" />
56                         <widget source="SensorTemp7" render="Label" position="100,290" zPosition="1" size="100,20" font="Regular;19" halign="right">
57                                 <convert type="SensorToText"></convert>
58                         </widget>
59
60                         <widget source="SensorFanText0" render="Label" position="290,150" zPosition="1" size="90,40" font="Regular;20" halign="left" valign="top" backgroundColor="#9f1313" transparent="1" />
61                         <widget source="SensorFan0" render="Label" position="380,150" zPosition="1" size="150,20" font="Regular;19" halign="right">
62                                 <convert type="SensorToText"></convert>
63                         </widget>
64                         <widget source="SensorFanText1" render="Label" position="290,170" zPosition="1" size="90,40" font="Regular;20" halign="left" valign="top" backgroundColor="#9f1313" transparent="1" />
65                         <widget source="SensorFan1" render="Label" position="380,170" zPosition="1" size="150,20" font="Regular;19" halign="right">
66                                 <convert type="SensorToText"></convert>
67                         </widget>
68                         <widget source="SensorFanText2" render="Label" position="290,190" zPosition="1" size="90,40" font="Regular;20" halign="left" valign="top" backgroundColor="#9f1313" transparent="1" />
69                         <widget source="SensorFan2" render="Label" position="380,190" zPosition="1" size="150,20" font="Regular;19" halign="right">
70                                 <convert type="SensorToText"></convert>
71                         </widget>
72                         <widget source="SensorFanText3" render="Label" position="290,210" zPosition="1" size="90,40" font="Regular;20" halign="left" valign="top" backgroundColor="#9f1313" transparent="1" />
73                         <widget source="SensorFan3" render="Label" position="380,210" zPosition="1" size="150,20" font="Regular;19" halign="right">
74                                 <convert type="SensorToText"></convert>
75                         </widget>
76                         <widget source="SensorFanText4" render="Label" position="290,230" zPosition="1" size="90,40" font="Regular;20" halign="left" valign="top" backgroundColor="#9f1313" transparent="1" />
77                         <widget source="SensorFan4" render="Label" position="380,230" zPosition="1" size="150,20" font="Regular;19" halign="right">
78                                 <convert type="SensorToText"></convert>
79                         </widget>
80                         <widget source="SensorFanText5" render="Label" position="290,250" zPosition="1" size="90,40" font="Regular;20" halign="left" valign="top" backgroundColor="#9f1313" transparent="1" />
81                         <widget source="SensorFan5" render="Label" position="380,250" zPosition="1" size="150,20" font="Regular;19" halign="right">
82                                 <convert type="SensorToText"></convert>
83                         </widget>
84                         <widget source="SensorFanText6" render="Label" position="290,270" zPosition="1" size="90,40" font="Regular;20" halign="left" valign="top" backgroundColor="#9f1313" transparent="1" />
85                         <widget source="SensorFan6" render="Label" position="380,270" zPosition="1" size="150,20" font="Regular;19" halign="right">
86                                 <convert type="SensorToText"></convert>
87                         </widget>
88                         <widget source="SensorFanText7" render="Label" position="290,290" zPosition="1" size="90,40" font="Regular;20" halign="left" valign="top" backgroundColor="#9f1313" transparent="1" />
89                         <widget source="SensorFan7" render="Label" position="380,290" zPosition="1" size="150,20" font="Regular;19" halign="right">
90                                 <convert type="SensorToText"></convert>
91                         </widget>
92                 </screen>"""
93
94         def __init__(self, session, args = None):
95                 Screen.__init__(self, session)
96
97                 self.setTitle(_("Temperature and fan control"))
98
99                 templist = sensors.getSensorsList(sensors.TYPE_TEMPERATURE)
100                 tempcount = len(templist)
101                 fanlist = sensors.getSensorsList(sensors.TYPE_FAN_RPM)
102                 fancount = len(fanlist)
103
104                 self["red"] = StaticText(_("Cancel"))
105                 self["green"] = StaticText(_("OK"))
106                 self["yellow"] = StaticText("")
107                 self["blue"] = StaticText("")
108
109                 for count in range(8):
110                         if count < tempcount:
111                                 id = templist[count]
112                                 self["SensorTempText%d" % count] = StaticText(sensors.getSensorName(id))
113                                 self["SensorTemp%d" % count] = SensorSource(sensorid = id)
114                         else:
115                                 self["SensorTempText%d" % count] = StaticText("")
116                                 self["SensorTemp%d" % count] = SensorSource()
117
118                         if count < fancount:
119                                 id = fanlist[count]
120                                 self["SensorFanText%d" % count] = StaticText(sensors.getSensorName(id))
121                                 self["SensorFan%d" % count] = SensorSource(sensorid = id)
122                         else:
123                                 self["SensorFanText%d" % count] = StaticText("")
124                                 self["SensorFan%d" % count] = SensorSource()
125
126                 self.list = []
127                 for count in range(fancontrol.getFanCount()):
128                         self.list.append(getConfigListEntry(_("Fan %d voltage") % (count + 1), fancontrol.getConfig(count).vlt))
129                         self.list.append(getConfigListEntry(_("Fan %d PWM") % (count + 1), fancontrol.getConfig(count).pwm))
130                         self.list.append(getConfigListEntry(_("Standby fan %d voltage") % (count + 1), fancontrol.getConfig(count).vlt_standby))
131                         self.list.append(getConfigListEntry(_("Standby fan %d PWM") % (count + 1), fancontrol.getConfig(count).pwm_standby))
132
133                 ConfigListScreen.__init__(self, self.list, session = self.session)
134                 #self["config"].list = self.list
135                 #self["config"].setList(self.list)
136                 self["config"].l.setSeperation(300)
137
138                 self["actions"] = ActionMap(["OkCancelActions", "ColorActions", "MenuActions"],
139                 {
140                         "ok": self.save,
141                         "cancel": self.revert,
142                         "red": self.revert,
143                         "green": self.save,
144                         "menu": self.closeRecursive,
145                 }, -1)
146
147         def save(self):
148                 for count in range(fancontrol.getFanCount()):
149                         fancontrol.getConfig(count).vlt.save()
150                         fancontrol.getConfig(count).pwm.save()
151                         fancontrol.getConfig(count).vlt_standby.save()
152                         fancontrol.getConfig(count).pwm_standby.save()
153                 self.close()
154
155         def revert(self):
156                 for count in range(fancontrol.getFanCount()):
157                         fancontrol.getConfig(count).vlt.load()
158                         fancontrol.getConfig(count).pwm.load()
159                         fancontrol.getConfig(count).vlt_standby.load()
160                         fancontrol.getConfig(count).pwm_standby.load()
161                 self.close()
162
163 def main(session, **kwargs):
164         session.open(TempFanControl)
165
166 def startMenu(menuid):
167         if menuid != "system":
168                 return []
169         return [(_("Temperature and fan control"), main, "tempfancontrol", 80)]
170
171 def Plugins(**kwargs):
172         return PluginDescriptor(name = _("Temperature and fan control"), description = _("Temperature and fan control"), where = PluginDescriptor.WHERE_MENU, needsRestart = False, fnc = startMenu)
173