changeset 229:99255c501e02

test sensor
author Matt Johnston <matt@ucc.asn.au>
date Fri, 10 Apr 2015 23:55:07 +0800
parents d9e81a563923
children 185621f47040
files py/sensor_test.py py/tempserver.py
diffstat 2 files changed, 38 insertions(+), 3 deletions(-) [+]
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/py/sensor_test.py	Fri Apr 10 23:55:07 2015 +0800
@@ -0,0 +1,35 @@
+import asyncio
+
+class SensorTest(object):
+
+    def __init__(self, server):
+        self.server = server
+        
+    def kill(self):
+        L("Killed SensorTest")
+
+    def make_vals(self):
+        def try_read(f, fallback):
+            try:
+                return open(f, 'r').read()
+            except Exception, e:
+                return fallback
+
+        vals = {}
+        vals[self.wort_name()] = try_read('test_wort.txt', 18)
+        vals[self.fridge_name()] = try_read('test_fridge.txt', 20)
+        vals['ambient'] = 31.2
+        return vals
+
+    def run(self):
+
+        while True:
+            yield from asyncio.sleep(1)
+            vals = self.make_vals()
+            self.server.add_reading(vals)
+
+    def wort_name(self):
+        return '28-wortname'
+
+    def fridge_name(self):
+        return '28-fridgename'
--- a/py/tempserver.py	Fri Mar 20 20:12:25 2015 +0800
+++ b/py/tempserver.py	Fri Apr 10 23:55:07 2015 +0800
@@ -31,7 +31,7 @@
         self.fridge = fridge.Fridge(self)
         self.uploader = uploader.Uploader(self)
         self.params.load()
-        self.set_sensors(sensor_ds18b20.DS18B20s(self))
+        self.set_sensors(sensor.make_sensor(self))
         asyncio.get_event_loop().add_signal_handler(signal.SIGHUP, self._reload_signal)
         return self
 
@@ -102,7 +102,7 @@
             L("Reloaded.")
             self._wakeup.set()
             self._wakeup.clear()
-        except self.Error, e:
+        except Error as e:
             W("Problem reloading: %s" % str(e))
 
 def setup_logging():
@@ -124,7 +124,7 @@
     try:
         pidf.acquire(1)
         pidf.release()
-    except (lockfile.AlreadyLocked, lockfile.LockTimeout), e:
+    except (lockfile.AlreadyLocked, lockfile.LockTimeout) as e:
         pid = pidf.read_pid()
         if do_hup:
             try: