add unit and language handling for weather provider darksky

This commit is contained in:
fewieden 2018-12-28 19:39:00 +01:00
parent b94dc5044b
commit 8a65bef004

View File

@ -14,6 +14,11 @@ WeatherProvider.register("darksky", {
// Not strictly required, but helps for debugging.
providerName: "Dark Sky",
units: {
imperial: 'us',
metric: 'ca'
},
fetchCurrentWeather: function() {
this.fetchData(this.getUrl())
.then(data => {
@ -46,7 +51,8 @@ WeatherProvider.register("darksky", {
// Create a URL from the config and base URL.
getUrl: function() {
return `${this.config.apiBase}${this.config.weatherEndpoint}/${this.config.apiKey}/${this.config.lat},${this.config.lon}`;
var 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}`;
},
// Implement WeatherDay generator.