Fix rounding in precipitation percentage (#3045)

Percentage should be always rounded so that we dont get something like
"47.0000000001 %"

Some small typo and naming fixes also while I am here

---------

Co-authored-by: veeck <michael@veeck.de>
This commit is contained in:
Veeck
2023-02-20 20:04:40 +01:00
committed by GitHub
parent 390e5d6490
commit 6d86ffade4
6 changed files with 21 additions and 19 deletions

View File

@@ -145,9 +145,9 @@ WeatherProvider.register("openweathermap", {
*/
generateWeatherObjectsFromForecast(forecasts) {
if (this.config.weatherEndpoint === "/forecast") {
return this.fetchForecastHourly(forecasts);
return this.generateForecastHourly(forecasts);
} else if (this.config.weatherEndpoint === "/forecast/daily") {
return this.fetchForecastDaily(forecasts);
return this.generateForecastDaily(forecasts);
}
// if weatherEndpoint does not match forecast or forecast/daily, what should be returned?
return [new WeatherObject()];
@@ -165,9 +165,10 @@ WeatherProvider.register("openweathermap", {
},
/*
* fetch forecast information for 3-hourly forecast (available for free subscription).
* Generate forecast information for 3-hourly forecast (available for free
* subscription).
*/
fetchForecastHourly(forecasts) {
generateForecastHourly(forecasts) {
// initial variable declaration
const days = [];
// variables for temperature range and rain
@@ -238,9 +239,10 @@ WeatherProvider.register("openweathermap", {
},
/*
* fetch forecast information for daily forecast (available for paid subscription or old apiKey).
* Generate forecast information for daily forecast (available for paid
* subscription or old apiKey).
*/
fetchForecastDaily(forecasts) {
generateForecastDaily(forecasts) {
// initial variable declaration
const days = [];

View File

@@ -40,7 +40,7 @@ const WeatherUtils = {
valueUnit = valueUnit ? valueUnit : "mm";
}
if (valueUnit === "%") return `${value}${valueUnit}`;
if (valueUnit === "%") return `${value.toFixed(0)} ${valueUnit}`;
return `${value.toFixed(2)} ${valueUnit}`;
},