Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
from __future__ import print_function
import sys
import codecs
from urllib.parse import quote
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ def set_fan_speed(client):

# DeviceBase interface methods:
def get_name(self):
return f"counter-rotating-fan-{self.__num}"
return ("counter-rotating-fan-" + str(self.__num))

def get_presence(self):
return _fan_info_get(self.__num, lambda _: True, False)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,14 @@
temp2_input: 37.000
...
'''
def _sensors_chip_parsed(data: str):
def _sensors_chip_parsed(data):
def kv(line):
k, v, *_ = [t.strip(': ') for t in line.split(':') if t] + ['']
k, v = [t.strip(': ') for t in line.split(':') if t] + ['']
return k, v

chip, *data = data.strip().split('\n')
data = data.split("\n")
chip = data[0]
data.remove(chip)
chip = chip.strip(': ')

sensors = []
Expand All @@ -34,7 +36,7 @@ def kv(line):
continue

if len(sensors) == 0:
raise RuntimeError(f'invalid data to parse: {data}')
raise RuntimeError('invalid data to parse: ' + str(data))

attr, value = kv(line)
sensor_label, sensor_data = sensors[-1]
Expand All @@ -51,7 +53,7 @@ def kv(line):
}
}
'''
def _sensors_get() -> dict:
def _sensors_get():
data = platform_sensors_get(['-A', '-u']) or ''
data += subprocess.check_output("/usr/bin/sensors -A -u",
shell=True, text=True)
Expand All @@ -60,7 +62,7 @@ def _sensors_get() -> dict:
data = dict(data)
return data

def _value_get(d: dict, key_prefix, key_suffix=''):
def _value_get(d, key_prefix, key_suffix=''):
for k, v in d.items():
if k.startswith(key_prefix) and k.endswith(key_suffix):
return v
Expand All @@ -71,7 +73,7 @@ class Thermal(ThermalBase):
def __init__(self, chip, label):
self.__chip = chip
self.__label = label
self.__name = f"{chip}:{label}".lower().replace(' ', '-')
self.__name = (str(chip) + ":" + str(label)).lower().replace(' ', '-')

def __get(self, attr_prefix, attr_suffix):
sensor_data = _sensors_get().get(self.__chip, {}).get(self.__label, {})
Expand All @@ -80,13 +82,13 @@ def __get(self, attr_prefix, attr_suffix):
raise NotImplementedError

# ThermalBase interface methods:
def get_temperature(self) -> float:
def get_temperature(self):
return float(self.__get('temp', 'input'))

def get_high_threshold(self) -> float:
def get_high_threshold(self):
return float(self.__get('temp', 'max'))

def get_high_critical_threshold(self) -> float:
def get_high_critical_threshold(self):
return float(self.__get('temp', 'crit'))

# DeviceBase interface methods:
Expand Down