def test_set_settings(self):
     new_temp_store = 60;
     new_instruction_interval = 120;
     new_temp_check = 10;
     new_temp_margin = 0.25;
     request_body = '{ "store_temperature_interval_seconds" : ' + str(new_temp_store) + ',  "instruction_interval_seconds" : ' + str(new_instruction_interval) + ',  "monitor_temperature_interval_seconds" : ' + str(new_temp_check) + ', "temperature_tolerance_C":' + str(new_temp_margin) + '}'        
     response = self._call_POST_with_credentials_and_body('http://localhost:8080/chestfreezer/api/options', request_body, 'application/json')[0]
     assert(response.status == 204)  
     assert configuration.store_temperature_interval_seconds() == new_temp_store      
     assert configuration.instruction_interval_seconds() == new_instruction_interval
     assert configuration.control_temperature_interval_seconds() == new_temp_check
     assert configuration.temperature_tolerance() == new_temp_margin
Ejemplo n.º 2
0
def get_settings_as_json():
    """ returns the application options as a json object """
    store_temperature_interval_seconds = configuration.store_temperature_interval_seconds()     
    l1 = '  "store_temperature_interval_seconds" : ' + str(int(store_temperature_interval_seconds)) + ',';
    instruction_interval_seconds = configuration.instruction_interval_seconds()
    l2 = '  "instruction_interval_seconds" : ' + str(int(instruction_interval_seconds)) + ',';
    control_temperature_interval_seconds = configuration.control_temperature_interval_seconds()
    l3 = '  "monitor_temperature_interval_seconds" : ' + str(int(control_temperature_interval_seconds)) + ',';
    temperature_tolerance = configuration.temperature_tolerance()
    l4 = '  "temperature_tolerance_C" : ' + str(temperature_tolerance) + ',';        
    database_size = db_adapter.get_database_size()
    l5 = '  "database_size_MB" : ' + str(round(database_size,1)) + ',';
    database_free_size = db_adapter.get_database_free_size()
    l6 = '  "database_free_size_MB" : ' + str(round(database_free_size,1)) + '';
    return '{\n  ' + l1 + '\n  ' + l2 + '\n  ' + l3 + '\n  ' + l4 + '\n  ' + l5 + '\n  ' + l6 + '\n}'
Ejemplo n.º 3
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())