From 0bd23b623bf4e902e57f0665303c705402a38fbf Mon Sep 17 00:00:00 2001 From: Knut Ahlers Date: Wed, 31 Jul 2019 12:32:42 +0200 Subject: [PATCH] Improve parsing, ignore AUXTIN* sensors Signed-off-by: Knut Ahlers --- .config/i3blocks/temp | 44 ++++++++++++++++++++++++++++++++++++------- 1 file changed, 37 insertions(+), 7 deletions(-) diff --git a/.config/i3blocks/temp b/.config/i3blocks/temp index 56e79f5..c414326 100755 --- a/.config/i3blocks/temp +++ b/.config/i3blocks/temp @@ -1,22 +1,52 @@ #!/usr/bin/env python +import json import re import subprocess CRIT = 70.0 +CHIP_BLACKLIST = [] +SENSOR_BLACKLIST = [r'^AUXTIN[0-9]'] + + +def in_blacklist(identifier, blacklist): + for entry in blacklist: + if entry == identifier or re.match(entry, identifier): + return True + return False + def main(): - sensors = subprocess.check_output(['sensors', '-u']).decode('utf-8') + sensors_data = json.loads(subprocess.check_output( + ['sensors', '-j']).decode('utf-8')) max_temp = 0.0 - for line in sensors.split('\n'): - if not re.match(r'.*temp._input:.*', line): - continue - temp = float(line.split(':')[1]) + # for line in sensors.split('\n'): + # if not re.match(r'.*temp._input:.*', line): + # continue + # temp = float(line.split(':')[1]) - if temp > max_temp: - max_temp = temp + # if temp > max_temp: + # max_temp = temp + + for chip, sensors in sensors_data.items(): + if in_blacklist(chip, CHIP_BLACKLIST): + continue + + for sensor, readings in sensors.items(): + if in_blacklist(sensor, SENSOR_BLACKLIST): + continue + + if type(readings) == str: + continue + + for name, value in readings.items(): + if not re.match(r'^temp._input$', name): + continue + + if value > max_temp: + max_temp = value color = '#ffffff' if max_temp > CRIT: