mirror of https://github.com/espruino/BangleApps
Merge pull request #1205 from myxor/weatherApp_v0.14
Weather app v0.14: use weather condition code for icon selectionpull/1203/head^2
commit
6b829c7e71
|
@ -845,7 +845,7 @@
|
|||
{
|
||||
"id": "weather",
|
||||
"name": "Weather",
|
||||
"version": "0.13",
|
||||
"version": "0.14",
|
||||
"description": "Show Gadgetbridge weather report",
|
||||
"icon": "icon.png",
|
||||
"screenshots": [{"url":"screenshot.png"}],
|
||||
|
|
|
@ -10,3 +10,4 @@
|
|||
0.11: Bangle.js 2 support
|
||||
0.12: Allow hiding the widget
|
||||
0.13: Tweak Bangle.js 2 light theme colors
|
||||
0.14: Use weather condition code for icon selection
|
||||
|
|
|
@ -9,7 +9,7 @@ var layout = new Layout({type:"v", bgCol: g.theme.bg, c: [
|
|||
{filly: 1},
|
||||
{type: "h", filly: 0, c: [
|
||||
{type: "custom", width: g.getWidth()/2, height: g.getWidth()/2, valign: -1, txt: "unknown", id: "icon",
|
||||
render: l => weather.drawIcon(l.txt, l.x+l.w/2, l.y+l.h/2, l.w/2-5)},
|
||||
render: l => weather.drawIcon(l, l.x+l.w/2, l.y+l.h/2, l.w/2-5)},
|
||||
{type: "v", fillx: 1, c: [
|
||||
{type: "h", pad: 2, c: [
|
||||
{type: "txt", font: "18%", id: "temp", label: "000"},
|
||||
|
@ -47,6 +47,7 @@ function formatDuration(millis) {
|
|||
|
||||
function draw() {
|
||||
layout.icon.txt = current.txt;
|
||||
layout.icon.code = current.code;
|
||||
const temp = locale.temp(current.temp-273.15).match(/^(\D*\d*)(.*)$/);
|
||||
layout.temp.label = temp[1];
|
||||
layout.tempUnit.label = temp[2];
|
||||
|
|
|
@ -16,7 +16,7 @@ function scheduleExpiry(json) {
|
|||
|
||||
function update(weatherEvent) {
|
||||
let json = storage.readJSON('weather.json')||{};
|
||||
|
||||
|
||||
if (weatherEvent) {
|
||||
let weather = weatherEvent.clone();
|
||||
delete weather.t;
|
||||
|
@ -55,7 +55,7 @@ scheduleExpiry(storage.readJSON('weather.json')||{});
|
|||
|
||||
exports.drawIcon = function(cond, x, y, r) {
|
||||
var palette;
|
||||
|
||||
|
||||
if (B2) {
|
||||
if (g.theme.dark) {
|
||||
palette = {
|
||||
|
@ -101,7 +101,7 @@ exports.drawIcon = function(cond, x, y, r) {
|
|||
};
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
function drawSun(x, y, r) {
|
||||
g.setColor(palette.sun);
|
||||
g.fillCircle(x, y, r);
|
||||
|
@ -280,5 +280,44 @@ exports.drawIcon = function(cond, x, y, r) {
|
|||
return drawUnknown;
|
||||
}
|
||||
|
||||
chooseIcon(cond)(x, y, r);
|
||||
/*
|
||||
* 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 drawThunderstorm;
|
||||
case 3: return drawRain;
|
||||
case 5:
|
||||
switch (code) {
|
||||
case 511: return drawSnow;
|
||||
case 520: return drawShowerRain;
|
||||
case 521: return drawShowerRain;
|
||||
case 522: return drawShowerRain;
|
||||
case 531: return drawShowerRain;
|
||||
default: return drawRain;
|
||||
}
|
||||
break;
|
||||
case 6: return drawSnow;
|
||||
case 7: return drawMist;
|
||||
case 8:
|
||||
switch (code) {
|
||||
case 800: return drawSun;
|
||||
case 801: return drawFewClouds;
|
||||
case 802: return drawCloud;
|
||||
default: return drawBrokenClouds;
|
||||
}
|
||||
break;
|
||||
default: return drawUnknown;
|
||||
}
|
||||
}
|
||||
|
||||
if (cond.code && cond.code > 0) {
|
||||
chooseIconByCode(cond.code)(x, y, r);
|
||||
} else {
|
||||
chooseIcon(cond.txt)(x, y, r);
|
||||
}
|
||||
|
||||
|
||||
};
|
||||
|
|
Loading…
Reference in New Issue