From 0a1067ec7d72271a6296ca4b8a0ad392e1ce90fa Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Malte=20Hallstr=C3=B6m?= Date: Sun, 28 Aug 2022 20:23:43 +0200 Subject: [PATCH] feat(weather/smhi): support custom location names --- modules/default/weather/providers/smhi.js | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/modules/default/weather/providers/smhi.js b/modules/default/weather/providers/smhi.js index 25a26608..ce5ac772 100644 --- a/modules/default/weather/providers/smhi.js +++ b/modules/default/weather/providers/smhi.js @@ -17,7 +17,8 @@ WeatherProvider.register("smhi", { defaults: { lat: 0, lon: 0, - precipitationValue: "pmedian" + precipitationValue: "pmedian", + location: false, }, /** @@ -29,7 +30,7 @@ WeatherProvider.register("smhi", { let closest = this.getClosestToCurrentTime(data.timeSeries); let coordinates = this.resolveCoordinates(data); let weatherObject = this.convertWeatherDataToObject(closest, coordinates); - this.setFetchedLocation(`(${coordinates.lat},${coordinates.lon})`); + this.setFetchedLocation(this.config.location || `(${coordinates.lat},${coordinates.lon})`); this.setCurrentWeather(weatherObject); }) .catch((error) => Log.error("Could not load data: " + error.message)) @@ -43,8 +44,8 @@ WeatherProvider.register("smhi", { this.fetchData(this.getURL()) .then((data) => { let coordinates = this.resolveCoordinates(data); - const weatherObjects = this.convertWeatherDataGroupedBy(data.timeSeries, coordinates); - this.setFetchedLocation(`(${coordinates.lat},${coordinates.lon})`); + let weatherObjects = this.convertWeatherDataGroupedBy(data.timeSeries, coordinates); + this.setFetchedLocation(this.config.location || `(${coordinates.lat},${coordinates.lon})`); this.setWeatherForecast(weatherObjects); }) .catch((error) => Log.error("Could not load data: " + error.message)) @@ -59,7 +60,7 @@ WeatherProvider.register("smhi", { .then((data) => { let coordinates = this.resolveCoordinates(data); let weatherObjects = this.convertWeatherDataGroupedBy(data.timeSeries, coordinates, "hour"); - this.setFetchedLocation(`(${coordinates.lat},${coordinates.lon})`); + this.setFetchedLocation(this.config.location || `(${coordinates.lat},${coordinates.lon})`); this.setWeatherHourly(weatherObjects); }) .catch((error) => Log.error("Could not load data: " + error.message))