reformat with black;
use pwm_min of 1 since newer kernels have different behaviour on pwm=0
This commit is contained in:
parent
6632f364ff
commit
0800a3e2e8
85
pyfan.py
85
pyfan.py
|
@ -26,15 +26,31 @@ class ThermalZone:
|
|||
config["interval"] = 3
|
||||
logging.getLogger("pyfan").warning(
|
||||
"[%s] No interval specified, using default. This is deprecated since 1.6 and may be removed in future "
|
||||
"versions. See example config for reference.", self.name)
|
||||
"versions. See example config for reference.",
|
||||
self.name,
|
||||
)
|
||||
|
||||
self.pid = PID(config["pid"]["p"], config["pid"]["i"], config["pid"]["d"], setpoint=0,
|
||||
sample_time=config["interval"])
|
||||
self.pid.output_limits = (0, 255)
|
||||
self.pid = PID(
|
||||
config["pid"]["p"],
|
||||
config["pid"]["i"],
|
||||
config["pid"]["d"],
|
||||
setpoint=0,
|
||||
sample_time=config["interval"],
|
||||
)
|
||||
|
||||
# we prefer 3 for pwm_enable, but since some chips do not support this mode, use 1 with pwm_min of 1 as fallback
|
||||
# more on pwm=0 behaviour: https://www.kernel.org/doc/html/latest/hwmon/pwm-fan.html
|
||||
self.pid.output_limits = (1, 255)
|
||||
self.setup_pwm()
|
||||
|
||||
logging.getLogger("pyfan").info("[%s] Source=%s Fans=%s Factor=%f %s", self.name, self.temp_source,
|
||||
self.fans, self.factor, self.pid)
|
||||
logging.getLogger("pyfan").info(
|
||||
"[%s] Source=%s Fans=%s Factor=%f %s",
|
||||
self.name,
|
||||
self.temp_source,
|
||||
self.fans,
|
||||
self.factor,
|
||||
self.pid,
|
||||
)
|
||||
|
||||
def eval(self):
|
||||
if self.get_temp():
|
||||
|
@ -50,24 +66,46 @@ class ThermalZone:
|
|||
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,
|
||||
)
|
||||
|
||||
if self.read_sysfs(fan) != min(fan_val[1], max(val, fan_val[0])):
|
||||
self.write_sysfs(fan, min(fan_val[1], max(val, fan_val[0])))
|
||||
if self.read_sysfs(fan) != min(
|
||||
fan_val[1], max(val, fan_val[0])
|
||||
):
|
||||
self.write_sysfs(
|
||||
fan, min(fan_val[1], max(val, fan_val[0]))
|
||||
)
|
||||
elif self.read_sysfs(fan) != min(val, fan_val):
|
||||
self.write_sysfs(fan, min(val, fan_val))
|
||||
|
||||
logging.getLogger("pyfan").debug("[%s] %s=%i%%", self.name, fan,
|
||||
int(int(self.read_sysfs(fan)) / 255 * 100))
|
||||
logging.getLogger("pyfan").debug(
|
||||
"[%s] %s=%i%%",
|
||||
self.name,
|
||||
fan,
|
||||
int(int(self.read_sysfs(fan)) / 255 * 100),
|
||||
)
|
||||
elif self.read_sysfs(target_fan) != val:
|
||||
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)
|
||||
|
||||
logging.getLogger("pyfan").debug("[%s] %i%% D:%iC T:%iC %s", self.name, int(val / 255 * 100), diff,
|
||||
self.get_temp(), self.pid)
|
||||
logging.getLogger("pyfan").debug(
|
||||
"[%s] %i%% D:%iC T:%iC %s",
|
||||
self.name,
|
||||
int(val / 255 * 100),
|
||||
diff,
|
||||
self.get_temp(),
|
||||
self.pid,
|
||||
)
|
||||
|
||||
def get_temp(self):
|
||||
if isinstance(self.temp_source, list):
|
||||
|
@ -94,7 +132,9 @@ class ThermalZone:
|
|||
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):
|
||||
|
@ -114,8 +154,11 @@ 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):
|
||||
|
@ -131,7 +174,8 @@ class PyFan:
|
|||
self.interval = 0.2
|
||||
logging.getLogger("pyfan").warning(
|
||||
"No pid_interval specified, using default. This is deprecated since 1.6 and may be removed in future "
|
||||
"versions. See example config for reference.")
|
||||
"versions. See example config for reference."
|
||||
)
|
||||
else:
|
||||
self.interval = self.config["pid_interval"]
|
||||
|
||||
|
@ -139,7 +183,8 @@ class PyFan:
|
|||
self.zones.append(ThermalZone(zone, self))
|
||||
|
||||
logging.getLogger("pyfan").info(
|
||||
"Created %d thermal zones, pid_interval=%f.", len(self.zones), self.interval)
|
||||
"Created %d thermal zones, pid_interval=%f.", len(self.zones), self.interval
|
||||
)
|
||||
|
||||
def __enter__(self):
|
||||
return self
|
||||
|
|
Loading…
Reference in New Issue