diff --git a/caimira/apps/calculator/__init__.py b/caimira/apps/calculator/__init__.py index 0c3505c2..fe1898eb 100644 --- a/caimira/apps/calculator/__init__.py +++ b/caimira/apps/calculator/__init__.py @@ -256,6 +256,10 @@ class ArveData(BaseRequestHandler): client_secret = self.settings['arve_client_secret'] arve_api_key = self.settings['arve_api_key'] + if (client_id == None or client_secret == None or arve_api_key == None): + # If the credentials are not defined, we skip the ARVE API connection + return self.send_error(401) + http_client = AsyncHTTPClient() URL = 'https://arveapi.auth.eu-central-1.amazoncognito.com/oauth2/token' @@ -345,9 +349,9 @@ def make_app( # COOKIE_SECRET being undefined will result in no login information being # presented to the user. cookie_secret=os.environ.get('COOKIE_SECRET', ''), - arve_client_id=os.environ.get('ARVE_CLIENT_ID', ''), - arve_client_secret=os.environ.get('ARVE_CLIENT_SECRET', ''), - arve_api_key=os.environ.get('ARVE_API_KEY', ''), + arve_client_id=os.environ.get('ARVE_CLIENT_ID', None), + arve_client_secret=os.environ.get('ARVE_CLIENT_SECRET', None), + arve_api_key=os.environ.get('ARVE_API_KEY', None), # Process parallelism controls. There is a balance between serving a single report # requests quickly or serving multiple requests concurrently. diff --git a/caimira/apps/calculator/static/js/form.js b/caimira/apps/calculator/static/js/form.js index 6c0525fa..45656c78 100644 --- a/caimira/apps/calculator/static/js/form.js +++ b/caimira/apps/calculator/static/js/form.js @@ -314,8 +314,15 @@ function show_sensors_data(url) { success: function (result) { DATA_FROM_SENSORS = result; result.map(room => { + if (room['Details']['Online'] == false) return; // If the sensor is offline, it should not be added to the list. $("#sensors").append(``); }); + if ($('#sensors > option').length == 0) { + $('#offline_sensors').show(); + $('#DIVsensors_data').hide(); + $('#arve_sensor_yes').prop('disabled', true) + return; // All sensors are offline + } populate_temp_hum_values(result, 0); if (url.searchParams.has('sensor_in_use')) { $("#sensors").val(url.searchParams.get('sensor_in_use')); @@ -324,9 +331,11 @@ function show_sensors_data(url) { })); } }, - error: function() { - alert('Authentication Error - Something went wrong during the authentication process.'); - }, + error: function(_, _, errorThrown) { + $("#arve_api_error_message").val(errorThrown).show(); + $('#DIVsensors_data').hide(); + $('#arve_sensor_yes').prop('disabled', true) + } }); } }; diff --git a/caimira/apps/templates/cern/calculator.form.html.j2 b/caimira/apps/templates/cern/calculator.form.html.j2 index ffc67bd2..4e5ae90a 100644 --- a/caimira/apps/templates/cern/calculator.form.html.j2 +++ b/caimira/apps/templates/cern/calculator.form.html.j2 @@ -14,7 +14,9 @@ -