import { Communicator, State } from './HestiaClasses.js'; let config; const psState = new State(); const comms = new Communicator(psState); 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 => { config = data; console.log(config); psState.init(config); comms.init(psState, 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; } function power(element) { psState[element].power(comms); }