141
|
1 #!/usr/bin/env python2.7 |
|
2 |
|
3 import sys |
|
4 import os |
|
5 import gevent |
|
6 |
|
7 import utils |
|
8 |
|
9 class Tempserver(object): |
|
10 def __init__(self): |
|
11 self.readings = [] |
|
12 self.current = (None, None, None) |
|
13 |
|
14 self.start_time = utils.monotonic_time() |
|
15 |
144
|
16 self.fridge = fridge.Fridge(self) |
|
17 self.fridge.start() |
|
18 |
|
19 self.set_sensors(sensor_ds18b20.DS18B20s(self)) |
141
|
20 |
144
|
21 def set_sensors(self, sensors): |
|
22 if self.hasattr(self, 'sensors'): |
|
23 self.sensors.kill() |
|
24 self.sensors = sensors |
|
25 self.wort_name = sensors.wort_name() |
|
26 self.fridge_name = sensors.fridge_name() |
|
27 self.sensor_names = sensors.sensor_names() |
141
|
28 |
|
29 def take_readings(self): |
|
30 ret = self.readings |
|
31 self.readings = [] |
|
32 return ret |
|
33 |
|
34 def pushfront(self, readings): |
|
35 """ used if a caller of take_readings() fails """ |
|
36 self.readings = pushback + self.readings |
|
37 |
144
|
38 # a reading is a map of {sensorname: value}. temperatures |
|
39 # are float degrees |
141
|
40 def add_reading(self, reading): |
|
41 """ adds a reading at the current time """ |
|
42 self.readings.append( (reading, utils.monotonic_time())) |
144
|
43 self.current = (reading.get(self.wort_name, None), |
|
44 reading.get(self.fridge_name, None)) |
141
|
45 |
|
46 def current_temps(self): |
144
|
47 """ returns (wort_temp, fridge_temp) tuple """ |
141
|
48 return current |