Mercurial > templog
diff py/sensor_test.py @ 229:99255c501e02
test sensor
author | Matt Johnston <matt@ucc.asn.au> |
---|---|
date | Fri, 10 Apr 2015 23:55:07 +0800 |
parents | |
children | 185621f47040 |
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'