Migrate temp to block usage
Signed-off-by: Knut Ahlers <knut@ahlers.me>
This commit is contained in:
parent
492e092a97
commit
36441150a8
1 changed files with 45 additions and 42 deletions
|
@ -4,38 +4,35 @@ import json
|
|||
import re
|
||||
import subprocess
|
||||
|
||||
from block import *
|
||||
|
||||
CRIT = 70.0
|
||||
|
||||
CHIP_BLACKLIST = []
|
||||
SENSOR_BLACKLIST = [r'^AUXTIN[0-9]']
|
||||
ICON = '\uf2c7'
|
||||
|
||||
|
||||
def in_blacklist(identifier, blacklist):
|
||||
class Temp(Block):
|
||||
|
||||
def in_blacklist(self, identifier, blacklist):
|
||||
for entry in blacklist:
|
||||
if entry == identifier or re.match(entry, identifier):
|
||||
return True
|
||||
return False
|
||||
|
||||
|
||||
def main():
|
||||
def execute(self):
|
||||
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])
|
||||
|
||||
# if temp > max_temp:
|
||||
# max_temp = temp
|
||||
|
||||
for chip, sensors in sensors_data.items():
|
||||
if in_blacklist(chip, CHIP_BLACKLIST):
|
||||
if self.in_blacklist(chip, CHIP_BLACKLIST):
|
||||
continue
|
||||
|
||||
for sensor, readings in sensors.items():
|
||||
if in_blacklist(sensor, SENSOR_BLACKLIST):
|
||||
if self.in_blacklist(sensor, SENSOR_BLACKLIST):
|
||||
continue
|
||||
|
||||
if type(readings) == str:
|
||||
|
@ -52,9 +49,15 @@ def main():
|
|||
if max_temp > CRIT:
|
||||
color = '#dd0000'
|
||||
|
||||
text = '\uf2c7 <span color="{}">{:.1f}°C</span>'.format(color, max_temp)
|
||||
return self.color_text(
|
||||
self.safe_text('{:.1f}°C'.format(max_temp)),
|
||||
color=color,
|
||||
)
|
||||
|
||||
print(text)
|
||||
|
||||
def main():
|
||||
block = Temp(ICON)
|
||||
block.render()
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
|
|
Loading…
Reference in a new issue