-
Notifications
You must be signed in to change notification settings - Fork 0
/
node_helper.js
26 lines (25 loc) · 934 Bytes
/
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
const NodeHelper = require("node_helper");
module.exports = NodeHelper.create({
start: function() {
console.log("Starting node helper for: " + this.name);
},
socketNotificationReceived: function(notification, payload) {
if (notification === "GET_HOME_ASSISTANT_DATA") {
this.getHomeAssistantData(payload);
}
},
getHomeAssistantData: function(config) {
const url = `${config.homeAssistantUrl}/api/states`;
const headers = {
"Authorization": `Bearer ${config.accessToken}`
};
fetch(url, { headers: headers })
.then(response => response.json())
.then(data => {
this.sendSocketNotification("HOME_ASSISTANT_DATA", data);
})
.catch(error => {
console.error("Error fetching data from Home Assistant:", error);
});
}
});