Use type value from config instead just only weatherEndpoint

This commit is contained in:
veeck 2022-08-16 22:39:30 +02:00
parent 4d8fb8c176
commit ec13c952d9

View File

@ -69,6 +69,31 @@ WeatherProvider.register("weatherbit", {
.finally(() => this.updateAvailable()); .finally(() => this.updateAvailable());
}, },
/**
* Overrides method for setting config to check if endpoint is correct for hourly
*
* @param {object} config The configuration object
*/
setConfig(config) {
this.config = config;
if (!this.config.weatherEndpoint) {
switch (this.config.type) {
case "hourly":
this.config.weatherEndpoint = "/forecast/hourly";
break;
case "daily":
case "forecast":
this.config.weatherEndpoint = "/forecast/daily";
break;
case "current":
this.config.weatherEndpoint = "/current";
break;
default:
Log.error("weatherEndpoint not configured and could not resolve it based on type");
}
}
},
// Create a URL from the config and base URL. // Create a URL from the config and base URL.
getUrl() { getUrl() {
const units = this.units[this.config.units] || "auto"; const units = this.units[this.config.units] || "auto";