fixed all pylint warnings

This commit is contained in:
2021-04-10 19:56:04 +02:00
parent 3cffd7fbb5
commit 4379a8edac

View File

@@ -22,17 +22,11 @@ class ThermalZone:
self.target = config["target"] self.target = config["target"]
self.hwmap = pyfan_parent.hwmap self.hwmap = pyfan_parent.hwmap
self.pyfan = pyfan_parent self.pyfan = pyfan_parent
self.alias_replace = re.compile('|'.join(self.hwmap.keys())) self.alias_replace = re.compile("|".join(self.hwmap.keys()))
self.setup_pwm() self.setup_pwm()
logging.getLogger("pyfan").info( logging.getLogger("pyfan").info("[%s] Source=%s Fans=%s Factor=%d PID=%f", self.name, self.temp_source,
"[{zone}] Source={source} Fans={fans} Factor={factor} PID={pid}".format(zone=self.name, self.fans, self.factor, (self.pid.Kp, self.pid.Ki, self.pid.Kd))
source=self.temp_source,
fans=self.fans,
factor=self.factor,
pid=(
self.pid.Kp, self.pid.Ki,
self.pid.Kd)))
def eval(self): def eval(self):
if self.get_temp(): if self.get_temp():
@@ -41,39 +35,35 @@ class ThermalZone:
try: try:
for target_fan in self.fans: for target_fan in self.fans:
if type(target_fan) is dict: if isinstance(target_fan, dict):
fan = list(target_fan.keys())[0] fan = list(target_fan.keys())[0]
fan_val = list(target_fan.values())[0] fan_val = list(target_fan.values())[0]
if type(fan_val) is list: if isinstance(fan_val, list):
if len(fan_val) < 2: if len(fan_val) < 2:
logging.getLogger("pyfan").warning( logging.getLogger("pyfan").warning(
"[%s] max/min for %s was not set correctly (%s)" % (self.name, fan, fan_val)) "[%s] max/min for %s was not set correctly (%s)", self.name, fan, fan_val)
self.write_sysfs(fan, min(fan_val[1], max(val, fan_val[0]))) self.write_sysfs(fan, min(fan_val[1], max(val, fan_val[0])))
else: else:
self.write_sysfs(fan, min(val, fan_val)) self.write_sysfs(fan, min(val, fan_val))
logging.getLogger("pyfan").debug( logging.getLogger("pyfan").debug("[%s] %s is set at %i%%", self.name, fan,
"[{name}] {fan} is set at {val}%".format(name=self.name, fan=fan, int(int(self.read_sysfs(fan)) / 255 * 100))
val=int(int(self.read_sysfs(fan)) / 255 * 100)))
else: else:
self.write_sysfs(target_fan, val) self.write_sysfs(target_fan, val)
except OSError as err: except OSError as err:
logging.getLogger("pyfan").warning( logging.getLogger("pyfan").warning("[%s] Failed to set pwm, trying to reset it. (%s)", self.name,
"[%s] Failed to set pwm, trying to reset it. (%s)" % (self.name, err.strerror)) err.strerror)
self.setup_pwm(1) self.setup_pwm(1)
p, i, d = self.pid.components p, i, d = self.pid.components
logging.getLogger("pyfan").debug( logging.getLogger("pyfan").debug("[%s] %i%% (%iC/%iC) (%f|%f|%f)", self.name, int(val / 255 * 100), diff,
"[{name}] {val}% ({diff}C/{temp}C) ({p}|{i}|{d})".format(name=self.name, val=int(val / 255 * 100), self.get_temp(), p, i, d)
diff=diff,
temp=self.get_temp(), p=int(p), i=int(i),
d=int(d)))
def get_temp(self): def get_temp(self):
if type(self.temp_source) is list: if isinstance(self.temp_source, list):
max_temp = -1.0 max_temp = -1.0
for fan in self.temp_source: for fan in self.temp_source:
if self.read_sysfs(fan): if self.read_sysfs(fan):
@@ -92,25 +82,24 @@ class ThermalZone:
def setup_pwm(self, value=1): def setup_pwm(self, value=1):
for target_fan in self.fans: for target_fan in self.fans:
try: try:
if type(target_fan) is dict: if isinstance(target_fan, dict):
self.set_pwm_mode(list(target_fan.keys())[0], value) self.set_pwm_mode(list(target_fan.keys())[0], value)
else: else:
self.set_pwm_mode(target_fan, value) self.set_pwm_mode(target_fan, value)
except FileNotFoundError: except FileNotFoundError:
logging.getLogger("pyfan").warning("[%s] pwm not found." logging.getLogger("pyfan").warning("[%s] pwm not found. Try reloading hwmon map...", self.name)
" Try reloading hwmon map..." % self.name)
self.hwmap = self.pyfan.hwmap self.hwmap = self.pyfan.hwmap
def replace_alias(self, path): def replace_alias(self, path):
replaced = self.alias_replace.sub(lambda x: self.hwmap[x.group()], path) replaced = self.alias_replace.sub(lambda x: self.hwmap[x.group()], path)
logging.getLogger("pyfan").debug("[ALIAS] %s -> %s" % (path, replaced)) logging.getLogger("pyfan").debug("[ALIAS] %s -> %s", path, replaced)
return replaced return replaced
def build_pwm_path(self, specific): def build_pwm_path(self, specific):
return self.replace_alias(SYSFS_HWMON_BASE + specific) return self.replace_alias(SYSFS_HWMON_BASE + specific)
def write_sysfs(self, path, value): def write_sysfs(self, path, value):
with open(self.build_pwm_path(path), 'w') as sysfs_f: with open(self.build_pwm_path(path), "w") as sysfs_f:
sysfs_f.write(str(value)) sysfs_f.write(str(value))
def read_sysfs(self, path): def read_sysfs(self, path):
@@ -118,9 +107,8 @@ class ThermalZone:
with open(self.build_pwm_path(path)) as sysfs_f: with open(self.build_pwm_path(path)) as sysfs_f:
return sysfs_f.readline() return sysfs_f.readline()
except FileNotFoundError as err: except FileNotFoundError as err:
logging.getLogger("pyfan").warning( logging.getLogger("pyfan").warning("[%s] temp source not found. Not ready yet or wrong path? (%s)",
"[%s] temp source not found. Not ready yet or wrong path? (%s)" % (self.name, self.name, err.strerror)
err.strerror))
return None return None
def set_pwm_mode(self, path, value=1): def set_pwm_mode(self, path, value=1):
@@ -143,7 +131,7 @@ class PyFan:
self.zones.append(ThermalZone(zone, self)) self.zones.append(ThermalZone(zone, self))
logging.getLogger("pyfan").info( logging.getLogger("pyfan").info(
"Finished creating %d thermal zones, checking all %d seconds" % (len(self.zones), self.interval)) "Finished creating %d thermal zones, checking all %d seconds", len(self.zones), self.interval)
def __enter__(self): def __enter__(self):
return self return self