mirror of
https://github.com/MichMich/MagicMirror.git
synced 2025-06-27 11:50:00 +00:00
## [2.22.0] - 2023-01-01 Thanks to: @angeldeejay, @buxxi, @dariom, @dWoolridge, @KristjanESPERANTO, @MagMar94, @naveensrinivasan, @retroflex, @SkySails and @Tom. Special thanks to @khassel, @rejas and @sdetweil for taking over most (if not all) of the work on this release as project collaborators. This version would not be there without their effort. Thank you! ### Added - Added test for remoteFile option in compliments module - Added hourlyWeather functionality to Weather.gov weather provider - Removed weatherEndpoint definition from weathergov.js (not used) - Added css class names "today" and "tomorrow" for default calendar - Added Collaboration.md - Added new github action for dependency review (#2862) - Added a WeatherProvider for Open-Meteo - Added Yr as a weather provider - Added config options "ignoreXOriginHeader" and "ignoreContentSecurityPolicy" ### Removed - Removed usage of internal fetch function of node until it is more stable ### Updated - Cleaned up test directory (#2937) and jest config (#2959) - Wait for all modules to start before declaring the system ready (#2487) - Updated e2e tests (moved `done()` in helper functions) and use es6 syntax in all tests - Updated da translation - Rework weather module - Make sure smhi provider api only gets a maximum of 6 digits coordinates (#2955) - Use fetch instead of XMLHttpRequest in weatherprovider (#2935) - Reworked how weatherproviders handle units (#2849) - Use unix() method for parsing times, fix suntimes on the way (#2950) - Refactor conversion functions into utils class (#2958) - The `cors`-method in `server.js` now supports sending and recieving HTTP headers - Replace `…` by `…` - Cleanup compliments module - Updated dependencies including electron to v22 (#2903) ### Fixed - Correctly show apparent temperature in SMHI weather provider - Ensure updatenotification module isn't shown when local is _ahead_ of remote - Handle node_helper errors during startup (#2944) - Possibility to change FontAwesome class in calendar, so icons like `fab fa-facebook-square` works. - Fix cors problems with newsfeed articles (as far as possible), allow disabling cors per feed with option `useCorsProxy: false` (#2840) - Tests not waiting for the application to start and stop before starting the next test - Fix electron tests failing sometimes in github workflow - Fixed gap in clock module when displayed on the left side with displayType=digital - Fixed playwright issue by upgrading to v1.29.1 (#2969) Signed-off-by: naveen <172697+naveensrinivasan@users.noreply.github.com> Co-authored-by: Karsten Hassel <hassel@gmx.de> Co-authored-by: Malte Hallström <46646495+SkySails@users.noreply.github.com> Co-authored-by: Veeck <github@veeck.de> Co-authored-by: veeck <michael@veeck.de> Co-authored-by: dWoolridge <dwoolridge@charter.net> Co-authored-by: Johan <jojjepersson@yahoo.se> Co-authored-by: Dario Mratovich <dario_mratovich@hotmail.com> Co-authored-by: Dario Mratovich <dario.mratovich@outlook.com> Co-authored-by: Magnus <34011212+MagMar94@users.noreply.github.com> Co-authored-by: Naveen <172697+naveensrinivasan@users.noreply.github.com> Co-authored-by: buxxi <buxxi@omfilm.net> Co-authored-by: Thomas Hirschberger <47733292+Tom-Hirschberger@users.noreply.github.com> Co-authored-by: Kristjan ESPERANTO <35647502+KristjanESPERANTO@users.noreply.github.com> Co-authored-by: Andrés Vanegas Jiménez <142350+angeldeejay@users.noreply.github.com>
172 lines
5.7 KiB
JavaScript
172 lines
5.7 KiB
JavaScript
/* global Class, performWebRequest */
|
|
|
|
/* MagicMirror²
|
|
* Module: Weather
|
|
*
|
|
* By Michael Teeuw https://michaelteeuw.nl
|
|
* MIT Licensed.
|
|
*
|
|
* This class is the blueprint for a weather provider.
|
|
*/
|
|
const WeatherProvider = Class.extend({
|
|
// Weather Provider Properties
|
|
providerName: null,
|
|
defaults: {},
|
|
|
|
// The following properties have accessor methods.
|
|
// Try to not access them directly.
|
|
currentWeatherObject: null,
|
|
weatherForecastArray: null,
|
|
weatherHourlyArray: null,
|
|
fetchedLocationName: null,
|
|
|
|
// The following properties will be set automatically.
|
|
// You do not need to overwrite these properties.
|
|
config: null,
|
|
delegate: null,
|
|
providerIdentifier: null,
|
|
|
|
// Weather Provider Methods
|
|
// All the following methods can be overwritten, although most are good as they are.
|
|
|
|
// Called when a weather provider is initialized.
|
|
init: function (config) {
|
|
this.config = config;
|
|
Log.info(`Weather provider: ${this.providerName} initialized.`);
|
|
},
|
|
|
|
// Called to set the config, this config is the same as the weather module's config.
|
|
setConfig: function (config) {
|
|
this.config = config;
|
|
Log.info(`Weather provider: ${this.providerName} config set.`, this.config);
|
|
},
|
|
|
|
// Called when the weather provider is about to start.
|
|
start: function () {
|
|
Log.info(`Weather provider: ${this.providerName} started.`);
|
|
},
|
|
|
|
// This method should start the API request to fetch the current weather.
|
|
// This method should definitely be overwritten in the provider.
|
|
fetchCurrentWeather: function () {
|
|
Log.warn(`Weather provider: ${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: function () {
|
|
Log.warn(`Weather provider: ${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: function () {
|
|
Log.warn(`Weather provider: ${this.providerName} does not subclass the fetchWeatherHourly method.`);
|
|
},
|
|
|
|
// This returns a WeatherDay object for the current weather.
|
|
currentWeather: function () {
|
|
return this.currentWeatherObject;
|
|
},
|
|
|
|
// This returns an array of WeatherDay objects for the weather forecast.
|
|
weatherForecast: function () {
|
|
return this.weatherForecastArray;
|
|
},
|
|
|
|
// This returns an object containing WeatherDay object(s) depending on the type of call.
|
|
weatherHourly: function () {
|
|
return this.weatherHourlyArray;
|
|
},
|
|
|
|
// This returns the name of the fetched location or an empty string.
|
|
fetchedLocation: function () {
|
|
return this.fetchedLocationName || "";
|
|
},
|
|
|
|
// Set the currentWeather and notify the delegate that new information is available.
|
|
setCurrentWeather: function (currentWeatherObject) {
|
|
// We should check here if we are passing a WeatherDay
|
|
this.currentWeatherObject = currentWeatherObject;
|
|
},
|
|
|
|
// Set the weatherForecastArray and notify the delegate that new information is available.
|
|
setWeatherForecast: function (weatherForecastArray) {
|
|
// We should check here if we are passing a WeatherDay
|
|
this.weatherForecastArray = weatherForecastArray;
|
|
},
|
|
|
|
// Set the weatherHourlyArray and notify the delegate that new information is available.
|
|
setWeatherHourly: function (weatherHourlyArray) {
|
|
this.weatherHourlyArray = weatherHourlyArray;
|
|
},
|
|
|
|
// Set the fetched location name.
|
|
setFetchedLocation: function (name) {
|
|
this.fetchedLocationName = name;
|
|
},
|
|
|
|
// Notify the delegate that new weather is available.
|
|
updateAvailable: function () {
|
|
this.delegate.updateAvailable(this);
|
|
},
|
|
|
|
/**
|
|
* A convenience function to make requests.
|
|
*
|
|
* @param {string} url the url to fetch from
|
|
* @param {string} type what contenttype to expect in the response, can be "json" or "xml"
|
|
* @param {Array.<{name: string, value:string}>} requestHeaders the HTTP headers to send
|
|
* @param {Array.<string>} expectedResponseHeaders the expected HTTP headers to recieve
|
|
* @returns {Promise} resolved when the fetch is done
|
|
*/
|
|
fetchData: async function (url, type = "json", requestHeaders = undefined, expectedResponseHeaders = undefined) {
|
|
const mockData = this.config.mockData;
|
|
if (mockData) {
|
|
const data = mockData.substring(1, mockData.length - 1);
|
|
return JSON.parse(data);
|
|
}
|
|
const useCorsProxy = typeof this.config.useCorsProxy !== "undefined" && this.config.useCorsProxy;
|
|
return performWebRequest(url, type, useCorsProxy, requestHeaders, expectedResponseHeaders);
|
|
}
|
|
});
|
|
|
|
/**
|
|
* Collection of registered weather providers.
|
|
*/
|
|
WeatherProvider.providers = [];
|
|
|
|
/**
|
|
* Static method to register a new weather provider.
|
|
*
|
|
* @param {string} providerIdentifier The name of the weather provider
|
|
* @param {object} providerDetails The details of the weather provider
|
|
*/
|
|
WeatherProvider.register = function (providerIdentifier, providerDetails) {
|
|
WeatherProvider.providers[providerIdentifier.toLowerCase()] = WeatherProvider.extend(providerDetails);
|
|
};
|
|
|
|
/**
|
|
* Static method to initialize a new weather provider.
|
|
*
|
|
* @param {string} providerIdentifier The name of the weather provider
|
|
* @param {object} delegate The weather module
|
|
* @returns {object} The new weather provider
|
|
*/
|
|
WeatherProvider.initialize = function (providerIdentifier, delegate) {
|
|
providerIdentifier = providerIdentifier.toLowerCase();
|
|
|
|
const provider = new WeatherProvider.providers[providerIdentifier]();
|
|
const config = Object.assign({}, provider.defaults, delegate.config);
|
|
|
|
provider.delegate = delegate;
|
|
provider.setConfig(config);
|
|
|
|
provider.providerIdentifier = providerIdentifier;
|
|
if (!provider.providerName) {
|
|
provider.providerName = providerIdentifier;
|
|
}
|
|
|
|
return provider;
|
|
};
|