Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

weathergov missing method fetchWeatherHourly() #2925

Closed
dWoolridge opened this issue Oct 3, 2022 · 3 comments
Closed

weathergov missing method fetchWeatherHourly() #2925

dWoolridge opened this issue Oct 3, 2022 · 3 comments

Comments

@dWoolridge
Copy link
Contributor

The fetchWeatherHourly() method does not exist in weathergov.js. I'd prefer to have it functional because weather.gov gives 6.5 days of hourly forecasts.

I've created the fetchWeatherHourly() method to weathergov.js and tested it for functionality. It works, but the strange thing is that the new code shows "Loading..." until the first 10 minute refresh is reached, then it works. The fetchCurrentWeather() and fetchWeatherForecast() populate almost immediately.

These 3 "fetch" methods are called before the config.js information is read. Weathergov.js works by first retrieving URL's from the weather.gov API for the current, forecast, and hourly data. The URLs are read inside the setConfig method. Weathergov.js' first call (on startup) to all three fetch(es) fails. The fetchCurrentWeather() and fetchWeatherForecast() are then called again shortly after the config.js info is read. For some reason fetchWeatherHourly() is not called a second time along with the other 2 fetch(es).

Any idea on why the fetchWeatherHourly isn't called again at startup, but the other 2 fetch(es) are?


// ADDED TO weathergov.js

        // Overwrite the fetchWeatherHourly method.
        fetchWeatherHourly() {
                if (!this.configURLs) {
                        Log.info("fetchWeatherHourly: fetch wx waiting on config URLs");
                        return;
                }
                this.fetchData(this.forecastHourlyURL)
                        .then((data) => {
                                if (!data) {
                                        // Did not receive usable new data.
                                        // Maybe this needs a better check?
                                        return;
                                }
                                const hourly = this.generateWeatherObjectsFromHourly(data.properties.periods);
                                this.setWeatherHourly(hourly);
                        })
                        .catch(function (request) {
                                Log.error("Could not load data ... ", request);
                        })
                        .finally(() => this.updateAvailable());
        },

// ADDED TO weathergov.js

        generateWeatherObjectsFromHourly(forecasts) {
                // initial variable declaration
                const days = [];

                // variable for date
                let date = "";
                let weather = new WeatherObject(this.config.units, this.config.tempUnits, this.config.windUnits, this.config.useKmh);
                for (const forecast of forecasts) {
                        weather.date = moment(forecast.startTime.slice(0,19));
                        weather.windSpeed = forecast.windSpeed;
                        weather.windDirection = forecast.windDirection;
                        weather.temperature = forecast.temperature;
                        weather.tempUnits = forecast.temperatureUnit;
                        // use the forecast isDayTime attribute to help build the weatherType label
                        weather.weatherType = this.convertWeatherType(forecast.shortForecast, forecast.isDaytime);

                        // push weather information to days array
                        days.push(weather);

                        // create new weather-object
                        weather = new WeatherObject(this.config.units, this.config.tempUnits, this.config.windUnits, this.config.useKmh);
                }

                // push weather information to days array
                days.push(weather);
                return days;
        },
@rejas
Copy link
Collaborator

rejas commented Oct 3, 2022

Hi @dWoolridge it might be easier to check your code if you'd create a PR with it and mark it as a draft. That way I can check it out directly and maybe help you sicne I was working quit a lot in the weather module the last feek weeks :)

@dWoolridge
Copy link
Contributor Author

Pull request created:
#2929 (comment)

Sorry, but I must have missed the Draft option when I created it.

@rejas
Copy link
Collaborator

rejas commented Oct 6, 2022

Fixed with #2933

Thanks for your work @dWoolridge !

@rejas rejas closed this as completed Oct 6, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants