-
-
Notifications
You must be signed in to change notification settings - Fork 15
/
Copy pathhelper.js
38 lines (35 loc) · 1.09 KB
/
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
/* MagicMirror²
* Module: MMM-AirQuality
*
* By Christopher Fenner https://github.com/CFenner
* MIT Licensed.
*/
module.exports = {
notifications: {
DATA: 'AIR_QUALITY_DATA',
DATA_RESPONSE: 'AIR_QUALITY_DATA_RESPONSE',
},
start: function () {
console.log('AirQuality helper started ...')
},
loadData: async function (payload) {
const self = this
const url = `https://${payload.config.apiBase}${payload.config.dataEndpoint}${payload.config.location}/?token=${payload.config.token}`
console.log(`AirQuality-Fetcher: ${url}`)
const result = await fetch(url)
.then(response => response.json())
self.sendSocketNotification(self.notifications.DATA_RESPONSE, {
payloadReturn: result,
status: 'OK',
identifier: payload.identifier,
})
},
socketNotificationReceived: function (notification, payload) {
switch (notification) {
case this.notifications.DATA:
console.log(`AirQuality-Fetcher: Loading data of ${payload.config.location} for module ${payload.identifier}`)
this.loadData(payload)
break
}
},
}