Пример #1
0
import unittest
from dht22_controller.utils import *
from dht22_controller.config import Config
from dht22_controller.temperature import Temperature
from dht22_controller.humidity import Humidity
from tests.testbase import TestBase
from datetime import datetime, timedelta
import math


c = Config()
c.config['target_temp_f'] = 60
c.config['temp_pad'] = 1


set_now(lambda: datetime(2000, 1, 1, 0, 0, 0))


optimal_time_s = 15
def temp_by_s(seconds):
    # exponential
    return float(seconds)**2. / (float(optimal_time_s)**2 / 2.)
    # # sigmoid
    # return (1. / (1. + math.exp(optimal_time_s - seconds))) * 4.


def temp_gen(last, increase=False, amount=.01):
    n = last + (amount if increase else -amount)
    # increase the time by the same amount as the temp. this way it takes
    # 1 minute to increase .1 degree, making math easier
    _now = now()
import Adafruit_DHT
import RPi.GPIO as g
from dht22_controller.config import Config
from dht22_controller.temperature import Temperature, c_to_f
from dht22_controller.humidity import Humidity
from dht22_controller.utils import clip


import logging
log = logging.getLogger(__name__)


g.setmode(g.BCM)
SENSOR = Adafruit_DHT.DHT22

conf = Config()
conf.load()

temperature = Temperature(
    conf,
    queue_size=10,
    debug=False,
    cool_for_s=20.,
    heat_for_s=20.,
    has_cooler=True,
    has_heater=False,
    recently_minutes=5.)
humidity = Humidity(
    conf,
    queue_size=10,
    debug=False,