-
Notifications
You must be signed in to change notification settings - Fork 11
/
Copy pathexample.py
executable file
·40 lines (29 loc) · 1.36 KB
/
example.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
#!/usr/bin/env python3
"""
@author: Pavel Rojtberg (http://www.rojtberg.net)
@see: https://github.com/paroj/sensors.py
@copyright: The MIT License (MIT) <http://opensource.org/licenses/MIT>
"""
import sensors
def print_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 = [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)
return
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])
print("\t"+label+"\t"+str_data)
if __name__ == "__main__":
sensors.init() # optionally takes config file
print("libsensors version: "+sensors.version)
for chip in sensors.ChipIterator(): # optional arg like "coretemp-*" restricts iterator
print(sensors.chip_snprintf_name(chip)+" ("+sensors.get_adapter_name(chip.bus)+")")
for feature in sensors.FeatureIterator(chip):
print_feature(chip, feature)
sensors.cleanup()