add SNRdB, but requires proper frontend support
[enigma2.git] / lib / python / Components / Converter / FrontendInfo.py
1 from Components.Converter.Converter import Converter
2 from Components.Element import cached
3
4 class FrontendInfo(Converter, object):
5         BER = 0
6         SNR = 1
7         AGC = 2
8         LOCK = 3
9         SNRdB = 4
10
11         def __init__(self, type):
12                 Converter.__init__(self, type)
13                 if type == "BER":
14                         self.type = self.BER
15                 elif type == "SNR":
16                         self.type = self.SNR
17                 elif type == "SNRdB":
18                         self.type = self.SNRdB
19                 elif type == "AGC":
20                         self.type = self.AGC
21                 else:
22                         self.type = self.LOCK
23
24         @cached
25         def getText(self):
26                 assert self.type != self.LOCK, "the text output of FrontendInfo cannot be used for lock info"
27                 if self.type == self.BER: # as count
28                         count = self.source.ber
29                         if count is not None:
30                                 return str(count)
31                         else:
32                                 return "N/A"
33                 elif self.type == self.AGC:
34                         percent = self.source.agc
35                 elif self.type == self.SNR:
36                         percent = self.source.snr
37                 elif self.type == self.SNRdB:
38                         if self.source.snr is None:
39                                 return "N/A"
40                         return "%3.02f dB" % (self.source.snr / 100.0)
41                 if percent is None:
42                         return "N/A"
43
44                 return "%d %%" % (percent * 100 / 65536)
45
46         @cached
47         def getBool(self):
48                 assert self.type in [self.LOCK, self.BER], "the boolean output of FrontendInfo can only be used for lock or BER info"
49                 if self.type == self.LOCK:
50                         return self.source.lock
51                 else:
52                         return self.source.ber > 0
53
54         text = property(getText)
55
56         boolean = property(getBool)
57
58         @cached
59         def getValue(self):
60                 assert self.type != self.LOCK, "the value/range output of FrontendInfo can not be used for lock info"
61                 if self.type == self.AGC:
62                         return self.source.agc or 0
63                 elif self.type == self.SNR:
64                         return self.source.snr or 0
65                 elif self.type == self.BER:
66                         if self.BER < self.range:
67                                 return self.BER or 0
68                         else:
69                                 return self.range
70
71         range = 65536
72         value = property(getValue)