예제 #1
0
 def record_temperatures():        
     while True:        
         try:
             readings = get_temperature_readings()               
             if readings is not None:
                 database.db_adapter.store_temperatures(readings)           
         except Exception as e:
             print 'Could not log temperature. Error:\n' + str(e)
         time.sleep(configuration.store_temperature_interval_seconds())
 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
예제 #3
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}'