From c2aec5ae36b59c57e9d63e78f342cbe153c2fafd Mon Sep 17 00:00:00 2001 From: Olexandr Savchuk Date: Fri, 2 Dec 2016 17:17:58 +0100 Subject: [PATCH 1/6] implemented roundTemperature in weather modules --- modules/default/currentweather/README.md | 7 +++++++ modules/default/currentweather/currentweather.js | 7 ++++++- modules/default/weatherforecast/README.md | 7 +++++++ modules/default/weatherforecast/weatherforecast.js | 13 +++++++++++-- 4 files changed, 31 insertions(+), 3 deletions(-) diff --git a/modules/default/currentweather/README.md b/modules/default/currentweather/README.md index 2a6f7844..e0bb392f 100644 --- a/modules/default/currentweather/README.md +++ b/modules/default/currentweather/README.md @@ -63,6 +63,13 @@ The following properties can be configured:
Default value: config.units + + roundTemperature + Round temperature value to nearest integer.
+
Possible values: true (round to integer) or false (display exact value with decimal point) +
Default value: false + + updateInterval How often does the content needs to be fetched? (Milliseconds)
diff --git a/modules/default/currentweather/currentweather.js b/modules/default/currentweather/currentweather.js index 5265b099..ea548f80 100644 --- a/modules/default/currentweather/currentweather.js +++ b/modules/default/currentweather/currentweather.js @@ -15,6 +15,7 @@ Module.register("currentweather",{ locationID: "", appid: "", units: config.units, + roundTemperature: false, updateInterval: 10 * 60 * 1000, // every 10 minutes animationSpeed: 1000, timeFormat: config.timeFormat, @@ -149,9 +150,13 @@ Module.register("currentweather",{ weatherIcon.className = "wi weathericon " + this.weatherType; large.appendChild(weatherIcon); + var temp = this.temperature; + if (this.config.roundTemperature) { + temp = Math.round(temp); + } var temperature = document.createElement("span"); temperature.className = "bright"; - temperature.innerHTML = " " + this.temperature + "°"; + temperature.innerHTML = " " + temp + "°"; large.appendChild(temperature); wrapper.appendChild(small); diff --git a/modules/default/weatherforecast/README.md b/modules/default/weatherforecast/README.md index aba03a41..a2492f70 100644 --- a/modules/default/weatherforecast/README.md +++ b/modules/default/weatherforecast/README.md @@ -63,6 +63,13 @@ The following properties can be configured:
Default value: config.units + + roundTemperature + Round temperature values to nearest integer.
+
Possible values: true (round to integer) or false (display exact value with decimal point) +
Default value: false + + maxNumberOfDays How many days of forecast to return. Specified by config.js
diff --git a/modules/default/weatherforecast/weatherforecast.js b/modules/default/weatherforecast/weatherforecast.js index a8a8ca6c..006dd685 100644 --- a/modules/default/weatherforecast/weatherforecast.js +++ b/modules/default/weatherforecast/weatherforecast.js @@ -15,6 +15,7 @@ Module.register("weatherforecast",{ locationID: "", appid: "", units: config.units, + roundTemperature: false, maxNumberOfDays: 7, updateInterval: 10 * 60 * 1000, // every 10 minutes animationSpeed: 1000, @@ -129,13 +130,20 @@ Module.register("weatherforecast",{ icon.className = "wi weathericon " + forecast.icon; iconCell.appendChild(icon); + var maxTemp = forecast.maxTemp; + var minTemp = forecast.minTemp; + if (this.config.roundTemperature) { + maxTemp = Math.round(maxTemp); + minTemp = Math.round(minTemp); + } + var maxTempCell = document.createElement("td"); - maxTempCell.innerHTML = forecast.maxTemp; + maxTempCell.innerHTML = maxTemp; maxTempCell.className = "align-right bright max-temp"; row.appendChild(maxTempCell); var minTempCell = document.createElement("td"); - minTempCell.innerHTML = forecast.minTemp; + minTempCell.innerHTML = minTemp; minTempCell.className = "align-right min-temp"; row.appendChild(minTempCell); @@ -289,3 +297,4 @@ Module.register("weatherforecast",{ return parseFloat(temperature).toFixed(1); } }); + From 3c33969d23b388df670bd8d0cbfafacee1b56e04 Mon Sep 17 00:00:00 2001 From: Olexandr Savchuk Date: Fri, 2 Dec 2016 17:17:58 +0100 Subject: [PATCH 2/6] implemented roundTemperature in weather modules --- modules/default/currentweather/README.md | 7 +++++++ modules/default/currentweather/currentweather.js | 7 ++++++- modules/default/weatherforecast/README.md | 7 +++++++ modules/default/weatherforecast/weatherforecast.js | 13 +++++++++++-- 4 files changed, 31 insertions(+), 3 deletions(-) diff --git a/modules/default/currentweather/README.md b/modules/default/currentweather/README.md index 35c03404..d7116930 100644 --- a/modules/default/currentweather/README.md +++ b/modules/default/currentweather/README.md @@ -64,6 +64,13 @@ The following properties can be configured:
Default value: config.units + + roundTemperature + Round temperature value to nearest integer.
+
Possible values: true (round to integer) or false (display exact value with decimal point) +
Default value: false + + updateInterval How often does the content needs to be fetched? (Milliseconds)
diff --git a/modules/default/currentweather/currentweather.js b/modules/default/currentweather/currentweather.js index a379332d..43b57f4f 100644 --- a/modules/default/currentweather/currentweather.js +++ b/modules/default/currentweather/currentweather.js @@ -15,6 +15,7 @@ Module.register("currentweather",{ locationID: false, appid: "", units: config.units, + roundTemperature: false, updateInterval: 10 * 60 * 1000, // every 10 minutes animationSpeed: 1000, timeFormat: config.timeFormat, @@ -181,9 +182,13 @@ Module.register("currentweather",{ weatherIcon.className = "wi weathericon " + this.weatherType; large.appendChild(weatherIcon); + var temp = this.temperature; + if (this.config.roundTemperature) { + temp = Math.round(temp); + } var temperature = document.createElement("span"); temperature.className = "bright"; - temperature.innerHTML = " " + this.temperature + "°"; + temperature.innerHTML = " " + temp + "°"; large.appendChild(temperature); wrapper.appendChild(large); diff --git a/modules/default/weatherforecast/README.md b/modules/default/weatherforecast/README.md index 6b88d21e..8b80e982 100644 --- a/modules/default/weatherforecast/README.md +++ b/modules/default/weatherforecast/README.md @@ -64,6 +64,13 @@ The following properties can be configured:
Default value: config.units + + roundTemperature + Round temperature values to nearest integer.
+
Possible values: true (round to integer) or false (display exact value with decimal point) +
Default value: false + + maxNumberOfDays How many days of forecast to return. Specified by config.js
diff --git a/modules/default/weatherforecast/weatherforecast.js b/modules/default/weatherforecast/weatherforecast.js index 51c3f56e..014e00cd 100644 --- a/modules/default/weatherforecast/weatherforecast.js +++ b/modules/default/weatherforecast/weatherforecast.js @@ -15,6 +15,7 @@ Module.register("weatherforecast",{ locationID: false, appid: "", units: config.units, + roundTemperature: false, maxNumberOfDays: 7, showRainAmount: false, updateInterval: 10 * 60 * 1000, // every 10 minutes @@ -133,13 +134,20 @@ Module.register("weatherforecast",{ icon.className = "wi weathericon " + forecast.icon; iconCell.appendChild(icon); + var maxTemp = forecast.maxTemp; + var minTemp = forecast.minTemp; + if (this.config.roundTemperature) { + maxTemp = Math.round(maxTemp); + minTemp = Math.round(minTemp); + } + var maxTempCell = document.createElement("td"); - maxTempCell.innerHTML = forecast.maxTemp; + maxTempCell.innerHTML = maxTemp; maxTempCell.className = "align-right bright max-temp"; row.appendChild(maxTempCell); var minTempCell = document.createElement("td"); - minTempCell.innerHTML = forecast.minTemp; + minTempCell.innerHTML = minTemp; minTempCell.className = "align-right min-temp"; row.appendChild(minTempCell); @@ -352,3 +360,4 @@ Module.register("weatherforecast",{ return parseFloat(temperature).toFixed(1); } }); + From 32df3e80b135971ac15bc43228d66d84defc50e3 Mon Sep 17 00:00:00 2001 From: Olexandr Savchuk Date: Fri, 2 Dec 2016 17:33:41 +0100 Subject: [PATCH 3/6] Renamed roundTemperature option to roundTemp Added changelog entry --- CHANGELOG.md | 1 + modules/default/currentweather/README.md | 2 +- modules/default/currentweather/currentweather.js | 6 +++--- modules/default/weatherforecast/README.md | 2 +- modules/default/weatherforecast/weatherforecast.js | 5 +++-- 5 files changed, 9 insertions(+), 7 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index d3acbcc4..0acfecc9 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -29,6 +29,7 @@ This project adheres to [Semantic Versioning](http://semver.org/). - Added option `address` to set bind address. - Added option `onlyTemp` for currentweather module to show show only current temperature and weather icon. - Added option `remoteFile` to compliments module to load compliment array from filesystem. +- Added option `roundTemp` for currentweather and weatherforecast modules to display temperatures rounded to nearest integer. ### Updated - Modified translations for Frysk. diff --git a/modules/default/currentweather/README.md b/modules/default/currentweather/README.md index d7116930..335dc0de 100644 --- a/modules/default/currentweather/README.md +++ b/modules/default/currentweather/README.md @@ -65,7 +65,7 @@ The following properties can be configured: - roundTemperature + roundTemp Round temperature value to nearest integer.

Possible values: true (round to integer) or false (display exact value with decimal point)
Default value: false diff --git a/modules/default/currentweather/currentweather.js b/modules/default/currentweather/currentweather.js index 43b57f4f..2d5635af 100644 --- a/modules/default/currentweather/currentweather.js +++ b/modules/default/currentweather/currentweather.js @@ -15,7 +15,6 @@ Module.register("currentweather",{ locationID: false, appid: "", units: config.units, - roundTemperature: false, updateInterval: 10 * 60 * 1000, // every 10 minutes animationSpeed: 1000, timeFormat: config.timeFormat, @@ -37,7 +36,8 @@ Module.register("currentweather",{ calendarClass: "calendar", onlyTemp: false, - + roundTemp: false, + iconTable: { "01d": "wi-day-sunny", "02d": "wi-day-cloudy", @@ -183,7 +183,7 @@ Module.register("currentweather",{ large.appendChild(weatherIcon); var temp = this.temperature; - if (this.config.roundTemperature) { + if (this.config.roundTemp) { temp = Math.round(temp); } var temperature = document.createElement("span"); diff --git a/modules/default/weatherforecast/README.md b/modules/default/weatherforecast/README.md index 8b80e982..0cc3e46b 100644 --- a/modules/default/weatherforecast/README.md +++ b/modules/default/weatherforecast/README.md @@ -65,7 +65,7 @@ The following properties can be configured: - roundTemperature + roundTemp Round temperature values to nearest integer.

Possible values: true (round to integer) or false (display exact value with decimal point)
Default value: false diff --git a/modules/default/weatherforecast/weatherforecast.js b/modules/default/weatherforecast/weatherforecast.js index 014e00cd..6eba014a 100644 --- a/modules/default/weatherforecast/weatherforecast.js +++ b/modules/default/weatherforecast/weatherforecast.js @@ -15,7 +15,6 @@ Module.register("weatherforecast",{ locationID: false, appid: "", units: config.units, - roundTemperature: false, maxNumberOfDays: 7, showRainAmount: false, updateInterval: 10 * 60 * 1000, // every 10 minutes @@ -35,6 +34,8 @@ Module.register("weatherforecast",{ appendLocationNameToHeader: true, calendarClass: "calendar", + roundTemp: false, + iconTable: { "01d": "wi-day-sunny", "02d": "wi-day-cloudy", @@ -136,7 +137,7 @@ Module.register("weatherforecast",{ var maxTemp = forecast.maxTemp; var minTemp = forecast.minTemp; - if (this.config.roundTemperature) { + if (this.config.roundTemp) { maxTemp = Math.round(maxTemp); minTemp = Math.round(minTemp); } From d67e9468c0e070fbacbeccad24a3d3590bce5868 Mon Sep 17 00:00:00 2001 From: Olexandr Savchuk Date: Fri, 2 Dec 2016 20:52:36 +0100 Subject: [PATCH 4/6] Changed roundTemp implementation to a cleaner one --- modules/default/currentweather/currentweather.js | 9 +++------ .../default/weatherforecast/weatherforecast.js | 16 +++++----------- 2 files changed, 8 insertions(+), 17 deletions(-) diff --git a/modules/default/currentweather/currentweather.js b/modules/default/currentweather/currentweather.js index 2d5635af..7cdcf51c 100644 --- a/modules/default/currentweather/currentweather.js +++ b/modules/default/currentweather/currentweather.js @@ -182,13 +182,9 @@ Module.register("currentweather",{ weatherIcon.className = "wi weathericon " + this.weatherType; large.appendChild(weatherIcon); - var temp = this.temperature; - if (this.config.roundTemp) { - temp = Math.round(temp); - } var temperature = document.createElement("span"); temperature.className = "bright"; - temperature.innerHTML = " " + temp + "°"; + temperature.innerHTML = " " + this.temperature + "°"; large.appendChild(temperature); wrapper.appendChild(large); @@ -436,6 +432,7 @@ Module.register("currentweather",{ roundValue: function(temperature) { - return parseFloat(temperature).toFixed(1); + var decimals = this.config.roundTemp ? 0 : 1; + return parseFloat(temperature).toFixed(decimals); } }); diff --git a/modules/default/weatherforecast/weatherforecast.js b/modules/default/weatherforecast/weatherforecast.js index 6eba014a..5078c9b6 100644 --- a/modules/default/weatherforecast/weatherforecast.js +++ b/modules/default/weatherforecast/weatherforecast.js @@ -135,20 +135,13 @@ Module.register("weatherforecast",{ icon.className = "wi weathericon " + forecast.icon; iconCell.appendChild(icon); - var maxTemp = forecast.maxTemp; - var minTemp = forecast.minTemp; - if (this.config.roundTemp) { - maxTemp = Math.round(maxTemp); - minTemp = Math.round(minTemp); - } - var maxTempCell = document.createElement("td"); - maxTempCell.innerHTML = maxTemp; + maxTempCell.innerHTML = forecast.maxTemp; maxTempCell.className = "align-right bright max-temp"; row.appendChild(maxTempCell); var minTempCell = document.createElement("td"); - minTempCell.innerHTML = minTemp; + minTempCell.innerHTML = forecast.minTemp; minTempCell.className = "align-right min-temp"; row.appendChild(minTempCell); @@ -351,14 +344,15 @@ Module.register("weatherforecast",{ }, /* function(temperature) - * Rounds a temperature to 1 decimal. + * Rounds a temperature to 1 decimal or integer (depending on config.roundTemp). * * argument temperature number - Temperature. * * return number - Rounded Temperature. */ roundValue: function(temperature) { - return parseFloat(temperature).toFixed(1); + var decimals = this.config.roundTemp ? 0 : 1; + return parseFloat(temperature).toFixed(decimals); } }); From 4d8d30f89731a2530c4f8e10c3a43f7d942e30ad Mon Sep 17 00:00:00 2001 From: Olexandr Savchuk Date: Fri, 2 Dec 2016 20:53:02 +0100 Subject: [PATCH 5/6] Moved misplaced method signature --- modules/default/currentweather/currentweather.js | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) diff --git a/modules/default/currentweather/currentweather.js b/modules/default/currentweather/currentweather.js index 7cdcf51c..46cb7dd6 100644 --- a/modules/default/currentweather/currentweather.js +++ b/modules/default/currentweather/currentweather.js @@ -386,14 +386,6 @@ Module.register("currentweather",{ return 12; }, - /* function(temperature) - * Rounds a temperature to 1 decimal. - * - * argument temperature number - Temperature. - * - * return number - Rounded Temperature. - */ - deg2Cardinal: function(deg) { if (deg>11.25 && deg<=33.75){ return "NNE"; @@ -430,7 +422,13 @@ Module.register("currentweather",{ } }, - + /* function(temperature) + * Rounds a temperature to 1 decimal. + * + * argument temperature number - Temperature. + * + * return number - Rounded Temperature. + */ roundValue: function(temperature) { var decimals = this.config.roundTemp ? 0 : 1; return parseFloat(temperature).toFixed(decimals); From 89bc3137ba8ab44702cf0333acb19f3e1a20358a Mon Sep 17 00:00:00 2001 From: Olexandr Savchuk Date: Fri, 2 Dec 2016 20:56:10 +0100 Subject: [PATCH 6/6] Fixed method description. --- modules/default/currentweather/currentweather.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/default/currentweather/currentweather.js b/modules/default/currentweather/currentweather.js index 46cb7dd6..ab48b911 100644 --- a/modules/default/currentweather/currentweather.js +++ b/modules/default/currentweather/currentweather.js @@ -423,7 +423,7 @@ Module.register("currentweather",{ }, /* function(temperature) - * Rounds a temperature to 1 decimal. + * Rounds a temperature to 1 decimal or integer (depending on config.roundTemp). * * argument temperature number - Temperature. *