view py/sensor_test.py @ 637:1e147b3c2c55 rust

update deps
author Matt Johnston <matt@ucc.asn.au>
date Sat, 09 Nov 2019 11:35:43 +0800
parents a01b7bccccd3
children
line wrap: on
line source

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 float(open(f, 'r').read())
            except Exception as 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'