ManualFancontrol : fix default pwm 10->100 for ultimo
[vuplus_dvbapp] / lib / python / Plugins / SystemPlugins / ManualFancontrol / InstandbyOn.py
1 from Components.config import config, ConfigSubList, ConfigSubsection
2 import NavigationInstance
3 from enigma import iRecordableService, eTimer, iPlayableService, eServiceCenter, iServiceInformation
4 from Components.ConfigList import ConfigListScreen
5 from Components.config import config, ConfigSubsection, ConfigSelection, ConfigSlider
6 from Components.Harddisk import harddiskmanager
7
8 def getModel():
9         file = open("/proc/stb/info/vumodel", "r")
10         modelname = file.readline().strip()
11         file.close()
12         return modelname
13
14 config.plugins.manualfancontrols = ConfigSubsection()
15 config.plugins.manualfancontrols.standbymode = ConfigSelection(default = "yes", choices = [
16         ("no", _("no")), ("yes", _("yes"))])
17
18 if getModel() == "ultimo":
19         config.plugins.manualfancontrols.pwmvalue = ConfigSlider(default = 100, increment = 5, limits = (0, 255))
20 else:
21         config.plugins.manualfancontrols.pwmvalue = ConfigSlider(default = 10, increment = 5, limits = (0, 255))
22
23 config.plugins.manualfancontrols.checkperiod = ConfigSelection(default = "10", choices = [
24                 ("5", "5 " + _("seconds")), ("10", "10 " + _("seconds")), ("30", "30 " + _("seconds")),
25                 ("60", "1 " + _("minute")), ("120", "2 " + _("minutes")),
26                 ("300", "5 " + _("minutes")), ("600", "10 " + _("minutes"))])
27
28 instandbyOn_playingpvr = False
29
30 class instandbyOn:
31         def __init__(self):
32                 self.fanoffmode = 'OFF'
33                 self.minimum_pwm = 5
34                 self.setPWM(config.plugins.manualfancontrols.pwmvalue.value)
35                 self.checkStstusTimer = eTimer()
36                 self.checkStstusTimer.callback.append(self.checkStstus)
37                 if config.plugins.manualfancontrols.pwmvalue.value == 0:
38                         self.fanoffmode = 'ON'
39                 if self.fanoffmode == 'ON':
40                         self.checkStatusLoopStart()
41
42                 config.misc.standbyCounter.addNotifier(self.standbyBegin, initial_call = False)
43                 print "<ManualFancontrol> init :  self.fanoffmode : ", self.fanoffmode
44                 print "<ManualFancontrol> init :  config.plugins.manualfancontrols.pwmvalue.value : ", config.plugins.manualfancontrols.pwmvalue.value
45
46         def checkStatusLoopStart(self):
47                 print "<ManualFancontrol> checkStatusLoopStart"
48                 self.checkStstusTimer.start(int(config.plugins.manualfancontrols.checkperiod.value) * 1000)
49
50         def checkStatusLoopStop(self):
51                 print "<ManualFancontrol> checkStatusLoopStop"
52                 self.checkStstusTimer.stop()
53
54         def checkStstus(self):
55                 from Screens.Standby import inStandby
56                 print "<ManualFancontrol> checkStstus, fanoffmode : %s, "%self.fanoffmode,"inStandby : ",inStandby and True or False
57                 if self.fanoffmode is 'ON' : # pwmvalue is '0'
58                         if self.isRecording() or self.isHDDActive():
59                                 self.setPWM(self.minimum_pwm)
60                         else:
61                                 self.setPWM(0)
62                 elif inStandby : # standby mode but pwm > 0
63                         if self.isRecording() or self.isHDDActive():
64                                 self.setPWM(config.plugins.manualfancontrols.pwmvalue.value)
65                         else:
66                                 self.setPWM(0)
67                 elif self.getPWM() != config.plugins.manualfancontrols.pwmvalue.value : # normal mode
68                         self.setPWM(config.plugins.manualfancontrols.pwmvalue.value)
69
70         def standbyBegin(self, configElement):
71                 print "<ManualFancontrol> Standby Begin"
72                 if config.plugins.manualfancontrols.standbymode.value == "yes" and self.fanoffmode is "OFF":
73                         from Screens.Standby import inStandby
74                         inStandby.onClose.append(self.StandbyEnd)
75                         self.addRecordEventCB()
76                         self.checkStatusLoopStart()
77                         self.checkStstus()
78
79         def StandbyEnd(self):
80                 print "<ManualFancontrol> Standby End"
81                 if self.fanoffmode is "OFF":
82                         self.removeRecordEventCB()
83                         self.checkStatusLoopStop()
84                 self.checkStstus()
85
86         def addRecordEventCB(self):
87                 print "<ManualFancontrol> addRecordEventCB"
88                 if self.getRecordEvent not in NavigationInstance.instance.record_event:
89                         NavigationInstance.instance.record_event.append(self.getRecordEvent)
90
91         def removeRecordEventCB(self):
92                 print "<ManualFancontrol> removeRecordEventCB"
93                 if self.getRecordEvent in NavigationInstance.instance.record_event:
94                         NavigationInstance.instance.record_event.remove(self.getRecordEvent)
95
96         def getRecordEvent(self, recservice, event):
97                 if event == iRecordableService.evEnd or event == iRecordableService.evStart:
98                         self.checkStstus()
99
100         def isRecording(self):
101                 recordings = NavigationInstance.instance.getRecordings()
102                 print "<ManualFancontrol_> recordings : ",len(recordings)
103                 if recordings :
104                         return True
105                 else:
106                         return False
107
108         def isHDDActive(self): # remake certainly
109                 for hdd in harddiskmanager.HDDList():
110                         if not hdd[1].isSleeping():
111                                 print "<ManualFancontrol_> %s is not Sleeping"%hdd[0]
112                                 return True
113                 print "<ManualFancontrol_> All HDDs are Sleeping"
114                 return False
115
116         def getPWM(self):
117                 f = open("/proc/stb/fp/fan_pwm", "r")
118                 value = int(f.readline().strip(), 16)
119                 f.close()
120                 print "<ManualFancontrol> getPWM : %d "%value
121                 return value
122
123         def setPWM(self, value):
124                 print "<ManualFancontrol> setPWM to : %d"%value
125                 f = open("/proc/stb/fp/fan_pwm", "w")
126                 f.write("%x" % value)
127                 f.close()
128
129 instandbyon = instandbyOn()
130