global: 'Dream Multimedia' -> 'Dream Property'
[enigma2-plugins.git] / fancontrol2 / src / Sensors.py
1 class Sensors:
2         # (type, name, unit, directory)
3         TYPE_TEMPERATURE = 0
4         # (type, name, unit, fanid)
5 #       TYPE_FAN_RPM = 1
6         
7         def __init__(self):
8                 # (type, name, unit, sensor_specific_dict/list)
9                 self.sensors_list = []
10                 self.addSensors()
11                 
12         def getSensorsCount(self, type = None):
13                 if type is None:
14                         return len(self.sensors_list)
15                 count = 0
16                 for sensor in self.sensors_list:
17                         if sensor[0] == type:
18                                 count += 1
19                 return count
20         
21         # returns a list of sensorids of type "type"
22         def getSensorsList(self, type = None):
23                 if type is None:
24                         return range(len(self.sensors_list))
25                 list = []
26                 for sensorid in range(len(self.sensors_list)):
27                         if self.sensors_list[sensorid][0] == type:
28                                 list.append(sensorid)
29                 return list
30
31         def getSensorType(self, sensorid):
32                 return self.sensors_list[sensorid][0]
33
34         def getSensorName(self, sensorid):
35                 return self.sensors_list[sensorid][1]
36
37         def getSensorDir(self, sensorid):
38                 return self.sensors_list[sensorid][3]
39
40         def getSensorValue(self, sensorid):
41                 value = -1
42                 sensor = self.sensors_list[sensorid]
43                 if sensor[0] == self.TYPE_TEMPERATURE:
44                         f = open("%s/value" % sensor[3], "r")
45                         value = int(f.readline().strip() or "0")
46                         f.close()
47                 return value
48
49         def addSensors(self):
50                 import os
51                 if os.path.exists("/proc/stb/sensors"):
52                         sd = []
53                         sd = os.listdir("/proc/stb/sensors")
54                         sd.sort()
55                         for dirname in sd:
56                                 if dirname.find("temp", 0, 4) == 0:
57                                         f = open("/proc/stb/sensors/%s/name" % dirname, "r")
58                                         name = f.readline().strip()
59                                         f.close()
60                                         
61                                         f = open("/proc/stb/sensors/%s/unit" % dirname, "r")
62                                         unit = f.readline().strip()
63                                         f.close()
64                                         
65                                         self.sensors_list.append((self.TYPE_TEMPERATURE, name, unit, "/proc/stb/sensors/%s" % dirname))
66
67 sensors = Sensors()