comparison py/sensor_test.py @ 528:61e61de49a50

test sensor
author Matt Johnston <matt@ucc.asn.au>
date Fri, 10 Apr 2015 23:55:07 +0800
parents
children 185621f47040
comparison
equal deleted inserted replaced
527:dd8895652485 528:61e61de49a50
1 import asyncio
2
3 class SensorTest(object):
4
5 def __init__(self, server):
6 self.server = server
7
8 def kill(self):
9 L("Killed SensorTest")
10
11 def make_vals(self):
12 def try_read(f, fallback):
13 try:
14 return open(f, 'r').read()
15 except Exception, e:
16 return fallback
17
18 vals = {}
19 vals[self.wort_name()] = try_read('test_wort.txt', 18)
20 vals[self.fridge_name()] = try_read('test_fridge.txt', 20)
21 vals['ambient'] = 31.2
22 return vals
23
24 def run(self):
25
26 while True:
27 yield from asyncio.sleep(1)
28 vals = self.make_vals()
29 self.server.add_reading(vals)
30
31 def wort_name(self):
32 return '28-wortname'
33
34 def fridge_name(self):
35 return '28-fridgename'