Skip to content

Commit

Permalink
add fahrenheit option
Browse files Browse the repository at this point in the history
  • Loading branch information
lgz committed Dec 25, 2016
1 parent cf07fa5 commit 5597978
Showing 1 changed file with 19 additions and 1 deletion.
20 changes: 19 additions & 1 deletion python.d/sensors.chart.py
Expand Up @@ -77,6 +77,9 @@ def __init__(self, configuration=None, name=None):
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):
Expand All @@ -94,7 +97,10 @@ def _get_data(self):
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
Expand All @@ -121,6 +127,8 @@ def _create_definitions(self):
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])
Expand All @@ -134,10 +142,20 @@ def check(self):
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

0 comments on commit 5597978

Please sign in to comment.