hestia/src/assets/hestia.js
2024-08-14 20:29:22 -04:00

39 lines
1.3 KiB
JavaScript

import { Communicator,State } from './HestiaClasses.js';
window.onload = async function() {
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 => {
const config = data;
console.log(config);
const psState = new State(config);
refreshState(window.document, psState);
})
.catch(error => {
console.error('There was a problem with the fetch operation:', error);
});
};
function refreshState(doc, state) {
const igniterStatus = doc.getElementById("igniter-status");
const exhaustStatus = doc.getElementById("exhaust-status");
const augerStatus = doc.getElementById("auger-status");
let statusString;
statusString = '';
if (state.igniter.on) statusString = "On"; else statusString = "Off";
igniterStatus.innerHTML = statusString;
statusString = '';
if (state.exhaust.on) statusString = "On"; else statusString = "Off";
exhaustStatus.innerHTML = statusString;
statusString = '';
if (state.auger.on) statusString = "On"; else statusString = "Off";
augerStatus.innerHTML = statusString;
}