From 7f2e643e6249f8e91be1bfc7e8edfa66b4ed385f Mon Sep 17 00:00:00 2001 From: Nicholas Hubbard Date: Thu, 21 Sep 2017 20:06:42 -0400 Subject: [PATCH 1/4] Add Dark Sky Module --- modules/default/weather/providers/darksky.js | 61 ++++++++++++++++++++ 1 file changed, 61 insertions(+) create mode 100644 modules/default/weather/providers/darksky.js diff --git a/modules/default/weather/providers/darksky.js b/modules/default/weather/providers/darksky.js new file mode 100644 index 00000000..43a87fd1 --- /dev/null +++ b/modules/default/weather/providers/darksky.js @@ -0,0 +1,61 @@ +/* global WeatherProvider, WeatherDay */ + +/* Magic Mirror + * Module: Weather + * Provider: Dark Sky + * + * By Nicholas Hubbard https://github.com/nhubbard + * MIT Licensed + * + * This class is a provider for Dark Sky. + */ +WeatherProvider.register("darksky", { + // Set the name of the provider. + // Not strictly required, but helps for debugging. + providerName: "Dark Sky", + // Implement fetchCurrentWeather. + fetchCurrentWeather: function() { + // Create a URL from the config and base URL. + var url = `https://api.darksky.net/forecast/${this.config.apiKey}/${this.config.latLong}`; + // Run the request. + this.fetchData(url).then(data => { + Log.log(data); + if(!data || !data.main || typeof data.main.temp === "undefined") { + // No usable data? + return; + } + var currentWeather = this.generateWeatherDayFromCurrentWeather(data); + this.setCurrentWeather(currentWeather); + }).catch(function(request) { + Log.error("Could not load data!", request); + }); + }, + // Implement WeatherDay generator. + generateWeatherDayFromCurrentWeather: function(currentWeatherData) { + var currentWeather = new WeatherDay(); + currentWeather.humidity = parseFloat(currentWeatherData.currently.humidity); + currentWeather.temperature = parseFloat(currentWeatherData.currently.temperature); + currentWeather.windSpeed = parseFloat(currentWeatherData.currently.windSpeed); + currentWeather.windDirection = currentWeatherData.currently.windBearing; + currentWeather.weatherType = this.currentWeatherType(currentWeatherData.currently.icon); + currentWeather.sunrise = new Date(currentWeatherData.daily.data[0].sunriseTime); + currentWeather.sunset = new Date(currentWeatherData.daily.data[0].sunsetTime); + return currentWeather; + }, + // Map icons from Dark Sky to our icons. + convertWeatherType: function(weatherType) { + var weatherTypes = { + "clear-day": "day-sunny", + "clear-night": "night-clear", + "rain": "rain", + "snow": "snow", + "sleet": "snow", + "wind": "wind", + "fog": "fog", + "cloudy": "cloudy", + "partly-cloudy-day": "day-cloudy", + "partly-cloudy-night": "night-cloudy" + }; + return weatherTypes.hasOwnProperty(weatherType) ? weatherTypes[weatherType] : null; + } +}); \ No newline at end of file From 2bf18d8bdab364636b2589a981c7e7fb395bc669 Mon Sep 17 00:00:00 2001 From: Nicholas Hubbard Date: Thu, 21 Sep 2017 20:12:25 -0400 Subject: [PATCH 2/4] Fix Indentation? --- js/class.js | 24 +++++++++---------- .../updatenotification/updatenotification.js | 4 +--- tests/configs/check_config.js | 2 +- 3 files changed, 14 insertions(+), 16 deletions(-) diff --git a/js/class.js b/js/class.js index 3c44250e..d054a73e 100644 --- a/js/class.js +++ b/js/class.js @@ -31,22 +31,22 @@ // Check if we're overwriting an existing function prototype[name] = typeof prop[name] == "function" && typeof _super[name] == "function" && fnTest.test(prop[name]) ? (function(name, fn) { - return function() { - var tmp = this._super; + return function() { + var tmp = this._super; - // Add a new ._super() method that is the same method - // but on the super-class - this._super = _super[name]; + // Add a new ._super() method that is the same method + // but on the super-class + this._super = _super[name]; - // The method only need to be bound temporarily, so we - // remove it when we're done executing - var ret = fn.apply(this, arguments); - this._super = tmp; + // The method only need to be bound temporarily, so we + // remove it when we're done executing + var ret = fn.apply(this, arguments); + this._super = tmp; - return ret; - }; - })(name, prop[name]) : prop[name]; + return ret; + }; + })(name, prop[name]) : prop[name]; } // The dummy class constructor diff --git a/modules/default/updatenotification/updatenotification.js b/modules/default/updatenotification/updatenotification.js index f663f593..9772f06b 100644 --- a/modules/default/updatenotification/updatenotification.js +++ b/modules/default/updatenotification/updatenotification.js @@ -58,9 +58,7 @@ Module.register("updatenotification", { wrapper.appendChild(message); var subtext = document.createElement("div"); - subtext.innerHTML = this.translate("UPDATE_INFO") - .replace("COMMIT_COUNT", this.status.behind + " " + ((this.status.behind == 1)? "commit" : "commits")) - .replace("BRANCH_NAME", this.status.current); + subtext.innerHTML = this.translate("UPDATE_INFO").replace("COMMIT_COUNT", this.status.behind + " " + ((this.status.behind == 1)? "commit" : "commits")).replace("BRANCH_NAME", this.status.current); subtext.className = "xsmall dimmed"; wrapper.appendChild(subtext); } diff --git a/tests/configs/check_config.js b/tests/configs/check_config.js index fa294761..85cc6a48 100644 --- a/tests/configs/check_config.js +++ b/tests/configs/check_config.js @@ -48,7 +48,7 @@ try { // In case the there errors show messages and // return console.info(Utils.colors.info("Checking file... ", configFileName)); - // I'm not sure if all ever is utf-8 +// I'm not sure if all ever is utf-8 fs.readFile(configFileName, "utf-8", function(err, data) { if (err) {throw err;} v.JSHINT(data); // Parser by jshint From 837e275bfd238b10433731454280d414cce78218 Mon Sep 17 00:00:00 2001 From: Nicholas Hubbard Date: Fri, 29 Sep 2017 10:11:46 -0400 Subject: [PATCH 3/4] Update fork --- modules/default/weather/providers/darksky.js | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/modules/default/weather/providers/darksky.js b/modules/default/weather/providers/darksky.js index 43a87fd1..3164d7c8 100644 --- a/modules/default/weather/providers/darksky.js +++ b/modules/default/weather/providers/darksky.js @@ -30,9 +30,23 @@ WeatherProvider.register("darksky", { Log.error("Could not load data!", request); }); }, + fetchWeatherForecast: function() { + // Also, fake data. + var forecast = []; + var today = moment(); + for(var i = 0; i < 5; i++) { + var weatherObject = new WeatherObject(); + weatherObject.date = moment(today).add(i, "days"); + weatherObject.minTemperature = Math.random() * 10 + 10; + weatherObject.maxTemperature = Math.random() * 15 + 10; + forecast.push(weatherObject); + } + this.setWeatherForecast(); + }, // Implement WeatherDay generator. generateWeatherDayFromCurrentWeather: function(currentWeatherData) { - var currentWeather = new WeatherDay(); + var currentWeather = new WeatherObject(); + currentWeather.date = new Date(); currentWeather.humidity = parseFloat(currentWeatherData.currently.humidity); currentWeather.temperature = parseFloat(currentWeatherData.currently.temperature); currentWeather.windSpeed = parseFloat(currentWeatherData.currently.windSpeed); From cd129fb05527b09f64ec8ffabc61314529906979 Mon Sep 17 00:00:00 2001 From: Nicholas Hubbard Date: Sat, 30 Sep 2017 19:44:54 -0400 Subject: [PATCH 4/4] Revert "Fix Indentation?" This reverts commit 2bf18d8bdab364636b2589a981c7e7fb395bc669. --- js/class.js | 24 +++++++++---------- .../updatenotification/updatenotification.js | 4 +++- tests/configs/check_config.js | 2 +- 3 files changed, 16 insertions(+), 14 deletions(-) diff --git a/js/class.js b/js/class.js index d054a73e..3c44250e 100644 --- a/js/class.js +++ b/js/class.js @@ -31,22 +31,22 @@ // Check if we're overwriting an existing function prototype[name] = typeof prop[name] == "function" && typeof _super[name] == "function" && fnTest.test(prop[name]) ? (function(name, fn) { - return function() { - var tmp = this._super; + return function() { + var tmp = this._super; - // Add a new ._super() method that is the same method - // but on the super-class - this._super = _super[name]; + // Add a new ._super() method that is the same method + // but on the super-class + this._super = _super[name]; - // The method only need to be bound temporarily, so we - // remove it when we're done executing - var ret = fn.apply(this, arguments); - this._super = tmp; + // The method only need to be bound temporarily, so we + // remove it when we're done executing + var ret = fn.apply(this, arguments); + this._super = tmp; - return ret; - }; - })(name, prop[name]) : prop[name]; + return ret; + }; + })(name, prop[name]) : prop[name]; } // The dummy class constructor diff --git a/modules/default/updatenotification/updatenotification.js b/modules/default/updatenotification/updatenotification.js index 9772f06b..f663f593 100644 --- a/modules/default/updatenotification/updatenotification.js +++ b/modules/default/updatenotification/updatenotification.js @@ -58,7 +58,9 @@ Module.register("updatenotification", { wrapper.appendChild(message); var subtext = document.createElement("div"); - subtext.innerHTML = this.translate("UPDATE_INFO").replace("COMMIT_COUNT", this.status.behind + " " + ((this.status.behind == 1)? "commit" : "commits")).replace("BRANCH_NAME", this.status.current); + subtext.innerHTML = this.translate("UPDATE_INFO") + .replace("COMMIT_COUNT", this.status.behind + " " + ((this.status.behind == 1)? "commit" : "commits")) + .replace("BRANCH_NAME", this.status.current); subtext.className = "xsmall dimmed"; wrapper.appendChild(subtext); } diff --git a/tests/configs/check_config.js b/tests/configs/check_config.js index 85cc6a48..fa294761 100644 --- a/tests/configs/check_config.js +++ b/tests/configs/check_config.js @@ -48,7 +48,7 @@ try { // In case the there errors show messages and // return console.info(Utils.colors.info("Checking file... ", configFileName)); -// I'm not sure if all ever is utf-8 + // I'm not sure if all ever is utf-8 fs.readFile(configFileName, "utf-8", function(err, data) { if (err) {throw err;} v.JSHINT(data); // Parser by jshint