mirror of
https://github.com/MichMich/MagicMirror.git
synced 2025-06-27 19:53:36 +00:00
Moving default values regarding specific providers into the providers themselves
This commit is contained in:
parent
e2cfa24686
commit
41508931be
@ -15,6 +15,15 @@ WeatherProvider.register("darksky", {
|
|||||||
// Not strictly required, but helps for debugging.
|
// Not strictly required, but helps for debugging.
|
||||||
providerName: "Dark Sky",
|
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: {
|
units: {
|
||||||
imperial: "us",
|
imperial: "us",
|
||||||
metric: "si"
|
metric: "si"
|
||||||
|
@ -14,6 +14,18 @@ WeatherProvider.register("openweathermap", {
|
|||||||
// But for debugging (and future alerts) it would be nice to have the real name.
|
// But for debugging (and future alerts) it would be nice to have the real name.
|
||||||
providerName: "OpenWeatherMap",
|
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.
|
// Overwrite the fetchCurrentWeather method.
|
||||||
fetchCurrentWeather() {
|
fetchCurrentWeather() {
|
||||||
this.fetchData(this.getUrl())
|
this.fetchData(this.getUrl())
|
||||||
|
@ -14,6 +14,13 @@
|
|||||||
WeatherProvider.register("smhi", {
|
WeatherProvider.register("smhi", {
|
||||||
providerName: "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
|
* Implements method in interface for fetching current weather
|
||||||
*/
|
*/
|
||||||
@ -55,7 +62,7 @@ WeatherProvider.register("smhi", {
|
|||||||
this.config = config;
|
this.config = config;
|
||||||
if (!config.precipitationValue || ["pmin", "pmean", "pmedian", "pmax"].indexOf(config.precipitationValue) == -1) {
|
if (!config.precipitationValue || ["pmin", "pmean", "pmedian", "pmax"].indexOf(config.precipitationValue) == -1) {
|
||||||
console.log("invalid or not set: " + config.precipitationValue);
|
console.log("invalid or not set: " + config.precipitationValue);
|
||||||
config.precipitationValue = "pmedian";
|
config.precipitationValue = this.defaults.precipitationValue;
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
|
@ -14,6 +14,13 @@ WeatherProvider.register("ukmetoffice", {
|
|||||||
// But for debugging (and future alerts) it would be nice to have the real name.
|
// But for debugging (and future alerts) it would be nice to have the real name.
|
||||||
providerName: "UK Met Office",
|
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: {
|
units: {
|
||||||
imperial: "us",
|
imperial: "us",
|
||||||
metric: "si"
|
metric: "si"
|
||||||
|
@ -44,6 +44,16 @@ WeatherProvider.register("ukmetofficedatahub", {
|
|||||||
// Set the name of the provider.
|
// Set the name of the provider.
|
||||||
providerName: "UK Met Office (DataHub)",
|
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)
|
// Build URL with query strings according to DataHub API (https://metoffice.apiconnect.ibmcloud.com/metoffice/production/api)
|
||||||
getUrl(forecastType) {
|
getUrl(forecastType) {
|
||||||
let queryStrings = "?";
|
let queryStrings = "?";
|
||||||
|
@ -14,6 +14,15 @@ WeatherProvider.register("weatherbit", {
|
|||||||
// Not strictly required, but helps for debugging.
|
// Not strictly required, but helps for debugging.
|
||||||
providerName: "Weatherbit",
|
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: {
|
units: {
|
||||||
imperial: "I",
|
imperial: "I",
|
||||||
metric: "M"
|
metric: "M"
|
||||||
|
@ -19,6 +19,14 @@ WeatherProvider.register("weathergov", {
|
|||||||
// But for debugging (and future alerts) it would be nice to have the real name.
|
// But for debugging (and future alerts) it would be nice to have the real name.
|
||||||
providerName: "Weather.gov",
|
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
|
// Flag all needed URLs availability
|
||||||
configURLs: false,
|
configURLs: false,
|
||||||
|
|
||||||
|
@ -12,10 +12,6 @@ Module.register("weather", {
|
|||||||
weatherProvider: "openweathermap",
|
weatherProvider: "openweathermap",
|
||||||
roundTemp: false,
|
roundTemp: false,
|
||||||
type: "current", // current, forecast, daily (equivalent to forecast), hourly (only with OpenWeatherMap /onecall endpoint)
|
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,
|
units: config.units,
|
||||||
useKmh: false,
|
useKmh: false,
|
||||||
tempUnits: config.units,
|
tempUnits: config.units,
|
||||||
@ -40,12 +36,6 @@ Module.register("weather", {
|
|||||||
fade: true,
|
fade: true,
|
||||||
fadePoint: 0.25, // Start on 1/4th of the list.
|
fadePoint: 0.25, // Start on 1/4th of the list.
|
||||||
initialLoadDelay: 0, // 0 seconds delay
|
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,
|
appendLocationNameToHeader: true,
|
||||||
calendarClass: "calendar",
|
calendarClass: "calendar",
|
||||||
tableClass: "small",
|
tableClass: "small",
|
||||||
@ -129,8 +119,8 @@ Module.register("weather", {
|
|||||||
return `hourly.njk`;
|
return `hourly.njk`;
|
||||||
case "daily":
|
case "daily":
|
||||||
case "forecast":
|
case "forecast":
|
||||||
|
//Make the invalid values use the "Loading..." from forecast
|
||||||
default:
|
default:
|
||||||
//Make the invalid values use the "Loading..." from forecast
|
|
||||||
return `forecast.njk`;
|
return `forecast.njk`;
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
@ -11,6 +11,7 @@
|
|||||||
var WeatherProvider = Class.extend({
|
var WeatherProvider = Class.extend({
|
||||||
// Weather Provider Properties
|
// Weather Provider Properties
|
||||||
providerName: null,
|
providerName: null,
|
||||||
|
defaults: {},
|
||||||
|
|
||||||
// The following properties have accessor methods.
|
// The following properties have accessor methods.
|
||||||
// Try to not access them directly.
|
// Try to not access them directly.
|
||||||
@ -154,10 +155,11 @@ WeatherProvider.register = function (providerIdentifier, providerDetails) {
|
|||||||
WeatherProvider.initialize = function (providerIdentifier, delegate) {
|
WeatherProvider.initialize = function (providerIdentifier, delegate) {
|
||||||
providerIdentifier = providerIdentifier.toLowerCase();
|
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.delegate = delegate;
|
||||||
provider.setConfig(delegate.config);
|
provider.setConfig(config);
|
||||||
|
|
||||||
provider.providerIdentifier = providerIdentifier;
|
provider.providerIdentifier = providerIdentifier;
|
||||||
if (!provider.providerName) {
|
if (!provider.providerName) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user