@cryptotaxi247 / netdata-1 / commits / 5597978a4

add fahrenheit option

lgz committed Dec 25, 2016 at 13:35 UTC 5597978a4b223f2c05a00b5b1dc823632f0f0e4f
1 file changed +19 -1
python.d/sensors.chart.py
+19 -1
@@ -77,6 +77,9 @@ class Service(SimpleService):
77 SimpleService.__init__(self, configuration=configuration, name=name)
78 self.order = []
79 self.definitions = {}
80 + self.celsius = ('Celsius', lambda x: x)
81 + self.fahrenheit = ('Fahrenheit', lambda x: x * 9 / 5 + 32) if self.configuration.get('fahrenheit') else False
82 + self.choice = (choice for choice in [self.fahrenheit, self.celsius] if choice)
83 self.chips = []
84
85 def _get_data(self):
@@ -94,7 +97,10 @@ class Service(SimpleService):
97 limit = LIMITS[typeName];
98 if val < limit[0] or val > limit[1]:
99 continue
97 - data[prefix + "_" + str(feature.name.decode())] = int(val * 1000)
100 + if 'temp' in str(feature.name.decode()):
101 + data[prefix + "_" + str(feature.name.decode())] = int(self.calc(val) * 1000)
102 + else:
103 + data[prefix + "_" + str(feature.name.decode())] = int(val * 1000)
104 except Exception as e:
105 self.error(e)
106 return None
@@ -121,6 +127,8 @@ class Service(SimpleService):
127 self.order.append(name)
128 chart_def = list(CHARTS[type]['options'])
129 chart_def[1] = chip_name + chart_def[1]
130 + if chart_def[2] == 'Celsius':
131 + chart_def[2] = self.choice[0]
132 self.definitions[name] = {'options': chart_def}
133 self.definitions[name]['lines'] = []
134 line = list(CHARTS[type]['lines'][0])
@@ -134,10 +142,20 @@ class Service(SimpleService):
142 except Exception as e:
143 self.error(e)
144 return False
145 +
146 + try:
147 + self.choice = next(self.choice)
148 + except StopIteration:
149 + # That can not happen but..
150 + self.choice = ('Celsius', lambda x: x)
151 + self.calc = self.choice[1]
152 + else:
153 + self.calc = self.choice[1]
154
155 try:
156 self._create_definitions()
157 except Exception as e:
158 self.error(e)
159 return False
160 +
161 return True