make weatherprovider have a method for hourly fetching instead of a generic weatherData

This commit is contained in:
buxxi
2021-01-23 10:45:55 +01:00
parent d48113f2d9
commit e2cfa24686
6 changed files with 19 additions and 30 deletions

View File

@@ -1,7 +1,4 @@
{% if current or weatherData %} {% if current %}
{% if weatherData %}
{% set current = weatherData.current %}
{% endif %}
{% if not config.onlyTemp %} {% if not config.onlyTemp %}
<div class="normal medium"> <div class="normal medium">
<span class="wi wi-strong-wind dimmed"></span> <span class="wi wi-strong-wind dimmed"></span>

View File

@@ -1,10 +1,5 @@
{% if forecast or weatherData %} {% if forecast %}
{% if weatherData %} {% set numSteps = forecast | calcNumSteps %}
{% set forecast = weatherData.days %}
{% set numSteps = forecast | calcNumEntries %}
{% else %}
{% set numSteps = forecast | calcNumSteps %}
{% endif %}
{% set currentStep = 0 %} {% set currentStep = 0 %}
<table class="{{ config.tableClass }}"> <table class="{{ config.tableClass }}">
{% set forecast = forecast.slice(0, numSteps) %} {% set forecast = forecast.slice(0, numSteps) %}

View File

@@ -1,7 +1,4 @@
{% if hourly or weatherData %} {% if hourly %}
{% if weatherData %}
{% set hourly = weatherData.hours %}
{% endif %}
{% set numSteps = hourly | calcNumEntries %} {% set numSteps = hourly | calcNumEntries %}
{% set currentStep = 0 %} {% set currentStep = 0 %}
<table class="{{ config.tableClass }}"> <table class="{{ config.tableClass }}">
@@ -29,4 +26,4 @@
{% endif %} {% endif %}
<!-- Uncomment the line below to see the contents of the `hourly` object. --> <!-- Uncomment the line below to see the contents of the `hourly` object. -->
<!-- <div style="word-wrap:break-word" class="xsmall dimmed">{{weatherData | dump}}</div> --> <!-- <div style="word-wrap:break-word" class="xsmall dimmed">{{hourly | dump}}</div> -->

View File

@@ -56,8 +56,8 @@ WeatherProvider.register("openweathermap", {
.finally(() => this.updateAvailable()); .finally(() => this.updateAvailable());
}, },
// Overwrite the fetchWeatherData method. // Overwrite the fetchWeatherHourly method.
fetchWeatherData() { fetchWeatherHourly() {
this.fetchData(this.getUrl()) this.fetchData(this.getUrl())
.then((data) => { .then((data) => {
if (!data) { if (!data) {
@@ -69,7 +69,7 @@ WeatherProvider.register("openweathermap", {
this.setFetchedLocation(`(${data.lat},${data.lon})`); this.setFetchedLocation(`(${data.lat},${data.lon})`);
const weatherData = this.generateWeatherObjectsFromOnecall(data); const weatherData = this.generateWeatherObjectsFromOnecall(data);
this.setWeatherData(weatherData); this.setWeatherHourly(weatherData.hours);
}) })
.catch(function (request) { .catch(function (request) {
Log.error("Could not load data ... ", request); Log.error("Could not load data ... ", request);

View File

@@ -141,7 +141,7 @@ Module.register("weather", {
config: this.config, config: this.config,
current: this.weatherProvider.currentWeather(), current: this.weatherProvider.currentWeather(),
forecast: this.weatherProvider.weatherForecast(), forecast: this.weatherProvider.weatherForecast(),
weatherData: this.weatherProvider.weatherData(), hourly: this.weatherProvider.weatherHourly(),
indoor: { indoor: {
humidity: this.indoorHumidity, humidity: this.indoorHumidity,
temperature: this.indoorTemperature temperature: this.indoorTemperature
@@ -172,7 +172,7 @@ Module.register("weather", {
this.weatherProvider.fetchCurrentWeather(); this.weatherProvider.fetchCurrentWeather();
break; break;
case "hourly": case "hourly":
this.weatherProvider.fetchWeatherData(); this.weatherProvider.fetchWeatherHourly();
break; break;
case "daily": case "daily":
case "forecast": case "forecast":

View File

@@ -16,7 +16,7 @@ var WeatherProvider = Class.extend({
// Try to not access them directly. // Try to not access them directly.
currentWeatherObject: null, currentWeatherObject: null,
weatherForecastArray: null, weatherForecastArray: null,
weatherDataObject: null, weatherHourlyArray: null,
fetchedLocationName: null, fetchedLocationName: null,
// The following properties will be set automatically. // The following properties will be set automatically.
@@ -57,10 +57,10 @@ var WeatherProvider = Class.extend({
Log.warn(`Weather provider: ${this.providerName} does not subclass the fetchWeatherForecast method.`); Log.warn(`Weather provider: ${this.providerName} does not subclass the fetchWeatherForecast method.`);
}, },
// This method should start the API request to fetch the weather forecast. // This method should start the API request to fetch the weather hourly.
// This method should definitely be overwritten in the provider. // This method should definitely be overwritten in the provider.
fetchWeatherData: function () { fetchWeatherHourly: function () {
Log.warn(`Weather provider: ${this.providerName} does not subclass the fetchWeatherData method.`); Log.warn(`Weather provider: ${this.providerName} does not subclass the fetchWeatherHourly method.`);
}, },
// This returns a WeatherDay object for the current weather. // This returns a WeatherDay object for the current weather.
@@ -74,8 +74,8 @@ var WeatherProvider = Class.extend({
}, },
// This returns an object containing WeatherDay object(s) depending on the type of call. // This returns an object containing WeatherDay object(s) depending on the type of call.
weatherData: function () { weatherHourly: function () {
return this.weatherDataObject; return this.weatherHourlyArray;
}, },
// This returns the name of the fetched location or an empty string. // This returns the name of the fetched location or an empty string.
@@ -95,9 +95,9 @@ var WeatherProvider = Class.extend({
this.weatherForecastArray = weatherForecastArray; this.weatherForecastArray = weatherForecastArray;
}, },
// Set the weatherDataObject and notify the delegate that new information is available. // Set the weatherHourlyArray and notify the delegate that new information is available.
setWeatherData: function (weatherDataObject) { setWeatherHourlyData: function (weatherHourlyArray) {
this.weatherDataObject = weatherDataObject; this.weatherHourlyArray = weatherHourlyArray;
}, },
// Set the fetched location name. // Set the fetched location name.