Raise exception if temps above given threshold

This commit is contained in:
2Shirt 2019-02-05 20:31:16 -07:00
parent 5efdf05274
commit f8404f3c16
Signed by: 2Shirt
GPG key ID: 152FAC923B0E132C

View file

@ -19,6 +19,11 @@ TEMP_LIMITS = {
REGEX_COLORS = re.compile(r'\033\[\d+;?1?m')
# Error Classes
class ThermalError(Exception):
pass
def clear_temps(sensor_data):
"""Clear saved temps but keep structure, returns dict."""
for _section, _adapters in sensor_data.items():
@ -214,7 +219,7 @@ def save_average_temp(sensor_data, temp_label, seconds=10):
_data[temp_label] = sum(_data['Temps']) / len(_data['Temps'])
def update_sensor_data(sensor_data):
def update_sensor_data(sensor_data, thermal_threshold=None):
"""Read sensors and update existing sensor_data, returns dict."""
json_data = get_raw_sensor_data()
for _section, _adapters in sensor_data.items():
@ -230,6 +235,11 @@ def update_sensor_data(sensor_data):
# Dumb workound for Dell sensors with changing source names
pass
# Check if thermal limit reached
if thermal_threshold and _section == 'CoreTemps':
if max(_data['Current'], _data['Max']) > thermal_threshold:
raise ThermalError('CoreTemps above threshold')
def join_columns(column1, column2, width=55):
return '{:<{}}{}'.format(