diff --git a/apps/ffcniftyapp/ChangeLog b/apps/ffcniftyapp/ChangeLog index 30dcec467..ef797827e 100644 --- a/apps/ffcniftyapp/ChangeLog +++ b/apps/ffcniftyapp/ChangeLog @@ -1,3 +1,4 @@ 0.01: New Clock Nifty A ++ >> adding more information on the right side of the clock +0.02: Fix weather icon for languages other than English diff --git a/apps/ffcniftyapp/app.js b/apps/ffcniftyapp/app.js index 840dd72ff..5ca48c2f1 100644 --- a/apps/ffcniftyapp/app.js +++ b/apps/ffcniftyapp/app.js @@ -1,5 +1,5 @@ const w = require("weather"); -//const locale = require("locale"); +const locale = require("locale"); // Weather icons from https://icons8.com/icon/set/weather/color function getSun() { @@ -67,6 +67,33 @@ function chooseIcon(condition) { return getPartSun; } else return getErr; } + +/* +* 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 getStorm; + case 3: return getRain; + case 5: + switch (code) { + case 511: return getSnow; + default: return getRain; + } + case 6: return getSnow; + case 7: return getPartSun; + case 8: + switch (code) { + case 800: return getSun; + case 804: return getCloud; + default: return getPartSun; + } + default: return getCloud; + } +} + /*function condenseWeather(condition) { condition = condition.toLowerCase(); if (condition.includes("thunderstorm") || @@ -143,8 +170,17 @@ const clock = new ClockFace({ //let cWea =(curr === "no data" ? "no data" : curr.txt); let cTemp= (curr === "no data" ? 273 : curr.temp); // const temp = locale.temp(curr.temp - 273.15).match(/^(\D*\d*)(.*)$/); - let w_icon = chooseIcon(curr.txt === undefined ? "no data" : curr.txt ); - //let w_icon = chooseIcon(curr.txt); + + let w_icon = getErr; + if (locale.name === "en" || locale.name === "en_GB" || locale.name === "en_US") { + w_icon = chooseIcon(curr.txt === undefined ? "no data" : curr.txt); + } else { + // cannot use condition string to determine icon if language is not English; use weather code instead + const code = curr.code || -1; + if (code > 0) { + w_icon = chooseIconByCode(curr.code); + } + } g.setFontAlign(1, 0).setFont("Vector", 90 * this.scale); g.drawString(format(hour), this.centerTimeScaleX, this.center.y - 31 * this.scale); diff --git a/apps/ffcniftyapp/metadata.json b/apps/ffcniftyapp/metadata.json index bbe8e7e69..6f368160b 100644 --- a/apps/ffcniftyapp/metadata.json +++ b/apps/ffcniftyapp/metadata.json @@ -1,7 +1,7 @@ { "id": "ffcniftyapp", "name": "Nifty-A Clock ++", - "version": "0.01", + "version": "0.02", "description": "A nifty clock with time and date and more", "dependencies": {"weather":"app"}, "icon": "app.png",