fixed all pylint warnings
This commit is contained in:
52
pyfan.py
52
pyfan.py
@@ -22,17 +22,11 @@ class ThermalZone:
|
||||
self.target = config["target"]
|
||||
self.hwmap = pyfan_parent.hwmap
|
||||
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()
|
||||
|
||||
logging.getLogger("pyfan").info(
|
||||
"[{zone}] Source={source} Fans={fans} Factor={factor} PID={pid}".format(zone=self.name,
|
||||
source=self.temp_source,
|
||||
fans=self.fans,
|
||||
factor=self.factor,
|
||||
pid=(
|
||||
self.pid.Kp, self.pid.Ki,
|
||||
self.pid.Kd)))
|
||||
logging.getLogger("pyfan").info("[%s] Source=%s Fans=%s Factor=%d PID=%f", self.name, self.temp_source,
|
||||
self.fans, self.factor, (self.pid.Kp, self.pid.Ki, self.pid.Kd))
|
||||
|
||||
def eval(self):
|
||||
if self.get_temp():
|
||||
@@ -41,39 +35,35 @@ class ThermalZone:
|
||||
|
||||
try:
|
||||
for target_fan in self.fans:
|
||||
if type(target_fan) is dict:
|
||||
if isinstance(target_fan, dict):
|
||||
fan = list(target_fan.keys())[0]
|
||||
fan_val = list(target_fan.values())[0]
|
||||
|
||||
if type(fan_val) is list:
|
||||
if isinstance(fan_val, list):
|
||||
if len(fan_val) < 2:
|
||||
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])))
|
||||
else:
|
||||
self.write_sysfs(fan, min(val, fan_val))
|
||||
|
||||
logging.getLogger("pyfan").debug(
|
||||
"[{name}] {fan} is set at {val}%".format(name=self.name, fan=fan,
|
||||
val=int(int(self.read_sysfs(fan)) / 255 * 100)))
|
||||
logging.getLogger("pyfan").debug("[%s] %s is set at %i%%", self.name, fan,
|
||||
int(int(self.read_sysfs(fan)) / 255 * 100))
|
||||
else:
|
||||
self.write_sysfs(target_fan, val)
|
||||
except OSError as err:
|
||||
logging.getLogger("pyfan").warning(
|
||||
"[%s] Failed to set pwm, trying to reset it. (%s)" % (self.name, err.strerror))
|
||||
logging.getLogger("pyfan").warning("[%s] Failed to set pwm, trying to reset it. (%s)", self.name,
|
||||
err.strerror)
|
||||
self.setup_pwm(1)
|
||||
|
||||
p, i, d = self.pid.components
|
||||
|
||||
logging.getLogger("pyfan").debug(
|
||||
"[{name}] {val}% ({diff}C/{temp}C) ({p}|{i}|{d})".format(name=self.name, val=int(val / 255 * 100),
|
||||
diff=diff,
|
||||
temp=self.get_temp(), p=int(p), i=int(i),
|
||||
d=int(d)))
|
||||
logging.getLogger("pyfan").debug("[%s] %i%% (%iC/%iC) (%f|%f|%f)", self.name, int(val / 255 * 100), diff,
|
||||
self.get_temp(), p, i, d)
|
||||
|
||||
def get_temp(self):
|
||||
if type(self.temp_source) is list:
|
||||
if isinstance(self.temp_source, list):
|
||||
max_temp = -1.0
|
||||
for fan in self.temp_source:
|
||||
if self.read_sysfs(fan):
|
||||
@@ -92,25 +82,24 @@ class ThermalZone:
|
||||
def setup_pwm(self, value=1):
|
||||
for target_fan in self.fans:
|
||||
try:
|
||||
if type(target_fan) is dict:
|
||||
if isinstance(target_fan, dict):
|
||||
self.set_pwm_mode(list(target_fan.keys())[0], value)
|
||||
else:
|
||||
self.set_pwm_mode(target_fan, value)
|
||||
except FileNotFoundError:
|
||||
logging.getLogger("pyfan").warning("[%s] pwm not found."
|
||||
" Try reloading hwmon map..." % self.name)
|
||||
logging.getLogger("pyfan").warning("[%s] pwm not found. Try reloading hwmon map...", self.name)
|
||||
self.hwmap = self.pyfan.hwmap
|
||||
|
||||
def replace_alias(self, 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
|
||||
|
||||
def build_pwm_path(self, specific):
|
||||
return self.replace_alias(SYSFS_HWMON_BASE + specific)
|
||||
|
||||
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))
|
||||
|
||||
def read_sysfs(self, path):
|
||||
@@ -118,9 +107,8 @@ class ThermalZone:
|
||||
with open(self.build_pwm_path(path)) as sysfs_f:
|
||||
return sysfs_f.readline()
|
||||
except FileNotFoundError as err:
|
||||
logging.getLogger("pyfan").warning(
|
||||
"[%s] temp source not found. Not ready yet or wrong path? (%s)" % (self.name,
|
||||
err.strerror))
|
||||
logging.getLogger("pyfan").warning("[%s] temp source not found. Not ready yet or wrong path? (%s)",
|
||||
self.name, err.strerror)
|
||||
return None
|
||||
|
||||
def set_pwm_mode(self, path, value=1):
|
||||
@@ -143,7 +131,7 @@ class PyFan:
|
||||
self.zones.append(ThermalZone(zone, self))
|
||||
|
||||
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):
|
||||
return self
|
||||
|
Reference in New Issue
Block a user