-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathnode_helper.js
46 lines (37 loc) · 1.13 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
/*
MMM-MyDutchWeather
Copyright (C) 2024 - H. Tilburgs
MIT License
v1.0.0 : Initial version
v1.2.0 : Update request to fetch (request package has been deprecated)
v2.0.0 - 12-11-2024 - API 2.0
//-------------------------------------------
*/
const NodeHelper = require("node_helper");
module.exports = NodeHelper.create({
start() {
console.log(`Starting node_helper for: ${this.name}`);
},
async getMWB(url) {
try {
// Maak een GET-aanroep naar de opgegeven URL
const response = await fetch(url);
if (!response.ok) {
throw new Error(
`MMM-MyDutchWeather: Network response was not ok. Status: ${response.status} ${response.statusText}`
);
}
const result = await response.json();
// Stuur de ontvangen gegevens naar de module
this.sendSocketNotification("MWB_RESULT", result);
} catch (error) {
console.error(`MMM-MyDutchWeather Error: ${error.message}`);
}
},
socketNotificationReceived(notification, payload) {
if (notification === "GET_MWB") {
// Start de API-aanroep met de payload (URL)
this.getMWB(payload);
}
},
});