add stv0299 snr to dB Calculation (thx to adenin for this)
[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                 percent = None
28                 if self.type == self.BER: # as count
29                         count = self.source.ber
30                         if count is not None:
31                                 return str(count)
32                         else:
33                                 return "N/A"
34                 elif self.type == self.AGC:
35                         percent = self.source.agc
36                 elif self.type == self.SNR:
37                         percent = self.source.snr
38                 elif self.type == self.SNRdB:
39                         if self.source.snr_db is not None:
40                                 return "%3.02f dB" % (self.source.snr_db / 100.0)
41                         elif self.source.snr is not None: #fallback to normal SNR...
42                                 percent = self.source.snr
43                                 return "SNR:%d %%" % (percent * 100 / 65536)
44                 if percent is None:
45                         return "N/A"
46
47                 return "%d %%" % (percent * 100 / 65536)
48
49         @cached
50         def getBool(self):
51                 assert self.type in [self.LOCK, self.BER], "the boolean output of FrontendInfo can only be used for lock or BER info"
52                 if self.type == self.LOCK:
53                         return self.source.lock
54                 else:
55                         return self.source.ber > 0
56
57         text = property(getText)
58
59         boolean = property(getBool)
60
61         @cached
62         def getValue(self):
63                 assert self.type != self.LOCK, "the value/range output of FrontendInfo can not be used for lock info"
64                 if self.type == self.AGC:
65                         return self.source.agc or 0
66                 elif self.type == self.SNR:
67                         return self.source.snr or 0
68                 elif self.type == self.BER:
69                         if self.BER < self.range:
70                                 return self.BER or 0
71                         else:
72                                 return self.range
73
74         range = 65536
75         value = property(getValue)