Merge remote branch 'remotes/origin/fantempplugin'
[enigma2.git] / lib / python / Components / Sources / Sensor.py
1 from Components.Sensors import sensors
2
3 from enigma import eTimer
4
5 from Source import Source
6
7 class SensorSource(Source):
8         def __init__(self, update_interval = 500, sensorid = None):
9                 self.update_interval = update_interval
10                 self.sensorid = sensorid
11                 Source.__init__(self)
12
13                 if sensorid is not None:
14                         self.update_timer = eTimer()
15                         self.update_timer.callback.append(self.updateValue)
16                         self.update_timer.start(self.update_interval)
17
18         def getValue(self):
19                 if self.sensorid is not None:
20                         return sensors.getSensorValue(self.sensorid)
21                 return None
22         
23         def getUnit(self):
24                 return sensors.getSensorUnit(self.sensorid)
25
26         def updateValue(self):
27                 self.changed((self.CHANGED_POLL,))
28
29         def destroy(self):
30                 if self.sensorid is not None:
31                         self.update_timer.callback.remove(self.updateValue)