Skip to content

Commit

Permalink
Merge branch 'hotfix/issue-11-fiber-npm-dependancy' into release/1.0.4
Browse files Browse the repository at this point in the history
  • Loading branch information
LoneWanderer-GH committed Jul 3, 2020
2 parents 201524b + ebf879b commit 142d532
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 45 deletions.
24 changes: 11 additions & 13 deletions MMM-Toulouse-Transports.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,6 @@
}
*/

// var moment = require('moment');

Module.register( "MMM-Toulouse-Transports", {
defaults: {
maxTimeOffset: 200, // Max time in the future for entries
Expand Down Expand Up @@ -57,19 +55,19 @@ Module.register( "MMM-Toulouse-Transports", {
// only one call should be necessary for now
Log.info("start - Send notification UPDATE_GLOBAL_TISSEO_DATA");
this.sendSocketNotification( 'UPDATE_GLOBAL_TISSEO_DATA', null);

this.busScheduleData = [];
this.currentUpdateInterval = this.config.updateInterval

this.lastUpdate = new Date();

// test to avoid first request delayed of update interval
//this.log(TRACE, "start - lastUpdate " + this.lastUpdate);
//this.lastUpdate.setHours(this.lastUpdate.getHours() - 1)
//this.log(TRACE, "start - lastUpdate minus 01h00 " + this.lastUpdate);
//this.config.lastUpdate = this.lastUpdate
// end

this.loaded = false;
this.updateTimer = null;

Expand All @@ -88,7 +86,7 @@ Module.register( "MMM-Toulouse-Transports", {
if ( this.config.showSecondsToNextUpdate ) {
//var timeDifference = Math.round( ( this.config.updateInterval - new Date( ) + Date.parse( this.config.lastUpdate ) ) / 1000 );
var timeDifference = Math.round( ( this.currentUpdateInterval - new Date( ) + Date.parse( this.config.lastUpdate ) ) / 1000 );

if ( timeDifference > 0 ) {
header += ', next update in ' + timeDifference + 's';
} else {
Expand All @@ -109,8 +107,8 @@ Module.register( "MMM-Toulouse-Transports", {
//Log.info("End getStyles (before return statement)");
return ['font-awesome.css'];
},


getDom: function ( ) {
Log.info("getDom - Start");
var now = new Date(); // moment(); // moment package cannot be invoked in here ... only in nodehelper ?! not very handy
Expand Down Expand Up @@ -165,11 +163,11 @@ Module.register( "MMM-Toulouse-Transports", {
var data = currentDataToDisplay.scheduleData;
rgbString = data.departure[0].line.color;
var lineColor = 'rgb'+rgbString

var stopName = data.stop.name;
var stopCode = data.stop.operatorCode;


// put line N°
lineIdCell.innerHTML += '<i class="fa fa-bus bright" style="color:'+lineColor+'"></i>' // put icon
lineIdCell.innerHTML += lineNumber;
Expand Down Expand Up @@ -276,17 +274,17 @@ Module.register( "MMM-Toulouse-Transports", {
Log.info("computeWaitingTime - end - waitingTime="+waitingTime);
return waitingTime;
},

socketNotificationReceived: function ( notification, payload ) {
Log.info("socketNotificationReceived - Module received notification: " + notification);
switch ( notification ) {
case "JOURNEYS":
case "JOURNEYS":
break;
case "BUS_SCHEDULES":
this.busScheduleData = payload.data;
this.lastUpdate = payload.lastUpdate;
this.loaded = payload.loaded;
this.currentUpdateInterval = payload.currentUpdateInterval
this.currentUpdateInterval = payload.currentUpdateInterval
//Log.info("socketNotificationReceived - bus schedule data received is: " + this.busScheduleData);
//Log.info("socketNotificationReceived - bus schedule data received is: " + JSON.stringify(this.busScheduleData));
this.updateDom( );
Expand Down
41 changes: 17 additions & 24 deletions node_helper.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,6 @@
const NodeHelper = require( "node_helper" );
const unirest = require( 'unirest' );

var moment = require('moment');

//const synchronize = require('synchronize');
//const fiber = sync.fiber;
//const await = sync.await;
//const defer = sync.defer;


// for logger
const WARNING = "WARNING";
Expand Down Expand Up @@ -55,13 +48,13 @@ module.exports = NodeHelper.create( {
// full list of required bus schedule data
this.busScheduleData = {};
this.busScheduleData.lastUpdate = new Date( );

// test to avoid first request delayed of update interval
this.log(TRACE, "start - busScheduleData.lastUpdate " + this.busScheduleData.lastUpdate);
this.busScheduleData.lastUpdate.setHours(this.busScheduleData.lastUpdate.getHours() - 1)
this.log(TRACE, "start - busScheduleData.lastUpdate minus 01h00 " + this.busScheduleData.lastUpdate);
//end

this.busScheduleData.loaded = false;
this.busScheduleData.data = [];

Expand Down Expand Up @@ -115,11 +108,11 @@ module.exports = NodeHelper.create( {
this.log(TRACE, ' *** call Update Lines list');
this.updateAllTisseoData();
this.started = true;

// test for display at startup
this.updateBusScheduleTimetable(0);
// test for immediate display

this.log(TRACE, "socketNotificationReceived - schedule update of bus data (call scheduleBusScheduleUpdate())");
this.scheduleBusScheduleUpdate(this.config.initialLoadDelay);
};
Expand Down Expand Up @@ -157,7 +150,7 @@ module.exports = NodeHelper.create( {
}
else {
self.log(ERROR, "updateLineInfo - REQUEST_END - Nothing found for lineNumber=" + lineShortName);

}
// do callback recursion ...
self.updateLineInfo(nextIndex);
Expand Down Expand Up @@ -226,7 +219,7 @@ module.exports = NodeHelper.create( {
self.updateLineInfo(0);
this.log(TRACE, "updateAllTisseoData - end");
},

/* scheduleUpdate()
* Schedule next update.
* argument delay number - Millis econds before next update. If empty, this.config.updateInterval is used.
Expand Down Expand Up @@ -259,7 +252,7 @@ module.exports = NodeHelper.create( {
}, nextLoad );
this.log(TRACE, "scheduleBusScheduleUpdate - end");
},

updateJourneysTimetable: function () {
this.log(TRACE, "updateJourneysTimetable - start");
this.sendSocketNotification( "UPDATE_JOURNEYS", { lastUpdate: new Date( ) } );
Expand Down Expand Up @@ -290,16 +283,16 @@ module.exports = NodeHelper.create( {
//}
this.log(TRACE, "updateJourneysTimetable - end");
},


isTisseoDataFullyLoaded : function() {
return (
(this.uniqueStops.length == this.neededTisseoStops.length)
&&
(this.uniqueLines.length == this.neededTisseoLines.length)
);
},

/*
*
*/
Expand Down Expand Up @@ -390,13 +383,13 @@ module.exports = NodeHelper.create( {
self.log(DEBUG, "updateBusScheduleTimetable - this.config.retryDelay="+this.config.retryDelay);
// update delay info
self.processBusScheduleDataPending(this.config.retryDelay);

// reschedule
self.scheduleBusScheduleUpdate( this.config.retryDelay );
};
this.log(TRACE, "updateBusScheduleTimetable - end");
},

findBusLineId: function ( lineNumber) {
this.log(TRACE, "findBusLineId - start");
var returnData = {error: true, msg: 'not found'};
Expand Down Expand Up @@ -463,22 +456,22 @@ module.exports = NodeHelper.create( {
this.busScheduleData.data = [];
this.log(TRACE, "processBusScheduleData - end");
},


/* send bus schedule data to module DOM management*/
processBusScheduleDataPending: function (updateInterval) {
this.log(TRACE, "processBusScheduleDataPending - start");
this.log(DEBUG, "processBusScheduleDataPending - sending the data to MM module. Data: ");

this.busScheduleData = {};
this.busScheduleData.lastUpdate = new Date( );
this.busScheduleData.loaded = false;
this.busScheduleData.currentUpdateInterval = updateInterval
this.log(DEBUG, "processBusScheduleDataPending - " + JSON.stringify(this.busScheduleData));
this.sendSocketNotification( "BUS_SCHEDULES", this.busScheduleData );

// reset data

this.busScheduleData.lastUpdate = new Date( );
this.busScheduleData.loaded = false;
this.busScheduleData.data = [];
Expand Down
13 changes: 5 additions & 8 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"description": "Toulouse Local transport based on https://github.com/da4throux/MMM-Paris-RATP-PG module for MagicMirror",
"repository": {
"type": "git",
"url": "git+https://github.com/Telomere31/MMM-Toulouse-Transports"
"url": "git+https://github.com/LoneWanderer-GH/MMM-Toulouse-Transports"
},
"keywords": [
"magic mirror",
Expand All @@ -13,17 +13,14 @@
"module",
"Toulouse"
],
"author": "Telomere31",
"contributors": "https://github.com/Telomere31/MMM-Toulouse-Transports/graphs/contributors",
"author": "LoneWanderer-GH",
"contributors": "https://github.com/LoneWanderer-GH/MMM-Toulouse-Transports/graphs/contributors",
"license": "MIT",
"bugs": {
"url": "https://github.com/Telomere31/MMM-Toulouse-Transports/issues"
"url": "https://github.com/LoneWanderer-GH/MMM-Toulouse-Transports/issues"
},
"homepage": "https://github.com/Telomere31/MMM-Toulouse-Transports#readme",
"homepage": "https://github.com/LoneWanderer-GH/MMM-Toulouse-Transports#readme",
"dependencies": {
"moment": "^2.18.1",
"node-forge": "latest",
"synchronize": "^2.0.0",
"unirest": "latest"
}
}

0 comments on commit 142d532

Please sign in to comment.