From c70f25a15e26b12a354645a07b2c76413a63ea92 Mon Sep 17 00:00:00 2001 From: Martin Boonk Date: Tue, 22 Feb 2022 18:37:01 +0100 Subject: [PATCH] Fix reading weather data if not available --- apps/imageclock/app.js | 17 +++++++---------- 1 file changed, 7 insertions(+), 10 deletions(-) diff --git a/apps/imageclock/app.js b/apps/imageclock/app.js index 48e11fc41..0ed182d1e 100644 --- a/apps/imageclock/app.js +++ b/apps/imageclock/app.js @@ -237,22 +237,19 @@ function getWeatherTemperature(){ var jsonWeather = require("Storage").readJSON('weather.json'); var weather = (jsonWeather && jsonWeather.weather) ? jsonWeather.weather : undefined; + var result = { unit: "unknown"}; if (weather && weather.temp){ - //print("Weather temp is", weather.temp); + //print("Weather is", weather); var temp = require('locale').temp(weather.temp-273.15); - var value = Number(temp.match(/[\d\-]*/)[0]); + result.value = Number(temp.match(/[\d\-]*/)[0]); var unit; if (temp.includes("C")){ - unit = "celsius"; + result.unit = "celsius"; } else if (temp.includes("F")){ - unit = "fahrenheit"; - } else { - throw new Error("Unknown temperature unit " + unit); + result.unit = "fahrenheit"; } - - return {value: value, unit: unit}; } - return undefined; + return result; } function updateOffset(element, offset){ @@ -299,7 +296,7 @@ numbers.Altitude = () => { return alt; }; numbers.BatteryPercentage = E.getBattery; numbers.BatteryVoltage = NRF.getBattery; numbers.WeatherCode = getWeatherCode; -numbers.WeatherTemperature = () => getWeatherTemperature().value; +numbers.WeatherTemperature = () => { var t = getWeatherTemperature().value; return t ? t : undefined; }; var multistates = {}; multistates.Lock = () => { return Bangle.isLocked() ? "on" : "off"; };