From 0d6f736c2c1d3519bef143f9f4a30ceabd6eb8b5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Aur=C3=A9lien=20Veillard?= Date: Sun, 8 Nov 2020 12:37:21 +0100 Subject: [PATCH 1/6] Fix windspeed convertion error in ukmetoffice weather provider Fix windspeed convertion error from mph to m/s in ukmetoffice weather provider (#2189) --- CHANGELOG.md | 1 + modules/default/weather/providers/ukmetoffice.js | 4 ++-- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 0d46712e..3be7e13d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -28,6 +28,7 @@ _This release is scheduled to be released on 2021-01-01._ - Rename Greek translation to correct ISO 639-1 alpha-2 code (gr > el). (#2155) - Add a space after icons of sunrise and sunset (#2169) - Fix calendar when no DTEND record found in event, startDate overlay when endDate set (#2177) +- Fix windspeed convertion error in ukmetoffice weather provider (#2189) ## [2.13.0] - 2020-10-01 diff --git a/modules/default/weather/providers/ukmetoffice.js b/modules/default/weather/providers/ukmetoffice.js index f1a50074..a8c40d4f 100755 --- a/modules/default/weather/providers/ukmetoffice.js +++ b/modules/default/weather/providers/ukmetoffice.js @@ -208,10 +208,10 @@ WeatherProvider.register("ukmetoffice", { }, /* - * Convert wind speed (from mph) if required + * Convert wind speed (from mph to m/s) if required */ convertWindSpeed(windInMph) { - return this.windUnits === "metric" ? windInMph * 2.23694 : windInMph; + return this.windUnits === "metric" ? windInMph / 2.23694 : windInMph; }, /* From 1460f002ab79c0aa209e56a44a41b91291d26d8e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Aur=C3=A9lien=20Veillard?= Date: Sun, 8 Nov 2020 14:01:02 +0100 Subject: [PATCH 2/6] Add new parameter "useKmh" to weather module Add new parameter "useKmh" to weather module for displaying wind speed as km/h instead of m/s when windUnits is set to metric. --- CHANGELOG.md | 1 + modules/default/weather/providers/darksky.js | 4 +-- .../weather/providers/openweathermap.js | 26 +++++++++++-------- .../default/weather/providers/ukmetoffice.js | 8 +++--- .../weather/providers/ukmetofficedatahub.js | 6 ++--- .../default/weather/providers/weathergov.js | 18 ++++++++----- modules/default/weather/weather.js | 1 + modules/default/weather/weatherobject.js | 5 ++-- 8 files changed, 40 insertions(+), 29 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 3be7e13d..a2aaa28e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -12,6 +12,7 @@ _This release is scheduled to be released on 2021-01-01._ ### Added - Added new log level "debug" to the logger. +- Added new parameter "useKmh" to weather module for displaying wind speed as kmh. ### Updated diff --git a/modules/default/weather/providers/darksky.js b/modules/default/weather/providers/darksky.js index 4ba90105..b2bf4e78 100755 --- a/modules/default/weather/providers/darksky.js +++ b/modules/default/weather/providers/darksky.js @@ -62,7 +62,7 @@ WeatherProvider.register("darksky", { // Implement WeatherDay generator. generateWeatherDayFromCurrentWeather(currentWeatherData) { - const currentWeather = new WeatherObject(this.config.units, this.config.tempUnits, this.config.windUnits); + const currentWeather = new WeatherObject(this.config.units, this.config.tempUnits, this.config.windUnits, this.config.useKmh); currentWeather.date = moment(); currentWeather.humidity = parseFloat(currentWeatherData.currently.humidity); @@ -80,7 +80,7 @@ WeatherProvider.register("darksky", { const days = []; for (const forecast of forecasts) { - const weather = new WeatherObject(this.config.units, this.config.tempUnits, this.config.windUnits); + const weather = new WeatherObject(this.config.units, this.config.tempUnits, this.config.windUnits, this.config.useKmh); weather.date = moment(forecast.time, "X"); weather.minTemperature = forecast.temperatureMin; diff --git a/modules/default/weather/providers/openweathermap.js b/modules/default/weather/providers/openweathermap.js index 12635f1b..0e0f7095 100755 --- a/modules/default/weather/providers/openweathermap.js +++ b/modules/default/weather/providers/openweathermap.js @@ -89,11 +89,15 @@ WeatherProvider.register("openweathermap", { * Generate a WeatherObject based on currentWeatherInformation */ generateWeatherObjectFromCurrentWeather(currentWeatherData) { - const currentWeather = new WeatherObject(this.config.units, this.config.tempUnits, this.config.windUnits); + const currentWeather = new WeatherObject(this.config.units, this.config.tempUnits, this.config.windUnits, this.config.useKmh); currentWeather.humidity = currentWeatherData.main.humidity; currentWeather.temperature = currentWeatherData.main.temp; - currentWeather.windSpeed = currentWeatherData.wind.speed; + if(this.config.windUnits === "metric") { + currentWeather.windSpeed = this.config.useKmh ? currentWeatherData.wind.speed * 3.6 : currentWeatherData.wind.speed; + } else { + currentWeather.windSpeed = currentWeatherData.wind.speed; + } currentWeather.windDirection = currentWeatherData.wind.deg; currentWeather.weatherType = this.convertWeatherType(currentWeatherData.weather[0].icon); currentWeather.sunrise = moment(currentWeatherData.sys.sunrise, "X"); @@ -112,7 +116,7 @@ WeatherProvider.register("openweathermap", { return this.fetchForecastDaily(forecasts); } // if weatherEndpoint does not match forecast or forecast/daily, what should be returned? - const days = [new WeatherObject(this.config.units, this.config.tempUnits, this.config.windUnits)]; + const days = [new WeatherObject(this.config.units, this.config.tempUnits, this.config.windUnits, this.config.useKmh)]; return days; }, @@ -124,7 +128,7 @@ WeatherProvider.register("openweathermap", { return this.fetchOnecall(data); } // if weatherEndpoint does not match onecall, what should be returned? - const weatherData = { current: new WeatherObject(this.config.units, this.config.tempUnits, this.config.windUnits), hours: [], days: [] }; + const weatherData = { current: new WeatherObject(this.config.units, this.config.tempUnits, this.config.windUnits, this.config.useKmh), hours: [], days: [] }; return weatherData; }, @@ -141,7 +145,7 @@ WeatherProvider.register("openweathermap", { let snow = 0; // variable for date let date = ""; - let weather = new WeatherObject(this.config.units, this.config.tempUnits, this.config.windUnits); + let weather = new WeatherObject(this.config.units, this.config.tempUnits, this.config.windUnits, this.config.useKmh); for (const forecast of forecasts) { if (date !== moment(forecast.dt, "X").format("YYYY-MM-DD")) { @@ -154,7 +158,7 @@ WeatherProvider.register("openweathermap", { // push weather information to days array days.push(weather); // create new weather-object - weather = new WeatherObject(this.config.units, this.config.tempUnits, this.config.windUnits); + weather = new WeatherObject(this.config.units, this.config.tempUnits, this.config.windUnits, this.config.useKmh); minTemp = []; maxTemp = []; @@ -217,7 +221,7 @@ WeatherProvider.register("openweathermap", { const days = []; for (const forecast of forecasts) { - const weather = new WeatherObject(this.config.units, this.config.tempUnits, this.config.windUnits); + const weather = new WeatherObject(this.config.units, this.config.tempUnits, this.config.windUnits, this.config.useKmh); weather.date = moment(forecast.dt, "X"); weather.minTemperature = forecast.temp.min; @@ -263,7 +267,7 @@ WeatherProvider.register("openweathermap", { let precip = false; // get current weather, if requested - const current = new WeatherObject(this.config.units, this.config.tempUnits, this.config.windUnits); + const current = new WeatherObject(this.config.units, this.config.tempUnits, this.config.windUnits, this.config.useKmh); if (data.hasOwnProperty("current")) { current.date = moment(data.current.dt, "X").utcOffset(data.timezone_offset / 60); current.windSpeed = data.current.wind_speed; @@ -295,7 +299,7 @@ WeatherProvider.register("openweathermap", { current.feelsLikeTemp = data.current.feels_like; } - let weather = new WeatherObject(this.config.units, this.config.tempUnits, this.config.windUnits); + let weather = new WeatherObject(this.config.units, this.config.tempUnits, this.config.windUnits, this.config.useKmh); // get hourly weather, if requested const hours = []; @@ -331,7 +335,7 @@ WeatherProvider.register("openweathermap", { } hours.push(weather); - weather = new WeatherObject(this.config.units, this.config.tempUnits, this.config.windUnits); + weather = new WeatherObject(this.config.units, this.config.tempUnits, this.config.windUnits, this.config.useKmh); } } @@ -370,7 +374,7 @@ WeatherProvider.register("openweathermap", { } days.push(weather); - weather = new WeatherObject(this.config.units, this.config.tempUnits, this.config.windUnits); + weather = new WeatherObject(this.config.units, this.config.tempUnits, this.config.windUnits, this.config.useKmh); } } diff --git a/modules/default/weather/providers/ukmetoffice.js b/modules/default/weather/providers/ukmetoffice.js index a8c40d4f..b71ced88 100755 --- a/modules/default/weather/providers/ukmetoffice.js +++ b/modules/default/weather/providers/ukmetoffice.js @@ -73,7 +73,7 @@ WeatherProvider.register("ukmetoffice", { * Generate a WeatherObject based on currentWeatherInformation */ generateWeatherObjectFromCurrentWeather(currentWeatherData) { - const currentWeather = new WeatherObject(this.config.units, this.config.tempUnits, this.config.windUnits); + const currentWeather = new WeatherObject(this.config.units, this.config.tempUnits, this.config.windUnits, this.config.useKmh); // data times are always UTC let nowUtc = moment.utc(); @@ -124,7 +124,7 @@ WeatherProvider.register("ukmetoffice", { // loop round the (5) periods getting the data // for each period array, Day is [0], Night is [1] for (var j in forecasts.SiteRep.DV.Location.Period) { - const weather = new WeatherObject(this.config.units, this.config.tempUnits, this.config.windUnits); + const weather = new WeatherObject(this.config.units, this.config.tempUnits, this.config.windUnits, this.config.useKmh); // data times are always UTC const dateStr = forecasts.SiteRep.DV.Location.Period[j].value; @@ -208,10 +208,10 @@ WeatherProvider.register("ukmetoffice", { }, /* - * Convert wind speed (from mph to m/s) if required + * Convert wind speed (from mph to m/s or km/h) if required */ convertWindSpeed(windInMph) { - return this.windUnits === "metric" ? windInMph / 2.23694 : windInMph; + return this.windUnits === "metric" ? (this.useKmh ? windInMph * 1.60934 : windInMph / 2.23694) : windInMph; }, /* diff --git a/modules/default/weather/providers/ukmetofficedatahub.js b/modules/default/weather/providers/ukmetofficedatahub.js index 505732d3..64e3997c 100644 --- a/modules/default/weather/providers/ukmetofficedatahub.js +++ b/modules/default/weather/providers/ukmetofficedatahub.js @@ -108,7 +108,7 @@ WeatherProvider.register("ukmetofficedatahub", { // Create a WeatherObject using current weather data (data for the current hour) generateWeatherObjectFromCurrentWeather(currentWeatherData) { - const currentWeather = new WeatherObject(this.config.units, this.config.tempUnits, this.config.windUnits); + const currentWeather = new WeatherObject(this.config.units, this.config.tempUnits, this.config.windUnits, this.config.useKmh); // Extract the actual forecasts let forecastDataHours = currentWeatherData.features[0].properties.timeSeries; @@ -189,7 +189,7 @@ WeatherProvider.register("ukmetofficedatahub", { // Go through each day in the forecasts for (day in forecastDataDays) { - const forecastWeather = new WeatherObject(this.config.units, this.config.tempUnits, this.config.windUnits); + const forecastWeather = new WeatherObject(this.config.units, this.config.tempUnits, this.config.windUnits, this.config.useKmh); // Get date of forecast let forecastDate = moment.utc(forecastDataDays[day].time); @@ -254,7 +254,7 @@ WeatherProvider.register("ukmetofficedatahub", { return windInMpS; } - if (this.config.windUnits == "kph" || this.config.windUnits == "metric") { + if (this.config.windUnits == "kph" || this.config.windUnits == "metric" || this.config.useKmh ) { return windInMpS * 3.6; } diff --git a/modules/default/weather/providers/weathergov.js b/modules/default/weather/providers/weathergov.js index 1b28bba1..9a93a13c 100755 --- a/modules/default/weather/providers/weathergov.js +++ b/modules/default/weather/providers/weathergov.js @@ -131,11 +131,11 @@ WeatherProvider.register("weathergov", { * ... object needs data in units based on config! */ generateWeatherObjectFromCurrentWeather(currentWeatherData) { - const currentWeather = new WeatherObject(this.config.units, this.config.tempUnits, this.config.windUnits); + const currentWeather = new WeatherObject(this.config.units, this.config.tempUnits, this.config.windUnits, this.config.useKmh); currentWeather.date = moment(currentWeatherData.timestamp); currentWeather.temperature = this.convertTemp(currentWeatherData.temperature.value); - currentWeather.windSpeed = this.covertSpeed(currentWeatherData.windSpeed.value); + currentWeather.windSpeed = this.convertSpeed(currentWeatherData.windSpeed.value); currentWeather.windDirection = currentWeatherData.windDirection.value; currentWeather.minTemperature = this.convertTemp(currentWeatherData.minTemperatureLast24Hours.value); currentWeather.maxTemperature = this.convertTemp(currentWeatherData.maxTemperatureLast24Hours.value); @@ -179,7 +179,7 @@ WeatherProvider.register("weathergov", { let maxTemp = []; // variable for date let date = ""; - let weather = new WeatherObject(this.config.units, this.config.tempUnits, this.config.windUnits); + let weather = new WeatherObject(this.config.units, this.config.tempUnits, this.config.windUnits, this.config.useKmh); weather.precipitation = 0; for (const forecast of forecasts) { @@ -191,7 +191,7 @@ WeatherProvider.register("weathergov", { // push weather information to days array days.push(weather); // create new weather-object - weather = new WeatherObject(this.config.units, this.config.tempUnits, this.config.windUnits); + weather = new WeatherObject(this.config.units, this.config.tempUnits, this.config.windUnits, this.config.useKmh); minTemp = []; maxTemp = []; @@ -238,12 +238,16 @@ WeatherProvider.register("weathergov", { return temp; } }, - // conversion to mph - covertSpeed(metSec) { + // conversion to mph or kmh + convertSpeed(metSec) { if (this.config.windUnits === "imperial") { return metSec * 2.23694; } else { - return metSec; + if(this.config.useKmh) { + return metSec * 3.6; + } else { + return metSec; + } } }, // conversion to inches diff --git a/modules/default/weather/weather.js b/modules/default/weather/weather.js index b5a68a52..4b882a4f 100644 --- a/modules/default/weather/weather.js +++ b/modules/default/weather/weather.js @@ -30,6 +30,7 @@ Module.register("weather", { showWindDirection: true, showWindDirectionAsArrow: false, useBeaufort: true, + useKmh: false, lang: config.language, showHumidity: false, showSun: true, diff --git a/modules/default/weather/weatherobject.js b/modules/default/weather/weatherobject.js index 0ee42123..82d77b46 100755 --- a/modules/default/weather/weatherobject.js +++ b/modules/default/weather/weatherobject.js @@ -10,10 +10,11 @@ * As soon as we start implementing the forecast, mode properties will be added. */ class WeatherObject { - constructor(units, tempUnits, windUnits) { + constructor(units, tempUnits, windUnits, useKmh) { this.units = units; this.tempUnits = tempUnits; this.windUnits = windUnits; + this.useKmh = useKmh; this.date = null; this.windSpeed = null; this.windDirection = null; @@ -67,7 +68,7 @@ class WeatherObject { } beaufortWindSpeed() { - const windInKmh = this.windUnits === "imperial" ? this.windSpeed * 1.609344 : (this.windSpeed * 60 * 60) / 1000; + const windInKmh = this.windUnits === "imperial" ? this.windSpeed * 1.609344 : (this.useKmh ? this.windSpeed : (this.windSpeed * 60 * 60) / 1000); const speeds = [1, 5, 11, 19, 28, 38, 49, 61, 74, 88, 102, 117, 1000]; for (const [index, speed] of speeds.entries()) { if (speed > windInKmh) { From ce46fb5384d7ae9986a36248a11b01c95c920277 Mon Sep 17 00:00:00 2001 From: Michael Teeuw Date: Tue, 8 Dec 2020 15:43:41 +0100 Subject: [PATCH 3/6] Fix Prettier Issue --- modules/default/weather/weatherobject.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/default/weather/weatherobject.js b/modules/default/weather/weatherobject.js index 82d77b46..d8202fe7 100755 --- a/modules/default/weather/weatherobject.js +++ b/modules/default/weather/weatherobject.js @@ -68,7 +68,7 @@ class WeatherObject { } beaufortWindSpeed() { - const windInKmh = this.windUnits === "imperial" ? this.windSpeed * 1.609344 : (this.useKmh ? this.windSpeed : (this.windSpeed * 60 * 60) / 1000); + const windInKmh = this.windUnits === "imperial" ? this.windSpeed * 1.609344 : this.useKmh ? this.windSpeed : (this.windSpeed * 60 * 60) / 1000; const speeds = [1, 5, 11, 19, 28, 38, 49, 61, 74, 88, 102, 117, 1000]; for (const [index, speed] of speeds.entries()) { if (speed > windInKmh) { From be0c8f4f166ecdd4580ffb3d8d99c8c936e88d9f Mon Sep 17 00:00:00 2001 From: Michael Teeuw Date: Tue, 8 Dec 2020 16:01:19 +0100 Subject: [PATCH 4/6] Prettier fix. --- modules/default/weather/weather.js | 8 -------- 1 file changed, 8 deletions(-) diff --git a/modules/default/weather/weather.js b/modules/default/weather/weather.js index 33fc21fd..73ee0e16 100644 --- a/modules/default/weather/weather.js +++ b/modules/default/weather/weather.js @@ -12,17 +12,14 @@ Module.register("weather", { weatherProvider: "openweathermap", roundTemp: false, type: "current", // current, forecast, daily (equivalent to forecast), hourly (only with OpenWeatherMap /onecall endpoint) - lat: 0, lon: 0, location: false, locationID: false, units: config.units, useKmh: false, - tempUnits: config.units, windUnits: config.units, - updateInterval: 10 * 60 * 1000, // every 10 minutes animationSpeed: 1000, timeFormat: config.timeFormat, @@ -31,7 +28,6 @@ Module.register("weather", { showWindDirection: true, showWindDirectionAsArrow: false, useBeaufort: true, - useKmh: false, lang: config.language, showHumidity: false, showSun: true, @@ -43,20 +39,16 @@ Module.register("weather", { maxEntries: 5, fade: true, fadePoint: 0.25, // Start on 1/4th of the list. - initialLoadDelay: 0, // 0 seconds delay retryDelay: 2500, - apiKey: "", apiSecret: "", apiVersion: "2.5", apiBase: "https://api.openweathermap.org/data/", // TODO: this should not be part of the weather.js file, but should be contained in the openweatherprovider weatherEndpoint: "/weather", - appendLocationNameToHeader: true, calendarClass: "calendar", tableClass: "small", - onlyTemp: false, showPrecipitationAmount: false, colored: false, From f97be2f8f3a2b062d7df2b8779a4eba5421b120b Mon Sep 17 00:00:00 2001 From: Michael Teeuw Date: Tue, 8 Dec 2020 16:07:11 +0100 Subject: [PATCH 5/6] Fix prettier issue. --- modules/default/weather/providers/weathergov.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/default/weather/providers/weathergov.js b/modules/default/weather/providers/weathergov.js index 9a93a13c..86837763 100755 --- a/modules/default/weather/providers/weathergov.js +++ b/modules/default/weather/providers/weathergov.js @@ -243,7 +243,7 @@ WeatherProvider.register("weathergov", { if (this.config.windUnits === "imperial") { return metSec * 2.23694; } else { - if(this.config.useKmh) { + if (this.config.useKmh) { return metSec * 3.6; } else { return metSec; From e950cdaf32341609e347f51151c40ea187f2d97d Mon Sep 17 00:00:00 2001 From: Michael Teeuw Date: Tue, 8 Dec 2020 16:20:48 +0100 Subject: [PATCH 6/6] Prettier fixes. --- modules/default/weather/providers/openweathermap.js | 2 +- modules/default/weather/providers/ukmetofficedatahub.js | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/modules/default/weather/providers/openweathermap.js b/modules/default/weather/providers/openweathermap.js index 0e0f7095..2fde7139 100755 --- a/modules/default/weather/providers/openweathermap.js +++ b/modules/default/weather/providers/openweathermap.js @@ -93,7 +93,7 @@ WeatherProvider.register("openweathermap", { currentWeather.humidity = currentWeatherData.main.humidity; currentWeather.temperature = currentWeatherData.main.temp; - if(this.config.windUnits === "metric") { + if (this.config.windUnits === "metric") { currentWeather.windSpeed = this.config.useKmh ? currentWeatherData.wind.speed * 3.6 : currentWeatherData.wind.speed; } else { currentWeather.windSpeed = currentWeatherData.wind.speed; diff --git a/modules/default/weather/providers/ukmetofficedatahub.js b/modules/default/weather/providers/ukmetofficedatahub.js index 64e3997c..af2e09c6 100644 --- a/modules/default/weather/providers/ukmetofficedatahub.js +++ b/modules/default/weather/providers/ukmetofficedatahub.js @@ -254,7 +254,7 @@ WeatherProvider.register("ukmetofficedatahub", { return windInMpS; } - if (this.config.windUnits == "kph" || this.config.windUnits == "metric" || this.config.useKmh ) { + if (this.config.windUnits == "kph" || this.config.windUnits == "metric" || this.config.useKmh) { return windInMpS * 3.6; }