e2923a95a3264f88673e773b72193ed760bf2da7
[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
10         def __init__(self, type):
11                 Converter.__init__(self, type)
12                 if type == "BER":
13                         self.type = self.BER
14                 elif type == "SNR":
15                         self.type = self.SNR
16                 elif type == "AGC":
17                         self.type = self.AGC
18                 else:
19                         self.type = self.LOCK
20
21         @cached
22         def getText(self):
23                 assert self.type != self.LOCK, "the text output of FrontendInfo cannot be used for lock info"
24                 if self.type == self.BER: # as count
25                         count = self.source.ber
26                         if count is not None:
27                                 return str(count)
28                         else:
29                                 return "N/A"
30                 elif self.type == self.AGC:
31                         percent = self.source.agc
32                 elif self.type == self.SNR:
33                         percent = self.source.snr
34                 
35                 if percent is None:
36                         return "N/A"
37
38                 return "%d %%" % (percent * 100 / 65536)
39
40         @cached
41         def getBool(self):
42                 assert self.type in [self.LOCK, self.BER], "the boolean output of FrontendInfo can only be used for lock or BER info"
43                 if self.type == self.LOCK:
44                         return self.source.lock
45                 else:
46                         return self.source.ber > 0
47
48         text = property(getText)
49
50         boolean = property(getBool)
51
52         @cached
53         def getValue(self):
54                 assert self.type != self.LOCK, "the value/range output of FrontendInfo can not be used for lock info"
55                 if self.type == self.AGC:
56                         return self.source.agc or 0
57                 elif self.type == self.SNR:
58                         return self.source.snr or 0
59                 elif self.type == self.BER:
60                         if self.BER < self.range:
61                                 return self.BER or 0
62                         else:
63                                 return self.range
64
65         range = 65536
66         value = property(getValue)