hestia/src/assets/hestia.js

39 lines
1.3 KiB
JavaScript
Raw Normal View History

2024-08-14 23:02:03 +00:00
import { Communicator,State } from './HestiaClasses.js';
2024-08-14 23:00:58 +00:00
2024-08-14 23:15:55 +00:00
window.onload = async function() {
const config = await fetch('/assets/config.json')
.then(response => {
if (!response.ok) {
throw new Error('Network response was not ok');
}
return response.json(); // Parse the JSON data from the response
})
.then(data => {
console.log(data); // Use the JSON data here
})
.catch(error => {
console.error('There was a problem with the fetch operation:', error);
});
console.log(config);
const psState = new State(config);
refreshState(window.document, psState);
2024-08-14 23:00:58 +00:00
};
2024-08-14 23:15:55 +00:00
function refreshState(doc, state) {
2024-08-14 23:00:58 +00:00
const igniterStatus = doc.getElementById("igniterStatus");
const exhaustStatus = doc.getElementById("exhaustStatus");
const augerStatus = doc.getElementById("augerStatus");
let statusString;
statusString = '';
2024-08-14 23:15:55 +00:00
if (state.igniter.on) statusString = "On"; else statusString = "Off";
2024-08-14 23:00:58 +00:00
igniterStatus.innerHTML = statusString;
statusString = '';
2024-08-14 23:15:55 +00:00
if (state.exhaust.on) statusString = "On"; else statusString = "Off";
2024-08-14 23:00:58 +00:00
exhaustStatus.innerHTML = statusString;
statusString = '';
2024-08-14 23:15:55 +00:00
if (state.auger.on) statusString = "On"; else statusString = "Off";
2024-08-14 23:00:58 +00:00
augerStatus.innerHTML = statusString;
}