From 1cdcedc997db4286270eaa5c3b7782b57310f073 Mon Sep 17 00:00:00 2001 From: David Peer Date: Tue, 11 Jan 2022 17:41:02 +0100 Subject: [PATCH] Bugfix: If the weather module does not exist, an exception was thrown. Now its hidden in a function. --- apps/lcars/lcars.app.js | 36 +++++++++++++++++++++--------------- 1 file changed, 21 insertions(+), 15 deletions(-) diff --git a/apps/lcars/lcars.app.js b/apps/lcars/lcars.app.js index 09998ccf5..39d01a687 100644 --- a/apps/lcars/lcars.app.js +++ b/apps/lcars/lcars.app.js @@ -1,10 +1,5 @@ const SETTINGS_FILE = "lcars.setting.json"; -const Storage = require("Storage"); -const weather = require('weather'); - - -// ...and overwrite them with any saved values -// This way saved values are preserved if a new version adds more settings +const locale = require('locale'); const storage = require('Storage') let settings = { alarm: -1, @@ -39,7 +34,7 @@ var disableInfoUpdate = true; // When gadgetbridge connects, step infos cannot b /* * Requirements and globals */ -const locale = require('locale'); + var bgLeft = { width : 27, height : 176, bpp : 3, @@ -124,7 +119,7 @@ function queueDraw() { function printData(key, y, c){ g.setFontAlign(-1,-1,0); var text = "ERR"; - var value = "NOT FOUND"; + var value = "ERR"; if(key == "Battery"){ text = "BAT"; @@ -136,7 +131,7 @@ function printData(key, y, c){ } else if(key == "Temp."){ text = "TEMP"; - value = Math.floor(E.getTemperature()) + "C"; + value = locale.temp(parseInt(E.getTemperature())); } else if(key == "HRM"){ text = "HRM"; @@ -148,12 +143,8 @@ function printData(key, y, c){ } else if (key == "Weather"){ text = "TEMP"; - const w = weather.get(); - if (!w) { - value = "ERR"; - } else { - value = require('locale').temp(w.temp-273.15); // applies conversion - } + var weather = getWeather(); + value = locale.temp(parseInt(weather.temp-273.15)); } g.setColor(c); @@ -429,6 +420,21 @@ function getSteps() { } +function getWeather(){ + let weather; + + try { + weather = require('weather'); + } catch(ex) { + return { + temp: 0.0 + }; + } + + return weather.get(); +} + + /* * Handle alarm */