8f1b36dc73fd3eb28ce57b1f9b85b41217e702cc
[openblackhole/openblackhole-enigma2.git] / lib / python / Components / Sources / FrontendStatus.py
1 from Source import Source
2 from enigma import eTimer
3
4 class FrontendStatus(Source):
5         def __init__(self, service_source = None, frontend_source = None, update_interval = 1000):
6                 Source.__init__(self)
7                 self.update_interval = update_interval
8                 self.service_source = service_source
9                 self.frontend_source = frontend_source
10                 self.invalidate()
11                 self.poll_timer = eTimer()
12                 self.poll_timer.callback.append(self.updateFrontendStatus)
13                 self.poll_timer.start(update_interval, True)
14
15         def invalidate(self):
16                 self.snr = self.agc = self.ber = self.lock = self.snr_db = None
17
18         def updateFrontendStatus(self):
19                 status = self.getFrontendStatus()
20                 if not status:
21                         self.invalidate()
22                 else:
23                         self.snr = status.get("tuner_signal_quality")
24                         self.snr_db = status.get("tuner_signal_quality_db")
25                         self.agc = status.get("tuner_signal_power")
26                         self.ber = status.get("tuner_bit_error_rate")
27                         self.lock = status.get("tuner_locked")
28                 self.changed((self.CHANGED_ALL, ))
29                 self.poll_timer.start(self.update_interval, True)
30
31         def getFrontendStatus(self):
32                 if self.frontend_source:
33                         frontend = self.frontend_source()
34                         dict = { }
35                         if frontend:
36                                 frontend.getFrontendStatus(dict)
37                         return dict
38                 elif self.service_source:
39                         service = self.service_source()
40                         feinfo = service and service.frontendInfo()
41                         return feinfo and feinfo.getFrontendStatus()
42                 else:
43                         return None
44
45         def doSuspend(self, suspended):
46                 if suspended:
47                         self.poll_timer.stop()
48                 else:
49                         self.updateFrontendStatus()
50
51         def destroy(self):
52                 self.poll_timer.callback.remove(self.updateFrontendStatus)
53                 Source.destroy(self)
54