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

@@ -48,7 +48,7 @@ _This release is scheduled to be released on 2023-04-01._
- Yr wind direction is no longer inverted - Yr wind direction is no longer inverted
- Fix async node_helper stopping electron start (#2487) - Fix async node_helper stopping electron start (#2487)
- The wind direction arrow now points in the direction the wind is flowing, not into the wind (#3019) - The wind direction arrow now points in the direction the wind is flowing, not into the wind (#3019)
- Fix precipitation css styles - Fix precipitation css styles and rounding value
## [2.22.0] - 2023-01-01 ## [2.22.0] - 2023-01-01

View File

@@ -14,7 +14,7 @@ function getConfig(req, res) {
} }
/** /**
* A method that forewards HTTP Get-methods to the internet to avoid CORS-errors. * A method that forwards HTTP Get-methods to the internet to avoid CORS-errors.
* *
* Example input request url: /cors?sendheaders=header1:value1,header2:value2&expectedheaders=header1,header2&url=http://www.test.com/path?param1=value1 * Example input request url: /cors?sendheaders=header1:value1,header2:value2&expectedheaders=header1,header2&url=http://www.test.com/path?param1=value1
* *
@@ -26,7 +26,7 @@ function getConfig(req, res) {
async function cors(req, res) { async function cors(req, res) {
try { try {
const urlRegEx = "url=(.+?)$"; const urlRegEx = "url=(.+?)$";
let url = ""; let url;
const match = new RegExp(urlRegEx, "g").exec(req.url); const match = new RegExp(urlRegEx, "g").exec(req.url);
if (!match) { if (!match) {
@@ -56,7 +56,7 @@ async function cors(req, res) {
} }
/** /**
* Gets headers and values to attatch to the web request. * Gets headers and values to attach to the web request.
* *
* @param {string} url - The url containing the headers and values to send. * @param {string} url - The url containing the headers and values to send.
* @returns {object} An object specifying name and value of the headers. * @returns {object} An object specifying name and value of the headers.

View File

@@ -5,8 +5,8 @@
* @param {string} type what contenttype to expect in the response, can be "json" or "xml" * @param {string} type what contenttype to expect in the response, can be "json" or "xml"
* @param {boolean} useCorsProxy A flag to indicate * @param {boolean} useCorsProxy A flag to indicate
* @param {Array.<{name: string, value:string}>} requestHeaders the HTTP headers to send * @param {Array.<{name: string, value:string}>} requestHeaders the HTTP headers to send
* @param {Array.<string>} expectedResponseHeaders the expected HTTP headers to recieve * @param {Array.<string>} expectedResponseHeaders the expected HTTP headers to receive
* @returns {Promise} resolved when the fetch is done. The response headers is placed in a headers-property (provided the response does not allready contain a headers-property). * @returns {Promise} resolved when the fetch is done. The response headers is placed in a headers-property (provided the response does not already contain a headers-property).
*/ */
async function performWebRequest(url, type = "json", useCorsProxy = false, requestHeaders = undefined, expectedResponseHeaders = undefined) { async function performWebRequest(url, type = "json", useCorsProxy = false, requestHeaders = undefined, expectedResponseHeaders = undefined) {
const request = {}; const request = {};
@@ -36,7 +36,7 @@ async function performWebRequest(url, type = "json", useCorsProxy = false, reque
* *
* @param {string} url the url to fetch from * @param {string} url the url to fetch from
* @param {Array.<{name: string, value:string}>} requestHeaders the HTTP headers to send * @param {Array.<{name: string, value:string}>} requestHeaders the HTTP headers to send
* @param {Array.<string>} expectedResponseHeaders the expected HTTP headers to recieve * @param {Array.<string>} expectedResponseHeaders the expected HTTP headers to receive
* @returns {string} to be used as URL when calling CORS-method on server. * @returns {string} to be used as URL when calling CORS-method on server.
*/ */
const getCorsUrl = function (url, requestHeaders, expectedResponseHeaders) { const getCorsUrl = function (url, requestHeaders, expectedResponseHeaders) {
@@ -84,7 +84,7 @@ const getRequestHeaderString = function (requestHeaders) {
}; };
/** /**
* Gets headers and values to attatch to the web request. * Gets headers and values to attach to the web request.
* *
* @param {Array.<{name: string, value:string}>} requestHeaders the HTTP headers to send * @param {Array.<{name: string, value:string}>} requestHeaders the HTTP headers to send
* @returns {object} An object specifying name and value of the headers. * @returns {object} An object specifying name and value of the headers.
@@ -101,9 +101,9 @@ const getHeadersToSend = (requestHeaders) => {
}; };
/** /**
* Gets the part of the CORS URL that represents the expected HTTP headers to recieve. * Gets the part of the CORS URL that represents the expected HTTP headers to receive.
* *
* @param {Array.<string>} expectedResponseHeaders the expected HTTP headers to recieve * @param {Array.<string>} expectedResponseHeaders the expected HTTP headers to receive
* @returns {string} to be used as the expected HTTP-headers component in CORS URL. * @returns {string} to be used as the expected HTTP-headers component in CORS URL.
*/ */
const getExpectedResponseHeadersString = function (expectedResponseHeaders) { const getExpectedResponseHeadersString = function (expectedResponseHeaders) {
@@ -124,7 +124,7 @@ const getExpectedResponseHeadersString = function (expectedResponseHeaders) {
/** /**
* Gets the values for the expected headers from the response. * Gets the values for the expected headers from the response.
* *
* @param {Array.<string>} expectedResponseHeaders the expected HTTP headers to recieve * @param {Array.<string>} expectedResponseHeaders the expected HTTP headers to receive
* @param {Response} response the HTTP response * @param {Response} response the HTTP response
* @returns {string} to be used as the expected HTTP-headers component in CORS URL. * @returns {string} to be used as the expected HTTP-headers component in CORS URL.
*/ */

View File

@@ -145,9 +145,9 @@ WeatherProvider.register("openweathermap", {
*/ */
generateWeatherObjectsFromForecast(forecasts) { generateWeatherObjectsFromForecast(forecasts) {
if (this.config.weatherEndpoint === "/forecast") { if (this.config.weatherEndpoint === "/forecast") {
return this.fetchForecastHourly(forecasts); return this.generateForecastHourly(forecasts);
} else if (this.config.weatherEndpoint === "/forecast/daily") { } 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? // if weatherEndpoint does not match forecast or forecast/daily, what should be returned?
return [new WeatherObject()]; 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 // initial variable declaration
const days = []; const days = [];
// variables for temperature range and rain // 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 // initial variable declaration
const days = []; const days = [];

View File

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

View File

@@ -51,7 +51,7 @@ describe("Weather module: Weather Hourly Forecast", () => {
}); });
describe("Shows precipitation probability", () => { describe("Shows precipitation probability", () => {
const propabilities = [undefined, undefined, "12%", "36%", "44%"]; const propabilities = [undefined, undefined, "12 %", "36 %", "44 %"];
for (const [index, pop] of propabilities.entries()) { for (const [index, pop] of propabilities.entries()) {
if (pop) { if (pop) {
it(`should render probability ${pop}`, async () => { it(`should render probability ${pop}`, async () => {