added reloading of hwmap after file not found errors
This commit is contained in:
29
pyfan.py
29
pyfan.py
@@ -12,7 +12,7 @@ SYSFS_HWMON_BASE = "/sys/class/hwmon/"
|
|||||||
|
|
||||||
|
|
||||||
class ThermalZone:
|
class ThermalZone:
|
||||||
def __init__(self, config, hwmon_map) -> None:
|
def __init__(self, config, pyfan_parent) -> None:
|
||||||
self.fans = config["fan"]
|
self.fans = config["fan"]
|
||||||
self.temp_source = config["source"]
|
self.temp_source = config["source"]
|
||||||
self.pid = PID(config["pid"]["p"], config["pid"]["i"], config["pid"]["d"], setpoint=0)
|
self.pid = PID(config["pid"]["p"], config["pid"]["i"], config["pid"]["d"], setpoint=0)
|
||||||
@@ -20,7 +20,8 @@ class ThermalZone:
|
|||||||
self.factor = 1 / config["factor"]
|
self.factor = 1 / config["factor"]
|
||||||
self.name = config["name"]
|
self.name = config["name"]
|
||||||
self.target = config["target"]
|
self.target = config["target"]
|
||||||
self.hwmap = hwmon_map
|
self.hwmap = pyfan.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()
|
self.setup_pwm()
|
||||||
|
|
||||||
@@ -89,7 +90,8 @@ class ThermalZone:
|
|||||||
self.set_pwm_mode(target_fan, value)
|
self.set_pwm_mode(target_fan, value)
|
||||||
except FileNotFoundError as err:
|
except FileNotFoundError as err:
|
||||||
logging.getLogger("pyfan").warning("[%s] pwm not found."
|
logging.getLogger("pyfan").warning("[%s] pwm not found."
|
||||||
" Not ready yet or wrong path? (%s)" % (self.name, err.strerror))
|
" Try reloading hwmon map..." % self.name)
|
||||||
|
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)
|
||||||
@@ -122,8 +124,7 @@ class PyFan:
|
|||||||
self.config = self.__load_config(config)
|
self.config = self.__load_config(config)
|
||||||
logging.basicConfig(level=logging.getLevelName(self.config["loglevel"]))
|
logging.basicConfig(level=logging.getLevelName(self.config["loglevel"]))
|
||||||
self.zones = []
|
self.zones = []
|
||||||
self.hwmon_map = {}
|
self._hwmon_map = {}
|
||||||
self.gen_hwmon_map()
|
|
||||||
|
|
||||||
if "interval" in self.config:
|
if "interval" in self.config:
|
||||||
self.interval = self.config["interval"]
|
self.interval = self.config["interval"]
|
||||||
@@ -131,7 +132,7 @@ class PyFan:
|
|||||||
self.interval = 1
|
self.interval = 1
|
||||||
|
|
||||||
for zone in self.config["thermalzones"]:
|
for zone in self.config["thermalzones"]:
|
||||||
self.zones.append(ThermalZone(zone, self.hwmon_map))
|
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))
|
||||||
@@ -147,19 +148,23 @@ class PyFan:
|
|||||||
for zone in self.zones:
|
for zone in self.zones:
|
||||||
zone.eval()
|
zone.eval()
|
||||||
|
|
||||||
@staticmethod
|
@property
|
||||||
def __load_config(path):
|
def hwmap(self):
|
||||||
with open(path) as cfg_file:
|
self._hwmon_map.clear()
|
||||||
return yaml.safe_load(cfg_file)
|
|
||||||
|
|
||||||
def gen_hwmon_map(self):
|
|
||||||
names = glob.glob(SYSFS_HWMON_BASE + "hwmon*/name")
|
names = glob.glob(SYSFS_HWMON_BASE + "hwmon*/name")
|
||||||
|
|
||||||
for name in names:
|
for name in names:
|
||||||
hwmon = name.split("/")[-2]
|
hwmon = name.split("/")[-2]
|
||||||
with open(name) as file:
|
with open(name) as file:
|
||||||
hwname = file.read().strip()
|
hwname = file.read().strip()
|
||||||
self.hwmon_map[hwname] = hwmon
|
self._hwmon_map[hwname] = hwmon
|
||||||
|
return self._hwmon_map
|
||||||
|
|
||||||
|
@staticmethod
|
||||||
|
def __load_config(path):
|
||||||
|
with open(path) as cfg_file:
|
||||||
|
return yaml.safe_load(cfg_file)
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
|
Reference in New Issue
Block a user