Better stability for weather

master
David Peer 2022-04-20 17:09:33 +02:00
parent a02e6d79c4
commit 058beeae94
1 changed files with 23 additions and 26 deletions

View File

@ -579,38 +579,35 @@ function getWeather(){
try { try {
weatherJson = storage.readJSON('weather.json'); weatherJson = storage.readJSON('weather.json');
var weather = weatherJson.weather;
// Temperature
weather.temp = locale.temp(weather.temp-273.15);
// Humidity
weather.hum = weather.hum + "%";
// Wind
const wind = locale.speed(weather.wind).match(/^(\D*\d*)(.*)$/);
var speedFactor = settings.speed == "kph" ? 1.0 : 1.0 / 1.60934;
weather.wind = Math.round(wind[1] * speedFactor);
return weather
} catch(ex) { } catch(ex) {
// Return default // Return default
} }
if(weatherJson === undefined){ return {
return { temp: " ? ",
temp: "-", hum: " ? ",
hum: "-", txt: " ? ",
txt: "-", wind: " ? ",
wind: "-", wdir: " ? ",
wdir: "-", wrose: " ? "
wrose: "-" };
};
}
var weather = weatherJson.weather;
// Temperature
weather.temp = locale.temp(weather.temp-273.15);
// Humidity
weather.hum = weather.hum + "%";
// Wind
const wind = locale.speed(weather.wind).match(/^(\D*\d*)(.*)$/);
var speedFactor = settings.speed == "kph" ? 1.0 : 1.0 / 1.60934;
weather.wind = Math.round(wind[1] * speedFactor);
return weather
} }
/* /*
* Handle alarm * Handle alarm
*/ */