Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions modules/default/weather/current.njk
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,8 @@
{% if config.showHumidity === "below" %}
<span class="medium dimmed">{{ humidity() }}</span>
{% endif %}
{% elseif error %}
<div class="small dimmed">{{ "MODULE_CONFIG_ERROR" | translate({MODULE_NAME: "Weather", ERROR: error}) | safe }}</div>
{% else %}
<div class="dimmed light small">{{ "LOADING" | translate }}</div>
{% endif %}
Expand Down
2 changes: 2 additions & 0 deletions modules/default/weather/forecast.njk
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@
{% set currentStep = currentStep + 1 %}
{% endfor %}
</table>
{% elseif error %}
<div class="small dimmed">{{ "MODULE_CONFIG_ERROR" | translate({MODULE_NAME: "Weather", ERROR: error}) | safe }}</div>
{% else %}
<div class="dimmed light small">{{ "LOADING" | translate }}</div>
{% endif %}
Expand Down
2 changes: 2 additions & 0 deletions modules/default/weather/hourly.njk
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@
{% set currentStep = currentStep + 1 %}
{% endfor %}
</table>
{% elseif error %}
<div class="small dimmed">{{ "MODULE_CONFIG_ERROR" | translate({MODULE_NAME: "Weather", ERROR: error}) | safe }}</div>
{% else %}
<div class="dimmed light small">{{ "LOADING" | translate }}</div>
{% endif %}
Expand Down
27 changes: 6 additions & 21 deletions modules/default/weather/providers/openmeteo.js
Original file line number Diff line number Diff line change
Expand Up @@ -143,56 +143,41 @@ WeatherProvider.register("openmeteo", {
},

fetchCurrentWeather () {
this.fetchData(this.getUrl())
return this.fetchData(this.getUrl())
.then((data) => this.parseWeatherApiResponse(data))
.then((parsedData) => {
if (!parsedData) {
// No usable data?
return;
throw new Error("No usable data ...");
}

const currentWeather = this.generateWeatherDayFromCurrentWeather(parsedData);
this.setCurrentWeather(currentWeather);
})
.catch(function (request) {
Log.error("[weatherprovider.openmeteo] Could not load data ... ", request);
})
.finally(() => this.updateAvailable());
},

fetchWeatherForecast () {
this.fetchData(this.getUrl())
return this.fetchData(this.getUrl())
.then((data) => this.parseWeatherApiResponse(data))
.then((parsedData) => {
if (!parsedData) {
// No usable data?
return;
throw new Error("No usable data ...");
}

const dailyForecast = this.generateWeatherObjectsFromForecast(parsedData);
this.setWeatherForecast(dailyForecast);
})
.catch(function (request) {
Log.error("[weatherprovider.openmeteo] Could not load data ... ", request);
})
.finally(() => this.updateAvailable());
},

fetchWeatherHourly () {
this.fetchData(this.getUrl())
return this.fetchData(this.getUrl())
.then((data) => this.parseWeatherApiResponse(data))
.then((parsedData) => {
if (!parsedData) {
// No usable data?
return;
throw new Error("No usable data ...");
}

const hourlyForecast = this.generateWeatherObjectsFromHourly(parsedData);
this.setWeatherHourly(hourlyForecast);
})
.catch(function (request) {
Log.error("[weatherprovider.openmeteo] Could not load data ... ", request);
})
.finally(() => this.updateAvailable());
},

Expand Down
1 change: 1 addition & 0 deletions modules/default/weather/providers/ukmetofficedatahub.js
Original file line number Diff line number Diff line change
Expand Up @@ -271,6 +271,7 @@ WeatherProvider.register("ukmetofficedatahub", {
30: "thunderstorm"
};

// TODO check for duplicat eand if neeeded
return weatherTypes.hasOwnProperty(weatherType) ? weatherTypes[weatherType] : null;
}
});
42 changes: 28 additions & 14 deletions modules/default/weather/weather.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,8 @@ Module.register("weather", {
// Module properties.
weatherProvider: null,

error: null,

// Can be used by the provider to display location of event if nothing else is specified
firstEvent: null,

Expand Down Expand Up @@ -149,6 +151,12 @@ Module.register("weather", {
// Skip some hourly forecast entries if configured
const hourlyData = this.weatherProvider.weatherHourly()?.filter((e, i) => (i + 1) % this.config.hourlyForecastIncrements === this.config.hourlyForecastIncrements - 1);

if (this.error) {
return {
error: this.error
};
}

return {
config: this.config,
current: currentData,
Expand Down Expand Up @@ -195,20 +203,26 @@ Module.register("weather", {
nextLoad = delay;
}

setTimeout(() => {
switch (this.config.type.toLowerCase()) {
case "current":
this.weatherProvider.fetchCurrentWeather();
break;
case "hourly":
this.weatherProvider.fetchWeatherHourly();
break;
case "daily":
case "forecast":
this.weatherProvider.fetchWeatherForecast();
break;
default:
Log.error(`[weather] Invalid type ${this.config.type} configured (must be one of 'current', 'hourly', 'daily' or 'forecast')`);
setTimeout(async () => {
try {
switch (this.config.type.toLowerCase()) {
case "current":
await this.weatherProvider.fetchCurrentWeather();
break;
case "hourly":
this.weatherProvider.fetchWeatherHourly();
break;
case "daily":
case "forecast":
this.weatherProvider.fetchWeatherForecast();
break;
default:
Log.error(`[weather] Invalid type ${this.config.type} configured (must be one of 'current', 'hourly', 'daily' or 'forecast')`);
}
this.error = null;
} catch (error) {
this.error = error;
this.updateAvailable();
}
}, nextLoad);
},
Expand Down
6 changes: 3 additions & 3 deletions modules/default/weather/weatherprovider.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,19 +41,19 @@ const WeatherProvider = Class.extend({

// This method should start the API request to fetch the current weather.
// This method should definitely be overwritten in the provider.
fetchCurrentWeather () {
async fetchCurrentWeather () {
Log.warn(`[weatherprovider] ${this.providerName} does not subclass the fetchCurrentWeather method.`);
},

// This method should start the API request to fetch the weather forecast.
// This method should definitely be overwritten in the provider.
fetchWeatherForecast () {
async fetchWeatherForecast () {
Log.warn(`[weatherprovider] ${this.providerName} does not subclass the fetchWeatherForecast method.`);
},

// This method should start the API request to fetch the weather hourly.
// This method should definitely be overwritten in the provider.
fetchWeatherHourly () {
async fetchWeatherHourly () {
Log.warn(`[weatherprovider] ${this.providerName} does not subclass the fetchWeatherHourly method.`);
},

Expand Down
2 changes: 1 addition & 1 deletion tests/e2e/modules/calendar_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ describe("Calendar module", () => {
* @param {string} not reverse result
* @returns {boolean} result
*/
const testElementLength = async (element, result, not) => {
const testElementLength = async (element, result, not = "") => {
const elem = await helpers.waitForAllElements(element);
expect(elem).not.toBeNull();
if (not === "not") {
Expand Down
Loading