mirror of
https://github.com/MichMich/MagicMirror.git
synced 2025-06-27 19:53:36 +00:00
fixed darksky metric units
This commit is contained in:
parent
8a65bef004
commit
cc274ffebe
@ -16,10 +16,10 @@ WeatherProvider.register("darksky", {
|
|||||||
|
|
||||||
units: {
|
units: {
|
||||||
imperial: 'us',
|
imperial: 'us',
|
||||||
metric: 'ca'
|
metric: 'si'
|
||||||
},
|
},
|
||||||
|
|
||||||
fetchCurrentWeather: function() {
|
fetchCurrentWeather() {
|
||||||
this.fetchData(this.getUrl())
|
this.fetchData(this.getUrl())
|
||||||
.then(data => {
|
.then(data => {
|
||||||
if(!data || !data.currently || typeof data.currently.temperature === "undefined") {
|
if(!data || !data.currently || typeof data.currently.temperature === "undefined") {
|
||||||
@ -27,14 +27,14 @@ WeatherProvider.register("darksky", {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
var currentWeather = this.generateWeatherDayFromCurrentWeather(data);
|
const currentWeather = this.generateWeatherDayFromCurrentWeather(data);
|
||||||
this.setCurrentWeather(currentWeather);
|
this.setCurrentWeather(currentWeather);
|
||||||
}).catch(function(request) {
|
}).catch(function(request) {
|
||||||
Log.error("Could not load data ... ", request);
|
Log.error("Could not load data ... ", request);
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
|
|
||||||
fetchWeatherForecast: function() {
|
fetchWeatherForecast() {
|
||||||
this.fetchData(this.getUrl())
|
this.fetchData(this.getUrl())
|
||||||
.then(data => {
|
.then(data => {
|
||||||
if(!data || !data.daily || !data.daily.data.length) {
|
if(!data || !data.daily || !data.daily.data.length) {
|
||||||
@ -42,7 +42,7 @@ WeatherProvider.register("darksky", {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
var forecast = this.generateWeatherObjectsFromForecast(data.daily.data);
|
const forecast = this.generateWeatherObjectsFromForecast(data.daily.data);
|
||||||
this.setWeatherForecast(forecast);
|
this.setWeatherForecast(forecast);
|
||||||
}).catch(function(request) {
|
}).catch(function(request) {
|
||||||
Log.error("Could not load data ... ", request);
|
Log.error("Could not load data ... ", request);
|
||||||
@ -50,14 +50,14 @@ WeatherProvider.register("darksky", {
|
|||||||
},
|
},
|
||||||
|
|
||||||
// Create a URL from the config and base URL.
|
// Create a URL from the config and base URL.
|
||||||
getUrl: function() {
|
getUrl() {
|
||||||
var units = this.units[this.config.units] || 'auto';
|
const units = this.units[this.config.units] || "auto";
|
||||||
return `${this.config.apiBase}${this.config.weatherEndpoint}/${this.config.apiKey}/${this.config.lat},${this.config.lon}?units=${units}&lang=${this.config.lang}`;
|
return `${this.config.apiBase}${this.config.weatherEndpoint}/${this.config.apiKey}/${this.config.lat},${this.config.lon}?units=${units}&lang=${this.config.lang}`;
|
||||||
},
|
},
|
||||||
|
|
||||||
// Implement WeatherDay generator.
|
// Implement WeatherDay generator.
|
||||||
generateWeatherDayFromCurrentWeather: function(currentWeatherData) {
|
generateWeatherDayFromCurrentWeather(currentWeatherData) {
|
||||||
var currentWeather = new WeatherObject();
|
const currentWeather = new WeatherObject(this.config.units);
|
||||||
|
|
||||||
currentWeather.date = moment();
|
currentWeather.date = moment();
|
||||||
currentWeather.humidity = parseFloat(currentWeatherData.currently.humidity);
|
currentWeather.humidity = parseFloat(currentWeatherData.currently.humidity);
|
||||||
@ -71,11 +71,11 @@ WeatherProvider.register("darksky", {
|
|||||||
return currentWeather;
|
return currentWeather;
|
||||||
},
|
},
|
||||||
|
|
||||||
generateWeatherObjectsFromForecast: function(forecasts) {
|
generateWeatherObjectsFromForecast(forecasts) {
|
||||||
var days = [];
|
const days = [];
|
||||||
|
|
||||||
for (var forecast of forecasts) {
|
for (const forecast of forecasts) {
|
||||||
var weather = new WeatherObject();
|
const weather = new WeatherObject(this.config.units);
|
||||||
|
|
||||||
weather.date = moment(forecast.time, "X");
|
weather.date = moment(forecast.time, "X");
|
||||||
weather.minTemperature = forecast.temperatureMin;
|
weather.minTemperature = forecast.temperatureMin;
|
||||||
@ -83,15 +83,15 @@ WeatherProvider.register("darksky", {
|
|||||||
weather.weatherType = this.convertWeatherType(forecast.icon);
|
weather.weatherType = this.convertWeatherType(forecast.icon);
|
||||||
weather.rain = forecast.precipAccumulation;
|
weather.rain = forecast.precipAccumulation;
|
||||||
|
|
||||||
days.push(weather)
|
days.push(weather);
|
||||||
}
|
}
|
||||||
|
|
||||||
return days
|
return days;
|
||||||
},
|
},
|
||||||
|
|
||||||
// Map icons from Dark Sky to our icons.
|
// Map icons from Dark Sky to our icons.
|
||||||
convertWeatherType: function(weatherType) {
|
convertWeatherType(weatherType) {
|
||||||
var weatherTypes = {
|
const weatherTypes = {
|
||||||
"clear-day": "day-sunny",
|
"clear-day": "day-sunny",
|
||||||
"clear-night": "night-clear",
|
"clear-night": "night-clear",
|
||||||
"rain": "rain",
|
"rain": "rain",
|
||||||
@ -103,6 +103,7 @@ WeatherProvider.register("darksky", {
|
|||||||
"partly-cloudy-day": "day-cloudy",
|
"partly-cloudy-day": "day-cloudy",
|
||||||
"partly-cloudy-night": "night-cloudy"
|
"partly-cloudy-night": "night-cloudy"
|
||||||
};
|
};
|
||||||
|
|
||||||
return weatherTypes.hasOwnProperty(weatherType) ? weatherTypes[weatherType] : null;
|
return weatherTypes.hasOwnProperty(weatherType) ? weatherTypes[weatherType] : null;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
Loading…
x
Reference in New Issue
Block a user