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
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 = 5, limits = (1, 100))
18 config.plugins.fancontrols.fanofftime = ConfigInteger(default = 60, limits = (1, 100))
20 class FancontrolConfiguration(Screen, ConfigListScreen):
22 <screen name="FancontrolConfiguration" position="center,center" size="560,300" title="Standbymode 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" />
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
37 self["shortcuts"] = ActionMap(["ShortcutActions", "SetupActions" ],
40 "cancel": self.keyCancel,
41 "red": self.keyCancel,
42 "green": self.keySave,
46 ConfigListScreen.__init__(self, self.list,session = self.session)
50 self["key_red"] = StaticText(_("Close"))
51 self["key_green"] = StaticText(_("Save"))
54 ConfigListScreen.keyLeft(self)
58 ConfigListScreen.keyRight(self)
63 value=int(open('/proc/stb/system/standby_fan_off','r').read())
65 config.plugins.fancontrols.standbymode.value="on"
67 config.plugins.fancontrols.standbymode.value="off"
68 value=int(open('/proc/stb/system/use_fan_timer','r').read())
70 config.plugins.fancontrols.usetimer.value = "off"
72 config.plugins.fancontrols.usetimer.value = "on"
73 time=int(open('/proc/stb/system/fan_on_time','r').read())
74 if time > 0 and time < 101:
75 config.plugins.fancontrols.fanontime.value = time
77 config.plugins.fancontrols.fanontime.value = 1
78 time=int(open('/proc/stb/system/fan_off_time','r').read())
79 if time > 0 and time < 101:
80 config.plugins.fancontrols.fanofftime.value = time
82 config.plugins.fancontrols.fanofftime.value = 1
84 print 'Error read proc of fan'
87 def createSetup(self):
89 self.standbyEntry = getConfigListEntry(_("Fan basic action"), config.plugins.fancontrols.standbymode)
90 self.usetimerEntry = getConfigListEntry(_("Use Fan timer"), config.plugins.fancontrols.usetimer)
91 self.fanontimeEntry = getConfigListEntry(_("Fan on duration time"), config.plugins.fancontrols.fanontime)
92 self.fanofftimeEntry = getConfigListEntry(_("Fan off duration time"), config.plugins.fancontrols.fanofftime)
94 self.list.append( self.standbyEntry )
95 if config.plugins.fancontrols.standbymode.value is "off":
96 self.list.append( self.usetimerEntry )
97 if config.plugins.fancontrols.usetimer.value is not "off":
98 self.list.append( self.fanontimeEntry )
99 self.list.append( self.fanofftimeEntry )
101 self["config"].list = self.list
102 self["config"].l.setList(self.list)
103 if not self.selectionChanged in self["config"].onSelectionChanged:
104 self["config"].onSelectionChanged.append(self.selectionChanged)
107 if self["config"].getCurrent() == self.usetimerEntry or self["config"].getCurrent() == self.standbyEntry:
110 def selectionChanged(self):
111 current = self["config"].getCurrent()
114 def cancelConfirm(self, result):
117 for x in self["config"].list:
124 if self["config"].isChanged():
125 self.session.openWithCallback(self.cancelConfirm, MessageBox, _("Really close without saving settings?"))
130 ConfigListScreen.keySave(self)
132 if config.plugins.fancontrols.standbymode.value is "on":
133 open('/proc/stb/system/standby_fan_off','w').write('0')
135 open('/proc/stb/system/standby_fan_off','w').write('1')
136 if config.plugins.fancontrols.usetimer.value is "off":
137 open('/proc/stb/system/use_fan_timer','w').write('0')
139 open('/proc/stb/system/use_fan_timer','w').write('1')
140 open('/proc/stb/system/fan_on_time','w').write('%s'%config.plugins.fancontrols.fanontime.value)
141 open('/proc/stb/system/fan_off_time','w').write('%s'%config.plugins.fancontrols.fanofftime.value)
143 print 'Error write proc of fan'
146 def openconfig(session, **kwargs):
147 session.open(FancontrolConfiguration)
149 def selSetup(menuid, **kwargs):
150 if menuid != "system":
153 return [(_("Fan Control"), openconfig, "fancontrol_config", 70)]
155 def setfancontrol(reason, **kwargs):
157 if config.plugins.fancontrols.standbymode.value == "on":
158 open('/proc/stb/system/standby_fan_off','w').write('0')
160 open('/proc/stb/system/standby_fan_off','w').write('1')
161 if config.plugins.fancontrols.usetimer.value is "off":
162 open('/proc/stb/system/use_fan_timer','w').write('0')
164 open('/proc/stb/system/use_fan_timer','w').write('1')
165 open('/proc/stb/system/fan_on_time','w').write('%s'%config.plugins.fancontrols.fanontime.value)
166 open('/proc/stb/system/fan_off_time','w').write('%s'%config.plugins.fancontrols.fanofftime.value)
168 print 'Error to set fan control'
170 def Plugins(**kwargs):
171 return [PluginDescriptor(name = "Fancontrols", description = "check Fan Control settings", where = PluginDescriptor.WHERE_AUTOSTART, fnc = setfancontrol),
172 PluginDescriptor(name=_("Fan control"), description="Fan Control", where = PluginDescriptor.WHERE_MENU, fnc=selSetup)]