Merge pull request #2036 from DarthBrento/develop

Fix #1109 - multiple calendar instances with different config
This commit is contained in:
Michael Teeuw 2020-06-02 10:16:09 +02:00 committed by GitHub
commit 3b32605b5e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 14 additions and 6 deletions

View File

@ -35,6 +35,7 @@ _This release is scheduled to be released on 2020-07-01._
- The broken modules due to Socket.io change from last release [#1973](https://github.com/MichMich/MagicMirror/issues/1973) - The broken modules due to Socket.io change from last release [#1973](https://github.com/MichMich/MagicMirror/issues/1973)
- Add backward compatibility for old module code in socketclient.js [#1973](https://github.com/MichMich/MagicMirror/issues/1973) - Add backward compatibility for old module code in socketclient.js [#1973](https://github.com/MichMich/MagicMirror/issues/1973)
- Support multiple instances of calendar module with different config [#1109](https://github.com/MichMich/MagicMirror/issues/1109)
- Fix the use of "maxNumberOfDays" in the module "weatherforecast" [#2018](https://github.com/MichMich/MagicMirror/issues/2018) - Fix the use of "maxNumberOfDays" in the module "weatherforecast" [#2018](https://github.com/MichMich/MagicMirror/issues/2018)
## [2.11.0] - 2020-04-01 ## [2.11.0] - 2020-04-01

View File

@ -128,6 +128,10 @@ Module.register("calendar", {
// Override socket notification handler. // Override socket notification handler.
socketNotificationReceived: function (notification, payload) { socketNotificationReceived: function (notification, payload) {
if (this.identifier !== payload.id) {
return;
}
if (notification === "CALENDAR_EVENTS") { if (notification === "CALENDAR_EVENTS") {
if (this.hasCalendarURL(payload.url)) { if (this.hasCalendarURL(payload.url)) {
this.calendarData[payload.url] = payload.events; this.calendarData[payload.url] = payload.events;
@ -541,6 +545,7 @@ Module.register("calendar", {
*/ */
addCalendar: function (url, auth, calendarConfig) { addCalendar: function (url, auth, calendarConfig) {
this.sendSocketNotification("ADD_CALENDAR", { this.sendSocketNotification("ADD_CALENDAR", {
id: this.identifier,
url: url, url: url,
excludedEvents: calendarConfig.excludedEvents || this.config.excludedEvents, excludedEvents: calendarConfig.excludedEvents || this.config.excludedEvents,
maximumEntries: calendarConfig.maximumEntries || this.config.maximumEntries, maximumEntries: calendarConfig.maximumEntries || this.config.maximumEntries,

View File

@ -23,7 +23,7 @@ module.exports = NodeHelper.create({
socketNotificationReceived: function (notification, payload) { socketNotificationReceived: function (notification, payload) {
if (notification === "ADD_CALENDAR") { if (notification === "ADD_CALENDAR") {
//console.log('ADD_CALENDAR: '); //console.log('ADD_CALENDAR: ');
this.createFetcher(payload.url, payload.fetchInterval, payload.excludedEvents, payload.maximumEntries, payload.maximumNumberOfDays, payload.auth, payload.broadcastPastEvents); this.createFetcher(payload.url, payload.fetchInterval, payload.excludedEvents, payload.maximumEntries, payload.maximumNumberOfDays, payload.auth, payload.broadcastPastEvents, payload.id);
} }
}, },
@ -35,16 +35,16 @@ module.exports = NodeHelper.create({
* attribute reloadInterval number - Reload interval in milliseconds. * attribute reloadInterval number - Reload interval in milliseconds.
*/ */
createFetcher: function (url, fetchInterval, excludedEvents, maximumEntries, maximumNumberOfDays, auth, broadcastPastEvents) { createFetcher: function (url, fetchInterval, excludedEvents, maximumEntries, maximumNumberOfDays, auth, broadcastPastEvents, identifier) {
var self = this; var self = this;
if (!validUrl.isUri(url)) { if (!validUrl.isUri(url)) {
self.sendSocketNotification("INCORRECT_URL", { url: url }); self.sendSocketNotification("INCORRECT_URL", { id: identifier, url: url });
return; return;
} }
var fetcher; var fetcher;
if (typeof self.fetchers[url] === "undefined") { if (typeof self.fetchers[identifier + url] === "undefined") {
console.log("Create new calendar fetcher for url: " + url + " - Interval: " + fetchInterval); console.log("Create new calendar fetcher for url: " + url + " - Interval: " + fetchInterval);
fetcher = new CalendarFetcher(url, fetchInterval, excludedEvents, maximumEntries, maximumNumberOfDays, auth, broadcastPastEvents); fetcher = new CalendarFetcher(url, fetchInterval, excludedEvents, maximumEntries, maximumNumberOfDays, auth, broadcastPastEvents);
@ -53,6 +53,7 @@ module.exports = NodeHelper.create({
//console.log(fetcher.events()); //console.log(fetcher.events());
self.sendSocketNotification("CALENDAR_EVENTS", { self.sendSocketNotification("CALENDAR_EVENTS", {
id: identifier,
url: fetcher.url(), url: fetcher.url(),
events: fetcher.events() events: fetcher.events()
}); });
@ -61,15 +62,16 @@ module.exports = NodeHelper.create({
fetcher.onError(function (fetcher, error) { fetcher.onError(function (fetcher, error) {
console.error("Calendar Error. Could not fetch calendar: ", fetcher.url(), error); console.error("Calendar Error. Could not fetch calendar: ", fetcher.url(), error);
self.sendSocketNotification("FETCH_ERROR", { self.sendSocketNotification("FETCH_ERROR", {
id: identifier,
url: fetcher.url(), url: fetcher.url(),
error: error error: error
}); });
}); });
self.fetchers[url] = fetcher; self.fetchers[identifier + url] = fetcher;
} else { } else {
//console.log('Use existing news fetcher for url: ' + url); //console.log('Use existing news fetcher for url: ' + url);
fetcher = self.fetchers[url]; fetcher = self.fetchers[identifier + url];
fetcher.broadcastEvents(); fetcher.broadcastEvents();
} }