diff --git a/CHANGELOG.md b/CHANGELOG.md index 71c1282c..7f8f25e0 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -12,6 +12,8 @@ _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. +- Chuvash translation. - Added Weatherbit as a provider to Weather module. - Added Hindi & Gujarati translation. - Chuvash translation. @@ -36,6 +38,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) - Fix console.debug not having timestamps (#2199) - Fix calendar full day event east of UTC start time (#2200) - Fix non-fullday recurring rule processing (#2216) 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..2fde7139 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 f1a50074..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) 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..af2e09c6 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..86837763 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 c195e7af..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, @@ -42,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, diff --git a/modules/default/weather/weatherobject.js b/modules/default/weather/weatherobject.js index 3b145b3d..3fbbb42a 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) {