diff --git a/modules/default/weather/providers/darksky.js b/modules/default/weather/providers/darksky.js index b2bf4e78..ea073887 100755 --- a/modules/default/weather/providers/darksky.js +++ b/modules/default/weather/providers/darksky.js @@ -15,6 +15,15 @@ WeatherProvider.register("darksky", { // Not strictly required, but helps for debugging. providerName: "Dark Sky", + // Set the default config properties that is specific to this provider + defaults: { + apiBase: "https://cors-anywhere.herokuapp.com/https://api.darksky.net", + weatherEndpoint: "/forecast", + apiKey: "", + lat: 0, + lon: 0 + }, + units: { imperial: "us", metric: "si" diff --git a/modules/default/weather/providers/openweathermap.js b/modules/default/weather/providers/openweathermap.js index fd9b3244..66f31703 100755 --- a/modules/default/weather/providers/openweathermap.js +++ b/modules/default/weather/providers/openweathermap.js @@ -14,6 +14,18 @@ WeatherProvider.register("openweathermap", { // But for debugging (and future alerts) it would be nice to have the real name. providerName: "OpenWeatherMap", + // Set the default config properties that is specific to this provider + defaults: { + apiVersion: "2.5", + apiBase: "https://api.openweathermap.org/data/", + weatherEndpoint: "/weather", + locationID: false, + location: false, + lat: 0, + lon: 0, + apiKey: "" + }, + // Overwrite the fetchCurrentWeather method. fetchCurrentWeather() { this.fetchData(this.getUrl()) diff --git a/modules/default/weather/providers/smhi.js b/modules/default/weather/providers/smhi.js index cdbaf013..a27b1300 100644 --- a/modules/default/weather/providers/smhi.js +++ b/modules/default/weather/providers/smhi.js @@ -14,6 +14,13 @@ WeatherProvider.register("smhi", { providerName: "SMHI", + // Set the default config properties that is specific to this provider + defaults: { + lat: 0, + lon: 0, + precipitationValue: "pmedian" + }, + /** * Implements method in interface for fetching current weather */ @@ -55,7 +62,7 @@ WeatherProvider.register("smhi", { this.config = config; if (!config.precipitationValue || ["pmin", "pmean", "pmedian", "pmax"].indexOf(config.precipitationValue) == -1) { console.log("invalid or not set: " + config.precipitationValue); - config.precipitationValue = "pmedian"; + config.precipitationValue = this.defaults.precipitationValue; } }, diff --git a/modules/default/weather/providers/ukmetoffice.js b/modules/default/weather/providers/ukmetoffice.js index b71ced88..11cee48f 100755 --- a/modules/default/weather/providers/ukmetoffice.js +++ b/modules/default/weather/providers/ukmetoffice.js @@ -14,6 +14,13 @@ WeatherProvider.register("ukmetoffice", { // But for debugging (and future alerts) it would be nice to have the real name. providerName: "UK Met Office", + // Set the default config properties that is specific to this provider + defaults: { + apiBase: "http://datapoint.metoffice.gov.uk/public/data/val/wxfcs/all/json/", + locationID: false, + apiKey: "" + }, + units: { imperial: "us", metric: "si" diff --git a/modules/default/weather/providers/ukmetofficedatahub.js b/modules/default/weather/providers/ukmetofficedatahub.js index af2e09c6..03e5fa5a 100644 --- a/modules/default/weather/providers/ukmetofficedatahub.js +++ b/modules/default/weather/providers/ukmetofficedatahub.js @@ -44,6 +44,16 @@ WeatherProvider.register("ukmetofficedatahub", { // Set the name of the provider. providerName: "UK Met Office (DataHub)", + // Set the default config properties that is specific to this provider + defaults: { + apiBase: "https://api-metoffice.apiconnect.ibmcloud.com/metoffice/production/v0/forecasts/point/", + apiKey: "", + apiSecret: "", + lat: 0, + lon: 0, + windUnits: "mph" + }, + // Build URL with query strings according to DataHub API (https://metoffice.apiconnect.ibmcloud.com/metoffice/production/api) getUrl(forecastType) { let queryStrings = "?"; diff --git a/modules/default/weather/providers/weatherbit.js b/modules/default/weather/providers/weatherbit.js index 6bd3508e..afca0c83 100644 --- a/modules/default/weather/providers/weatherbit.js +++ b/modules/default/weather/providers/weatherbit.js @@ -14,6 +14,15 @@ WeatherProvider.register("weatherbit", { // Not strictly required, but helps for debugging. providerName: "Weatherbit", + // Set the default config properties that is specific to this provider + defaults: { + apiBase: "https://api.weatherbit.io/v2.0", + weatherEndpoint: "/current", + apiKey: "", + lat: 0, + lon: 0 + }, + units: { imperial: "I", metric: "M" diff --git a/modules/default/weather/providers/weathergov.js b/modules/default/weather/providers/weathergov.js index 86837763..ee418edc 100755 --- a/modules/default/weather/providers/weathergov.js +++ b/modules/default/weather/providers/weathergov.js @@ -19,6 +19,14 @@ WeatherProvider.register("weathergov", { // But for debugging (and future alerts) it would be nice to have the real name. providerName: "Weather.gov", + // Set the default config properties that is specific to this provider + defaults: { + apiBase: "https://api.weatherbit.io/v2.0", + weatherEndpoint: "/forecast", + lat: 0, + lon: 0 + }, + // Flag all needed URLs availability configURLs: false, diff --git a/modules/default/weather/weather.js b/modules/default/weather/weather.js index d6678134..4006313a 100644 --- a/modules/default/weather/weather.js +++ b/modules/default/weather/weather.js @@ -12,10 +12,6 @@ Module.register("weather", { weatherProvider: "openweathermap", roundTemp: false, type: "current", // current, forecast, daily (equivalent to forecast), hourly (only with OpenWeatherMap /onecall endpoint) - lat: 0, - lon: 0, - location: false, - locationID: false, units: config.units, useKmh: false, tempUnits: config.units, @@ -40,12 +36,6 @@ Module.register("weather", { fade: true, fadePoint: 0.25, // Start on 1/4th of the list. initialLoadDelay: 0, // 0 seconds delay - retryDelay: 2500, - apiKey: "", - apiSecret: "", - apiVersion: "2.5", - apiBase: "https://api.openweathermap.org/data/", // TODO: this should not be part of the weather.js file, but should be contained in the openweatherprovider - weatherEndpoint: "/weather", appendLocationNameToHeader: true, calendarClass: "calendar", tableClass: "small", @@ -129,8 +119,8 @@ Module.register("weather", { return `hourly.njk`; case "daily": case "forecast": + //Make the invalid values use the "Loading..." from forecast default: - //Make the invalid values use the "Loading..." from forecast return `forecast.njk`; } }, diff --git a/modules/default/weather/weatherprovider.js b/modules/default/weather/weatherprovider.js index 2d031b2e..29e0aee5 100644 --- a/modules/default/weather/weatherprovider.js +++ b/modules/default/weather/weatherprovider.js @@ -11,6 +11,7 @@ var WeatherProvider = Class.extend({ // Weather Provider Properties providerName: null, + defaults: {}, // The following properties have accessor methods. // Try to not access them directly. @@ -154,10 +155,11 @@ WeatherProvider.register = function (providerIdentifier, providerDetails) { WeatherProvider.initialize = function (providerIdentifier, delegate) { providerIdentifier = providerIdentifier.toLowerCase(); - var provider = new WeatherProvider.providers[providerIdentifier](); + const provider = new WeatherProvider.providers[providerIdentifier](); + const config = Object.assign({}, provider.defaults, delegate.config); provider.delegate = delegate; - provider.setConfig(delegate.config); + provider.setConfig(config); provider.providerIdentifier = providerIdentifier; if (!provider.providerName) {