add FrontendStatus source, add converter to SNR/AGC/BER bar and text
[enigma2.git] / lib / python / Components / Converter / FrontendInfo.py
1 from Components.Converter.Converter import Converter
2
3 class FrontendInfo(Converter, object):
4         BER = 0
5         SNR = 1
6         AGC = 2
7         LOCK = 3
8
9         def __init__(self, type, *args, **kwargs):
10                 Converter.__init__(self)
11                 if type == "BER":
12                         self.type = self.BER
13                 elif type == "SNR":
14                         self.type = self.SNR
15                 elif type == "AGC":
16                         self.type = self.AGC
17                 else:
18                         self.type = self.LOCK
19
20         def getText(self):
21                 assert self.type != self.LOCK, "the text output of FrontendInfo cannot be used for lock info"
22                 if self.type == self.BER: # as count
23                         count = self.source.ber
24                         if count is not None:
25                                 return str(count)
26                         else:
27                                 return "N/A"
28                 elif self.type == self.AGC:
29                         percent = self.source.agc
30                 elif self.type == self.SNR:
31                         percent = self.source.snr
32                 
33                 if percent is None:
34                         return "N/A"
35
36                 return "%d %%" % (percent * 100 / 65536)
37
38         def getBool(self):
39                 assert self.type == LOCK, "the boolean output of FrontendInfo can only be used for lock info"
40                 return self.source.lock
41
42         text = property(getText)
43
44         bool = property(getBool)
45
46         def getValue(self):
47                 assert self.type != self.LOCK, "the value/range output of FrontendInfo can not be used for lock info"
48                 if self.type == self.AGC:
49                         return self.source.agc or 0
50                 elif self.type == self.SNR:
51                         return self.source.snr or 0
52                 elif self.type == self.BER:
53                         if self.BER < self.range:
54                                 return self.BER or 0
55                         else:
56                                 return self.range
57
58         range = 65536
59         value = property(getValue)