add possibility to use ValueRange as ValueEqual Converter
[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                 if percent is None:
44                         return "N/A"
45
46                 return "%d %%" % (percent * 100 / 65536)
47
48         @cached
49         def getBool(self):
50                 assert self.type in [self.LOCK, self.BER], "the boolean output of FrontendInfo can only be used for lock or BER info"
51                 if self.type == self.LOCK:
52                         return self.source.lock
53                 else:
54                         return self.source.ber > 0
55
56         text = property(getText)
57
58         boolean = property(getBool)
59
60         @cached
61         def getValue(self):
62                 assert self.type != self.LOCK, "the value/range output of FrontendInfo can not be used for lock info"
63                 if self.type == self.AGC:
64                         return self.source.agc or 0
65                 elif self.type == self.SNR:
66                         return self.source.snr or 0
67                 elif self.type == self.BER:
68                         if self.BER < self.range:
69                                 return self.BER or 0
70                         else:
71                                 return self.range
72
73         range = 65536
74         value = property(getValue)