def check_feature(chip, feature): sfs = list(sensors.SubFeatureIterator(chip, feature)) # get a list of all subfeatures label = sensors.get_label(chip, feature) skipname = len(feature.name)+1 # skip common prefix # vals is a list of value min and max vals = [sensors.get_value(chip, sf.number) for sf in sfs] if feature.type == sensors.feature.INTRUSION: # short path for INTRUSION to demonstrate type usage status = "alarm" if int(vals[0]) == 1 else "normal" print("\t"+label+"\t"+status) names = [sf.name[skipname:].decode("utf-8") for sf in sfs] data = list(zip(names, vals)) str_data = ", ".join([e[0]+": "+str(e[1]) for e in data]) if vals[2] > value_max[label]: print("\tCheck "+src[label]+"\tFAILED! "+str(vals[2])+" > "+str(value_max[label])+")") return False if vals[1] < value_min[label]: print("\tCheck "+src[label]+"\tFAILED! "+str(vals[1])+" < "+str(value_min[label])+")") return False print("\tCheck "+src[label]+"\t"+"\t("+str(vals[0])+") ....OK") return True
def print_feature(chip, feature): sfs = list(sensors.SubFeatureIterator(chip, feature)) # get a list of all subfeatures label = sensors.get_label(chip, feature) skip_name = len(feature.name) + 1 # skip common prefix values = [sensors.get_value(chip, sf.number) for sf in sfs] if feature.type == sensors.Feature.INTRUSION: # short path for INTRUSION to demonstrate type usage status = "alarm" if int(values[0]) == 1 else "normal" print("\t" + label + "\t" + status) return names = [sf.name[skip_name:].decode("utf-8") for sf in sfs] data = list(zip(names, values)) str_data = ", ".join([e[0] + ": " + str(e[1]) for e in data]) print("\t" + label + "\t" + str_data)
def coretemp(): rv = {} for chip in sensors.ChipIterator(): chipname = sensors.chip_snprintf_name(chip) if "temp" not in chipname: continue chipdata = {} for feature in sensors.FeatureIterator(chip): label = sensors.get_label(chip, feature) sfs = list(sensors.SubFeatureIterator(chip, feature)) # get a list of all subfeatures vals = [sensors.get_value(chip, sf.number) for sf in sfs] names = [sf.name[len(feature.name)+1:].decode("utf-8") for sf in sfs] data = dict(zip(names, vals)) # We use the label instead of the name because the name is typically unhelpful. chipdata[sanitizeName(label)] = data["input"] rv[chipname] = chipdata return rv
def get_temp(): sensors.init() temp = 0 try: for chip in sensors.ChipIterator(): for feature in sensors.FeatureIterator(chip): subs = list(sensors.SubFeatureIterator(chip, feature)) try: sensor_temp = sensors.get_value(chip, subs[0].number) # el 200 es por que en las maquinas de desarrollo devuelve # los RPM de los ventiladores como features. Esta es la # solucion menos compleja para descartar ese valor. if sensor_temp < 200 and sensor_temp > temp: temp = sensor_temp except Exception: # alguno de los sensores no se pudo leer. en circunstancias # normales no pasa pero atajamoe el error para que siga con # el resto de las featuras pass finally: sensors.cleanup() return temp