def test_is_within_distance(self):
     assert(misc_utils.is_within_distance(10, 15, 6))
     assert(misc_utils.is_within_distance(1, 1.5, 0.6))
     assert(misc_utils.is_within_distance(10, 20, 10))
     assert(misc_utils.is_within_distance(100, -100, 200))
     assert(misc_utils.is_within_distance(10, 10.5, 0.5))
     
     assert(not misc_utils.is_within_distance(65, 72.3, 0.5))
     assert(not misc_utils.is_within_distance(1, 2, 0.5))
     assert(not misc_utils.is_within_distance(30, 60, 29))
     assert(not misc_utils.is_within_distance(0.5, -1, 0.1))
Beispiel #2
0
 def control_temperature():
     while True:                   
         try:
             actual_target_C = get_actual_target_temperature_C()                
             current_temperature_C = hardware.temperature_probes.get_current_temperature()
             if _is_device_overriden() | (current_temperature_C is None) | (actual_target_C is None): raise StopControlThread  # skip iteration
             # the great and (not so) efficient algorithm!
             if misc_utils.is_within_distance(current_temperature_C, actual_target_C, configuration.temperature_tolerance()):                     
                 _set_heater(False); _set_freezer(False)                
             elif current_temperature_C < actual_target_C:
                 _set_heater(True); _set_freezer(False)
             elif current_temperature_C > actual_target_C:
                 _set_heater(False); _set_freezer(True)
         except StopControlThread as e:
             # nothing, let loop re-iterate
             pass
         except Exception as e:
             print 'Error while setting temperature:\n' + str(e)            
         time.sleep(configuration.control_temperature_interval_seconds())