diff options
author | Costa Tsaousis <costa@tsaousis.gr> | 2016-12-25 12:56:18 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2016-12-25 12:56:18 +0200 |
commit | 77a85c91865359185007bda3f4f99069cb5abb81 (patch) | |
tree | 49cc7a9e1f4e831cac9c76d0c83a34f12b39ab9e | |
parent | 00e511171600fb6bc656128f6b4cc790c0696b09 (diff) | |
parent | fbf1ecf683080f7f8795fdbfe9cca3d762015d52 (diff) |
Merge pull request #1440 from l2isbad/sensors_chart_py_enhancement
Sensors chart py enhancement
-rw-r--r-- | conf.d/python.d/sensors.conf | 4 | ||||
-rw-r--r-- | python.d/sensors.chart.py | 20 |
2 files changed, 23 insertions, 1 deletions
diff --git a/conf.d/python.d/sensors.conf b/conf.d/python.d/sensors.conf index 7d895c348c..2e9a41338e 100644 --- a/conf.d/python.d/sensors.conf +++ b/conf.d/python.d/sensors.conf @@ -52,3 +52,7 @@ types: # # chip names can be found using the sensors shell command # the prefix is matched (anything that starts like that) +# +#---------------------------------------------------------------------- +# To change celsius to fahrenheit uncomment line below +#fahrenheit: True diff --git a/python.d/sensors.chart.py b/python.d/sensors.chart.py index 23bccb97cf..e83aacfd81 100644 --- a/python.d/sensors.chart.py +++ b/python.d/sensors.chart.py @@ -77,6 +77,9 @@ class Service(SimpleService): SimpleService.__init__(self, configuration=configuration, name=name) self.order = [] self.definitions = {} + self.celsius = ('Celsius', lambda x: x) + self.fahrenheit = ('Fahrenheit', lambda x: x * 9 / 5 + 32) if self.configuration.get('fahrenheit') else False + self.choice = (choice for choice in [self.fahrenheit, self.celsius] if choice) self.chips = [] def _get_data(self): @@ -94,7 +97,10 @@ class Service(SimpleService): limit = LIMITS[typeName]; if val < limit[0] or val > limit[1]: continue - data[prefix + "_" + str(feature.name.decode())] = int(val * 1000) + if 'temp' in str(feature.name.decode()): + data[prefix + "_" + str(feature.name.decode())] = int(self.calc(val) * 1000) + else: + data[prefix + "_" + str(feature.name.decode())] = int(val * 1000) except Exception as e: self.error(e) return None @@ -121,6 +127,8 @@ class Service(SimpleService): self.order.append(name) chart_def = list(CHARTS[type]['options']) chart_def[1] = chip_name + chart_def[1] + if chart_def[2] == 'Celsius': + chart_def[2] = self.choice[0] self.definitions[name] = {'options': chart_def} self.definitions[name]['lines'] = [] line = list(CHARTS[type]['lines'][0]) @@ -134,10 +142,20 @@ class Service(SimpleService): except Exception as e: self.error(e) return False + + try: + self.choice = next(self.choice) + except StopIteration: + # That can not happen but.. + self.choice = ('Celsius', lambda x: x) + self.calc = self.choice[1] + else: + self.calc = self.choice[1] try: self._create_definitions() except Exception as e: self.error(e) return False + return True |