mirror of
https://github.com/MichMich/MagicMirror.git
synced 2025-07-04 22:58:03 +00:00
Added autoLocation option for weather modules.
This commit is contained in:
parent
44896db668
commit
5ca3fbeaea
@ -15,6 +15,7 @@ This project adheres to [Semantic Versioning](http://semver.org/).
|
||||
- Italian translation for "Feels"
|
||||
- Disabled the screensaver on raspbian with installation script
|
||||
- Added option to truncate the number of vertical lines a calendar item can span if `wrapEvents` is enabled.
|
||||
- Added autoLocation options for weather forcast and current weather modules.
|
||||
|
||||
### Updated
|
||||
- Bumped the Electron dependency to v3.0.13 to support the most recent Raspbian. [#1500](https://github.com/MichMich/MagicMirror/issues/1500)
|
||||
|
@ -11,6 +11,7 @@ Module.register("currentweather",{
|
||||
|
||||
// Default module config.
|
||||
defaults: {
|
||||
autoLocation: false,
|
||||
location: false,
|
||||
locationID: false,
|
||||
appid: "",
|
||||
@ -109,8 +110,19 @@ Module.register("currentweather",{
|
||||
this.weatherType = null;
|
||||
this.feelsLike = null;
|
||||
this.loaded = false;
|
||||
this.scheduleUpdate(this.config.initialLoadDelay);
|
||||
|
||||
if (this.config.autoLocation) {
|
||||
this.sendSocketNotification("AUTO_LOCATION");
|
||||
} else {
|
||||
this.scheduleUpdate(this.config.initialLoadDelay);
|
||||
}
|
||||
},
|
||||
|
||||
socketNotificationReceived: function (notification, payload) {
|
||||
if (notification === "UPDATE_LOCATION") {
|
||||
this.config.location = payload.location;
|
||||
this.scheduleUpdate(this.config.initialLoadDelay);
|
||||
}
|
||||
},
|
||||
|
||||
// add extra information of current weather
|
||||
|
29
modules/default/currentweather/node_helper.js
Normal file
29
modules/default/currentweather/node_helper.js
Normal file
@ -0,0 +1,29 @@
|
||||
var http = require("http");
|
||||
var NodeHelper = require("node_helper");
|
||||
|
||||
module.exports = NodeHelper.create({
|
||||
start: function () {
|
||||
},
|
||||
|
||||
socketNotificationReceived: function (notification, payload) {
|
||||
var self = this;
|
||||
|
||||
if (notification === "AUTO_LOCATION") {
|
||||
console.log("Loading timezone...");
|
||||
http.get("http://ip-api.com/json", function (req) {
|
||||
var data = "";
|
||||
req.on("data", function (d) {
|
||||
data += d;
|
||||
});
|
||||
req.on("end", function () {
|
||||
var body = JSON.parse(data);
|
||||
payload.location = body.city + ", " + body.regionName;
|
||||
self.sendSocketNotification("UPDATE_LOCATION", payload);
|
||||
});
|
||||
}).on("error", function () {
|
||||
payload.error = "Could not figure out the timezone.";
|
||||
self.sendSocketNotification("UPDATE_LOCATION", payload);
|
||||
});
|
||||
}
|
||||
}
|
||||
});
|
29
modules/default/weatherforecast/node_helper.js
Normal file
29
modules/default/weatherforecast/node_helper.js
Normal file
@ -0,0 +1,29 @@
|
||||
var http = require("http");
|
||||
var NodeHelper = require("node_helper");
|
||||
|
||||
module.exports = NodeHelper.create({
|
||||
start: function () {
|
||||
},
|
||||
|
||||
socketNotificationReceived: function (notification, payload) {
|
||||
var self = this;
|
||||
|
||||
if (notification === "AUTO_LOCATION") {
|
||||
console.log("Loading timezone...");
|
||||
http.get("http://ip-api.com/json", function (req) {
|
||||
var data = "";
|
||||
req.on("data", function (d) {
|
||||
data += d;
|
||||
});
|
||||
req.on("end", function () {
|
||||
var body = JSON.parse(data);
|
||||
payload.location = body.city + ", " + body.regionName;
|
||||
self.sendSocketNotification("UPDATE_LOCATION", payload);
|
||||
});
|
||||
}).on("error", function () {
|
||||
payload.error = "Could not figure out the timezone.";
|
||||
self.sendSocketNotification("UPDATE_LOCATION", payload);
|
||||
});
|
||||
}
|
||||
}
|
||||
});
|
@ -11,6 +11,7 @@ Module.register("weatherforecast",{
|
||||
|
||||
// Default module config.
|
||||
defaults: {
|
||||
autoLocation: false,
|
||||
location: false,
|
||||
locationID: false,
|
||||
appid: "",
|
||||
@ -95,10 +96,20 @@ Module.register("weatherforecast",{
|
||||
|
||||
this.forecast = [];
|
||||
this.loaded = false;
|
||||
this.scheduleUpdate(this.config.initialLoadDelay);
|
||||
|
||||
this.updateTimer = null;
|
||||
|
||||
if (this.config.autoLocation) {
|
||||
this.sendSocketNotification("AUTO_LOCATION");
|
||||
} else {
|
||||
this.scheduleUpdate(this.config.initialLoadDelay);
|
||||
}
|
||||
},
|
||||
|
||||
socketNotificationReceived: function (notification, payload) {
|
||||
if (notification === "UPDATE_LOCATION") {
|
||||
this.config.location = payload.location;
|
||||
this.scheduleUpdate(this.config.initialLoadDelay);
|
||||
}
|
||||
},
|
||||
|
||||
// Override dom generator.
|
||||
|
Loading…
x
Reference in New Issue
Block a user