forked from FOSS/BangleApps
Merge pull request #1195 from myxor/weatherClock0.05
WeatherClock: Use weather condition code for icon selectionmaster
commit
7091e551df
|
@ -4780,7 +4780,7 @@
|
|||
{
|
||||
"id": "weatherClock",
|
||||
"name": "Weather Clock",
|
||||
"version": "0.04",
|
||||
"version": "0.05",
|
||||
"description": "A clock which displays current weather conditions (requires Gadgetbridge and Weather apps).",
|
||||
"icon": "app.png",
|
||||
"screenshots": [{"url":"screens/screen1.png"}],
|
||||
|
|
|
@ -2,3 +2,4 @@
|
|||
0.02: Minor layout format tweak so it uses less memory and draws ok on Bangle.js 1 (#1012)
|
||||
0.03: Minor layout extra spaces.
|
||||
0.04: Layout now compatible with Bangle.js 2
|
||||
0.05: Use weather condition code for icon selection
|
||||
|
|
|
@ -53,6 +53,29 @@ function chooseIcon(condition) {
|
|||
return cloudIcon;
|
||||
}
|
||||
|
||||
/*
|
||||
* Choose weather icon to display based on weather conditition code
|
||||
* https://openweathermap.org/weather-conditions#Weather-Condition-Codes-2
|
||||
*/
|
||||
function chooseIconByCode(code) {
|
||||
const codeGroup = Math.round(code / 100);
|
||||
switch (codeGroup) {
|
||||
case 2: return stormIcon;
|
||||
case 3: return rainIcon;
|
||||
case 5: return rainIcon;
|
||||
case 6: return snowIcon;
|
||||
case 7: return cloudIcon;
|
||||
case 8:
|
||||
switch (code) {
|
||||
case 800: return sunIcon;
|
||||
case 801: return partSunIcon;
|
||||
default: return cloudIcon;
|
||||
}
|
||||
break;
|
||||
default: return cloudIcon;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
Get weather stored in json file by weather app.
|
||||
*/
|
||||
|
@ -105,7 +128,12 @@ function draw() {
|
|||
var currentWeather = weatherJson.weather;
|
||||
const temp = locale.temp(currentWeather.temp-273.15).match(/^(\D*\d*)(.*)$/);
|
||||
clockLayout.temp.label = temp[1] + " " + temp[2];
|
||||
clockLayout.weatherIcon.src = chooseIcon(currentWeather.txt);
|
||||
const code = currentWeather.code || -1;
|
||||
if (code > 0) {
|
||||
clockLayout.weatherIcon.src = chooseIconByCode(code);
|
||||
} else {
|
||||
clockLayout.weatherIcon.src = chooseIcon(currentWeather.txt);
|
||||
}
|
||||
const wind = locale.speed(currentWeather.wind).match(/^(\D*\d*)(.*)$/);
|
||||
clockLayout.wind.label = wind[1] + " " + wind[2] + " " + (currentWeather.wrose||'').toUpperCase();
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue