4
# Copyright 2008-2009 Grega Podlesek <grega.podlesek@gmail.com>
6
# This program is free software; you can redistribute it and/or modify
7
# it under the terms of the GNU General Public License as published by
8
# the Free Software Foundation; either version 2 of the License, or
9
# (at your option) any later version.
11
# This program is distributed in the hope that it will be useful,
12
# but WITHOUT ANY WARRANTY; without even the implied warranty of
13
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14
# GNU General Public License for more details.
16
# You should have received a copy of the GNU General Public License
17
# along with this program; if not, write to the Free Software
18
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
25
from sensorinterface import Sensor
26
from sensorinterface import Updater
27
from sensorvalues.tempvalue import TempValue
29
from sensorvalues import units
31
interface_name = "HDDTemp"
32
hddtemp_address = ("127.0.0.1", 7634)
35
class HDDTempSensor(Sensor):
37
def __init__(self, name, seq_num, updater):
38
Sensor.__init__(self, name, name, TempValue())
39
self.__seq_num = seq_num
40
self.updater = updater
41
self.interface = interface_name
43
def read_sensor(self):
44
input = self.updater.get_update()
47
self.value = float(input[3 + 5 * self.__seq_num])
51
def get_hddtemp_output():
53
htsocket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
54
htsocket.connect(hddtemp_address)
56
htin = htsocket.recv(256)
59
htin = htsocket.recv(256)
61
except socket.error, (errno, errorstr):
62
print "HDDTemp sensors interface:", \
63
"Socket error(%s): %s" % (errno, errorstr)
67
return input.split('|')
72
updater = Updater(60, get_hddtemp_output)
73
input = get_hddtemp_output()
76
# Number of hdd sensors
77
n = (len(input) - 1) / 5
78
for i in xrange(0, n):
79
new_sensor = HDDTempSensor(input[1 + 5 * i], i, updater)
80
new_sensor.label = input[2 + 5 * i]
81
unit = input[4 + 5 * i]
84
new_sensor.unit = units.UNIT_CELSIUS
86
new_sensor.unit = units.UNIT_FAHRENHEIT
88
new_sensor.unit = units.UNIT_KELVIN
90
print "HDDTemp sensors interface: unknown unit:", unit
92
htsensors.append(new_sensor)