From 48756e877403d914c64c8da06a4f7e5bfbace07c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Malte=20Hallstr=C3=B6m?= Date: Sun, 28 Aug 2022 20:23:01 +0200 Subject: [PATCH] feat(weather/smhi): calculate apparent temperature --- modules/default/weather/providers/smhi.js | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/modules/default/weather/providers/smhi.js b/modules/default/weather/providers/smhi.js index 4bced3e0c9..25a266085c 100644 --- a/modules/default/weather/providers/smhi.js +++ b/modules/default/weather/providers/smhi.js @@ -108,6 +108,16 @@ WeatherProvider.register("smhi", { return `https://opendata-download-metfcst.smhi.se/api/category/pmp3g/version/2/geotype/point/lon/${lon}/lat/${lat}/data.json`; }, + /** Calculates the apparent temperature based on known atmospheric data. */ + calculateApparentTemperature(weatherData) { + const Ta = this.paramValue(weatherData, "t"); + const rh = this.paramValue(weatherData, "r"); + const ws = this.paramValue(weatherData, "ws"); + const p = (rh / 100) * 6.105 * Math.E * ((17.27 * Ta) / (237.7 + Ta)) + + return Ta + 0.33 * p - 0.7 * ws - 4 + }, + /** * Converts the returned data into a WeatherObject with required properties set for both current weather and forecast. * The returned units is always in metric system. @@ -128,6 +138,7 @@ WeatherProvider.register("smhi", { currentWeather.windSpeed = this.paramValue(weatherData, "ws"); currentWeather.windDirection = this.paramValue(weatherData, "wd"); currentWeather.weatherType = this.convertWeatherType(this.paramValue(weatherData, "Wsymb2"), currentWeather.isDayTime()); + currentWeather.feelsLikeTemp = this.calculateAT(weatherData); // Determine the precipitation amount and category and update the // weatherObject with it, the valuetype to use can be configured or uses