def init_sensors(self): sensors = {} if self.hwmonpath == '': print("WattmanGTK could not link the hwmon folder to the proper card, program will run without displaying any sensors") return sensors pattern = r"([a-zA-Z]{1,})(\d{1,})(_([a-zA-Z]{1,})|)(_([a-zA-Z]{1,})|)" files = "\n".join(os.listdir(self.hwmonpath)) for match in re.finditer(pattern,files): # check if sensor is empty print(f"Found sensor {match.group(0).rstrip()}") subsystem, sensornumber, attribute, subattribute = match.group(1,2,4,6) path = "/" + match.group(0).rstrip() print(f"Trying to read {self.hwmonpath + path}") value = read(self.hwmonpath + path) if value is None: print(f"Cannot read {self.hwmonpath + path}") continue if not subsystem in sensors: sensors.update({subsystem: {}}) if not sensornumber in sensors[subsystem]: sensors[subsystem].update({sensornumber: {}}) if attribute is None: sensors[subsystem][sensornumber].update({"value": value, "path": path}) else: if not attribute in sensors[subsystem][sensornumber]: sensors[subsystem][sensornumber].update({attribute: {}}) if subattribute is None: sensors[subsystem][sensornumber][attribute].update({"value": value, "path": path}) else: if not subattribute in sensors[subsystem][sensornumber][attribute]: sensors[subsystem][sensornumber][attribute].update({subattribute: {}}) sensors[subsystem][sensornumber][attribute][subattribute].update({"value": value, "path": path}) return sensors
def update_sensors(self, sensordict): for key, value in sensordict.items(): if type(value) is dict: self.update_sensors(value) elif key == "value": sensordict['value'] = read(self.hwmonpath + sensordict['path']) else: continue
def read_sensor(self,filename): return read(self.cardpath+"/"+filename)