Yet Another WebIOPi+
 All Classes Namespaces Files Functions Variables Macros Pages
onewiretemp.py
Go to the documentation of this file.
1 # Copyright 2012-2013 Eric Ptak - trouch.com
2 #
3 # Licensed under the Apache License, Version 2.0 (the "License");
4 # you may not use this file except in compliance with the License.
5 # You may obtain a copy of the License at
6 #
7 # http://www.apache.org/licenses/LICENSE-2.0
8 #
9 # Unless required by applicable law or agreed to in writing, software
10 # distributed under the License is distributed on an "AS IS" BASIS,
11 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 # See the License for the specific language governing permissions and
13 # limitations under the License.
14 
15 import sys
16 from webiopi.devices.onewire import OneWire
17 from webiopi.devices.sensor import Temperature
18 
20  def __init__(self, slave=None, family=0, name="1-Wire"):
21  OneWire.__init__(self, slave, family, "TEMP")
22  self.name = name
23 
24  def __str__(self):
25  return "%s(slave=%s)" % (self.name, self.slave)
26 
27  def __getKelvin__(self):
28  return self.Celsius2Kelvin()
29 
30  def __getCelsius__(self):
31  data = self.read()
32  lines = data.split("\n")
33  if lines[0].endswith("YES"):
34  i = lines[1].find("=")
35  temp = lines[1][i+1:]
36  return int(temp) / 1000.0
37  return (-sys.maxsize - 1) / 1000.0
38 
39  def __getFahrenheit__(self):
40  return self.Celsius2Fahrenheit()
41 
43  def __init__(self, slave=None):
44  OneWireTemp.__init__(self, slave, 0x10, "DS18S20")
45 
47  def __init__(self, slave=None):
48  OneWireTemp.__init__(self, slave, 0x22, "DS1822")
49 
51  def __init__(self, slave=None):
52  OneWireTemp.__init__(self, slave, 0x28, "DS18B20")
53 
55  def __init__(self, slave=None):
56  OneWireTemp.__init__(self, slave, 0x3B, "DS1825")
57 
59  def __init__(self, slave=None):
60  OneWireTemp.__init__(self, slave, 0x42, "DS28EA00")