This document describes the way to develop your own MagicMirror² weather module weather provider.
Table of Contents:
- The weather provider file: yourprovider.js
This is the script in which the weather provider will be defined. In it's most simple form, the weather provider must implement the following:
WeatherProvider.register("yourprovider", {
providerName: "YourProvider",
fetchCurrentWeather() {},
fetchWeatherForecast() {}
});
This method is called when the weather module tries to fetch the current weather of your provider. The implementation of this method is required.
The implementation can make use of the already implemented function this.fetchData(url, method, data);
, which is returning a promise.
After the response is processed, the current weather information (as a WeatherObject) needs to be set with this.setCurrentWeather(currentWeather);
.
It will then automatically refresh the module DOM with the new data.
This method is called when the weather module tries to fetch the weather weather of your provider. The implementation of this method is required.
The implementation can make use of the already implemented function this.fetchData(url, method, data);
, which is returning a promise.
After the response is processed, the weather forecast information (as an array of WeatherObjects) needs to be set with this.setCurrentWeather(forecast);
.
It will then automatically refresh the module DOM with the new data.
Called when a weather provider is initialized.
Called to set the config, this config is the same as the weather module's config.
Called when the weather provider is about to start.
This returns a WeatherDay object for the current weather.
This returns an array of WeatherDay objects for the weather forecast.
This returns the name of the fetched location or an empty string.
Set the currentWeather and notify the delegate that new information is available.
Set the weatherForecastArray and notify the delegate that new information is available.
Set the fetched location name.
Notify the delegate that new weather is available.
A convenience function to make requests. It returns a promise.
Property | Type | Value/Unit |
---|---|---|
units | string |
Gets initialized with the constructor. Possible values: metric and imperial |
date | object |
Moment.js object of the time/date. |
windSpeed | number |
Metric: meter/second Imperial: miles/hour |
windDirection | number |
Direction of the wind in degrees. |
sunrise | object |
Moment.js object of sunrise. |
sunset | object |
Moment.js object of sunset. |
temperature | number |
Current temperature |
minTemperature | number |
Lowest temperature of the day. |
maxTemperature | number |
Highest temperature of the day. |
weatherType | string |
Icon name of the weather type. Possible values: WeatherIcons |
humidity | number |
Percentage of humidity |
rain | number |
Metric: millimeters Imperial: inches |
snow | number |
Metric: millimeters Imperial: inches |
precipitation | number |
Metric: millimeters Imperial: inches |
For the current weather object the following properties are required:
- humidity
- sunrise
- sunset
- temperature
- units
- weatherType
- windDirection
- windSpeed
For the forecast weather object the following properties are required:
- date
- maxTemperature
- minTemperature
- rain
- units
- weatherType