528
|
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: |
531
|
14 return float(open(f, 'r').read()) |
529
|
15 except Exception as e: |
528
|
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 while True: |
|
26 yield from asyncio.sleep(1) |
|
27 vals = self.make_vals() |
|
28 self.server.add_reading(vals) |
|
29 |
|
30 def wort_name(self): |
|
31 return '28-wortname' |
|
32 |
|
33 def fridge_name(self): |
|
34 return '28-fridgename' |