352b9fdc5252fe01a8acfc7e433cd35a2255611b
[enigma2.git] / lib / python / Components / Sources / FrontendStatus.py
1 from Source import Source
2 from enigma import eTimer, iFrontendInformation
3
4 class FrontendStatus(Source):
5         def __init__(self, service_source = None, frontend_source = None):
6                 Source.__init__(self)
7                 self.service_source = service_source
8                 self.frontend_source = frontend_source
9                 self.invalidate()
10                 
11                 self.poll_timer = eTimer()
12                 self.poll_timer.timeout.get().append(self.updateFrontendStatus)
13                 self.poll_timer.start(1000)
14
15         def invalidate(self):
16                 self.snr = self.agc = self.ber = self.lock = None
17
18         def updateFrontendStatus(self):
19                 feinfo = self.getFrontendInfo()
20                 if feinfo is None:
21                         self.invalidate()
22                 else:
23                         (self.snr, self.agc, self.ber, self.lock) = \
24                                 [feinfo.getFrontendInfo(x) \
25                                         for x in [iFrontendInformation.signalPower, 
26                                                 iFrontendInformation.signalQuality, 
27                                                 iFrontendInformation.bitErrorRate, 
28                                                 iFrontendInformation.lockState] ]
29
30                 self.changed((self.CHANGED_ALL, ))
31
32         def getFrontendInfo(self):
33                 if self.frontend_source:
34                         return self.frontend_source()
35                 elif self.service_source:
36                         service = self.service_source()
37                         return service and service.frontendInfo()
38                 else:
39                         return None
40
41         def doSuspend(self, suspended):
42                 if suspended:
43                         self.poll_timer.stop()
44                 else:
45                         self.poll_timer.start(1000)
46