FrontendInfo: When we have more than x tuners indicate it condesed.
[openblackhole/openblackhole-enigma2.git] / lib / python / Components / Converter / FrontendInfo.py
1 from Components.Converter.Converter import Converter
2 from Components.Element import cached
3 from Components.config import config
4 from Components.NimManager import nimmanager
5
6 class FrontendInfo(Converter, object):
7         BER = 0
8         SNR = 1
9         AGC = 2
10         LOCK = 3
11         SNRdB = 4
12         SLOT_NUMBER = 5
13         TUNER_TYPE = 6
14         STRING = 7
15
16         def __init__(self, type):
17                 Converter.__init__(self, type)
18                 if type == "BER":
19                         self.type = self.BER
20                 elif type == "SNR":
21                         self.type = self.SNR
22                 elif type == "SNRdB":
23                         self.type = self.SNRdB
24                 elif type == "AGC":
25                         self.type = self.AGC
26                 elif type == "NUMBER":
27                         self.type = self.SLOT_NUMBER
28                 elif type == "TYPE":
29                         self.type = self.TUNER_TYPE
30                 elif type.startswith("STRING"):
31                         self.type = self.STRING
32                         type = type.split(",")
33                         self.space_for_tuners = len(type) > 1 and int(type[1]) or 5
34                 else:
35                         self.type = self.LOCK
36
37         @cached
38         def getText(self):
39                 assert self.type not in (self.LOCK, self.SLOT_NUMBER), "the text output of FrontendInfo cannot be used for lock info"
40                 percent = None
41                 swapsnr = config.usage.swap_snr_on_osd.value
42                 if self.type == self.BER: # as count
43                         count = self.source.ber
44                         if count is not None:
45                                 return str(count)
46                         else:
47                                 return "N/A"
48                 elif self.type == self.AGC:
49                         percent = self.source.agc
50                 elif (self.type == self.SNR and not swapsnr) or (self.type == self.SNRdB and swapsnr):
51                         percent = self.source.snr
52                 elif self.type  == self.SNR or self.type == self.SNRdB:
53                         if self.source.snr_db is not None:
54                                 return "%3.01f dB" % (self.source.snr_db / 100.0)
55                         elif self.source.snr is not None: #fallback to normal SNR...
56                                 percent = self.source.snr
57                 elif self.type == self.TUNER_TYPE:
58                         return self.source.frontend_type and self.frontend_type or "Unknown"
59                 elif self.type == self.STRING:
60                         string = ""
61                         for n in nimmanager.nim_slots:
62                                 if n.type:
63                                         if string:
64                                                 string += " "
65                                         if n.slot == self.source.slot_number:
66                                                 string += "\c0000??00"
67                                         elif self.source.tuner_mask & 1 << n.slot:
68                                                 string += "\c00????00"
69                                         elif len(nimmanager.nim_slots) <= self.space_for_tuners:
70                                                 string += "\c007?7?7?"
71                                         else:
72                                                 continue
73                                         string += chr(ord("A")+n.slot)
74                         return string
75                 if percent is None:
76                         return "N/A"
77                 return "%d %%" % (percent * 100 / 65536)
78
79         @cached
80         def getBool(self):
81                 assert self.type in (self.LOCK, self.BER), "the boolean output of FrontendInfo can only be used for lock or BER info"
82                 if self.type == self.LOCK:
83                         lock = self.source.lock
84                         if lock is None:
85                                 lock = False
86                         return lock
87                 else:
88                         ber = self.source.ber
89                         if ber is None:
90                                 ber = 0
91                         return ber > 0
92
93         text = property(getText)
94
95         boolean = property(getBool)
96
97         @cached
98         def getValue(self):
99                 assert self.type != self.LOCK, "the value/range output of FrontendInfo can not be used for lock info"
100                 if self.type == self.AGC:
101                         return self.source.agc or 0
102                 elif self.type == self.SNR:
103                         return self.source.snr or 0
104                 elif self.type == self.BER:
105                         if self.BER < self.range:
106                                 return self.BER or 0
107                         else:
108                                 return self.range
109                 elif self.type == self.TUNER_TYPE:
110                         type = self.source.frontend_type
111                         if type == 'DVB-S':
112                                 return 0
113                         elif type == 'DVB-C':
114                                 return 1
115                         elif type == 'DVB-T':
116                                 return 2
117                         elif type == 'ATSC':
118                                 return 3
119                         return -1
120                 elif self.type == self.SLOT_NUMBER:
121                         num = self.source.slot_number
122                         return num is None and -1 or num
123
124         range = 65536
125         value = property(getValue)