def test_is_decreasing_should_not_be_cooling(self): t = Temperature(c, debug=True, has_heater=True, has_cooler=True) last_temp = 60. t.add(last_temp) t.update() while True: last_temp = temp_gen(last_temp, False) t.add(last_temp) t.update() if t.temperature_average_f() <= c.min_temp_f: self.assertTrue(t.heating_on) self.assertFalse(t.cooling_on) break else: self.assertFalse(t.cooling_on)
def test_is_decreasing_should_be_heating(self): t = Temperature(c, debug=True, has_heater=True, has_cooler=True) last_temp = 60. t.add(last_temp) t.update() increasing = False while True: last_temp = temp_gen(last_temp, increasing) t.add(last_temp) t.update() if not increasing and t.temperature_average_f() > c.min_temp_f: self.assertFalse(t.heating_on) increasing = False elif not increasing and t.temperature_average_f() <= c.min_temp_f: self.assertTrue(t.heating_on) increasing = True elif increasing and (now() - t.heater_enabled_at) >= timedelta(seconds=t.heat_for_s): self.assertFalse(t.heating_on) break
def test_learns_heat_for_time(self): t = Temperature(c, debug=True, has_heater=True) last_temp = 60. t.add(last_temp) t.update() increasing = False i = e = 0 works = False while i < 10000: i += 1 last_temp = temp_gen(last_temp, increasing) t.add(last_temp) t.update() if t.heating_on: e += 1 maximum = t.temperature_average_f() + temp_by_s(t.heat_for_s) last_temp = maximum if abs(maximum - c.max_temp_f) < .05: works = True break [t.add(maximum + j*.01) for j in range(t.queue.cap)] t.heating_on = False t.waiting_for_temp_decrease = True self.assertTrue(works, msg="Failed to learn the correct temperature.") print('NOTE: heating steady after {} learned updates'.format(e))
def test_temp_avg(self): t = Temperature(c, debug=True) for i in range(1, 11, 1): t.add(i) self.assertEqual(5.5, t.temperature_average_f())
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, has_humidifier=False, has_dehumidifier=True, recently_minutes=5.) # Reversed since that's what's working for me (must have reversed polarity # on current socket?)