This repository has been archived by the owner on May 18, 2022. It is now read-only.
forked from deg0nz/MMM-PublicTransportBerlin
-
Notifications
You must be signed in to change notification settings - Fork 7
/
node_helper.js
120 lines (92 loc) · 3.19 KB
/
node_helper.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
"use strict";
const NodeHelper = require('node_helper');
const Fetcher = require('./DbFetcher');
const Promise = require('./vendor/bluebird-3.4.5.min');
module.exports = NodeHelper.create({
start: function () {
this.departuresFetchers = []
},
createFetcher: function (config) {
let fetcher;
if (typeof this.departuresFetchers[config.stationId] === "undefined") {
fetcher = new Fetcher(config);
this.departuresFetchers[config.stationId] = fetcher;
this.sendInit(fetcher);
console.log("Transportation fetcher created. (Station ID: " + fetcher.getStationId() + ")");
} else {
fetcher = this.departuresFetchers[config.stationId];
this.sendInit(fetcher);
}
this.getDepartures(fetcher.getStationId());
},
sendInit: function(fetcher){
this.sendSocketNotification('FETCHER_INIT', {
stationId: fetcher.getStationId(),
stationName: 'name'
});
},
getDepartures: function (stationId) {
this.departuresFetchers[stationId].fetchDepartures().then((departuresData) => {
this.pimpDeparturesArray(departuresData.departuresArray);
this.sendSocketNotification('DEPARTURES', departuresData);
});
},
pimpDeparturesArray: function (departuresArray) {
let currentProperties = {};
departuresArray.forEach((current) => {
currentProperties = this.getLineProperties(current);
//if (!this.config.marqueeLongDirections) {
// current.direction = this.trimDirectionString(current.direction);
//}
current.color = currentProperties.color;
current.cssClass = currentProperties.cssClass;
});
return departuresArray;
},
getLineProperties: function (product) {
let out = {
color: "#000000",
cssClass: ""
};
let type = product.type;
let line = product.nr;
switch (type) {
case "suburban":
out.color = product.color;
out.cssClass = "sbahnsign";
break;
case "subway":
out.color = product.color;
out.cssClass = "ubahnsign";
break;
case "bus":
out.color = product.color;
out.cssClass = "bussign";
break;
case "tram":
out.color = product.color;
out.cssClass = "tramsign";
break;
case "regional":
out.color = product.color;
out.cssClass = "dbsign";
break;
}
return out;
},
getSuburbanLineColor: function (lineNumber) {
let color;
return color;
},
getSubwayLineColor: function (lineNumber) {
let color;
return color;
},
socketNotificationReceived: function (notification, payload) {
if (notification === 'GET_DEPARTURES') {
this.getDepartures(payload);
} else if (notification === 'CREATE_FETCHER') {
this.createFetcher(payload);
}
}
});