~ubuntu-branches/ubuntu/vivid/computertemp/vivid

« back to all changes in this revision

Viewing changes to computertemp/temp_hddtemp.py

  • Committer: Bazaar Package Importer
  • Author(s): Loic Minier
  • Date: 2007-03-28 22:05:58 UTC
  • Revision ID: james.westby@ubuntu.com-20070328220558-cpo9o1k61ayi23x4
Tags: upstream-0.9.6
Import upstream version 0.9.6

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
# -*- coding: UTF-8 -*-
 
2
 
 
3
# +-------------------------------------------------------------------------------------+
 
4
# | GPL                                                                                 |
 
5
# +-------------------------------------------------------------------------------------+
 
6
# | Copyright (c) 2005,2006 Adolfo González Blázquez <code@infinicode.org>      |
 
7
# |                                                                                     |
 
8
# | This program is free software; you can redistribute it and/or                       |
 
9
# | modify it under the terms of the GNU General Public License                         |
 
10
# | as published by the Free Software Foundation; either version 2                      |
 
11
# | of the License, or (at your option) any later version.                              |
 
12
# |                                                                                     |
 
13
# | This program is distributed in the hope that it will be useful,                     |
 
14
# | but WITHOUT ANY WARRANTY; without even the implied warranty of                      |
 
15
# | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the                       |
 
16
# | GNU General Public License for more details.                                        |
 
17
# |                                                                                     |
 
18
# | You should have received a copy of the GNU General Public License                   |
 
19
# | along with this program; if not, write to the Free Software                         |
 
20
# | Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.      |
 
21
# +-------------------------------------------------------------------------------------+
 
22
 
 
23
from telnetlib import Telnet
 
24
 
 
25
class TempFuncs:
 
26
 
 
27
        def __init__(self):
 
28
        
 
29
                self.host = 'localhost'
 
30
                self.port = 7634
 
31
                
 
32
                self.get_data()
 
33
 
 
34
        # Read data from hddtemp telnet interface
 
35
        def get_data(self):
 
36
                self.hds = []
 
37
                try:
 
38
                        tn = Telnet(self.host, self.port)
 
39
                        data = tn.read_all()
 
40
                        tn.close()
 
41
                        data = data.split('||')
 
42
                        for i in data: self.hds.append(i.lstrip('|').rstrip('|').split('|'))
 
43
                except:
 
44
                        self.hds = None
 
45
 
 
46
        # Get the name of the hardware sensor
 
47
        def get_sensor_name(self): return 'HDDTEMP'
 
48
 
 
49
        # Is there acpi thermal_zone support on machine?
 
50
        def temp_support(self):
 
51
                if self.hds != None: return True
 
52
                else: return False
 
53
 
 
54
 
 
55
        # Return a list with the thermal zones availables
 
56
        def get_zones(self): 
 
57
                if self.temp_support():
 
58
                        return range(len(self.hds))
 
59
 
 
60
 
 
61
        # Return zone name at position num
 
62
        def get_zone_name(self, num):
 
63
                if self.temp_support():
 
64
                        return num
 
65
                else: return None
 
66
 
 
67
                
 
68
        # Return zone name to display at position num
 
69
        def get_zone_display_name(self, num):
 
70
                return self.hds[num][1] + ' (' + self.hds[num][0] + ')'
 
71
 
 
72
 
 
73
        # Reads temperature from zone
 
74
        def get_zone_temp(self, zone):
 
75
                if self.temp_support():
 
76
                        self.get_data()
 
77
                        return self.hds[int(zone)][2]
 
78
                else:
 
79
                        return 0