2024-08-15 13:46:45 +00:00
|
|
|
import { Communicator, State } from './HestiaClasses.js';
|
|
|
|
let config;
|
|
|
|
const psState = new State();
|
2024-08-15 13:47:34 +00:00
|
|
|
const comms = new Communicator(psState);
|
2024-08-14 23:00:58 +00:00
|
|
|
|
2024-08-14 23:15:55 +00:00
|
|
|
window.onload = async function() {
|
2024-08-15 00:26:40 +00:00
|
|
|
await fetch('/assets/config.json')
|
2024-08-14 23:15:55 +00:00
|
|
|
.then(response => {
|
|
|
|
if (!response.ok) {
|
|
|
|
throw new Error('Network response was not ok');
|
2024-08-15 00:27:24 +00:00
|
|
|
}
|
2024-08-15 00:26:40 +00:00
|
|
|
return response.json(); // Parse the JSON data from the response
|
2024-08-14 23:15:55 +00:00
|
|
|
})
|
|
|
|
.then(data => {
|
2024-08-15 13:46:45 +00:00
|
|
|
config = data;
|
|
|
|
psState.init(config);
|
2024-08-15 13:49:24 +00:00
|
|
|
comms.init(psState, config);
|
2024-08-15 00:26:40 +00:00
|
|
|
refreshState(window.document, psState);
|
2024-08-14 23:15:55 +00:00
|
|
|
})
|
|
|
|
.catch(error => {
|
|
|
|
console.error('There was a problem with the fetch operation:', error);
|
|
|
|
});
|
2024-08-14 23:00:58 +00:00
|
|
|
};
|
|
|
|
|
2024-08-14 23:15:55 +00:00
|
|
|
function refreshState(doc, state) {
|
2024-08-15 00:29:22 +00:00
|
|
|
const igniterStatus = doc.getElementById("igniter-status");
|
|
|
|
const exhaustStatus = doc.getElementById("exhaust-status");
|
|
|
|
const augerStatus = doc.getElementById("auger-status");
|
2024-08-14 23:00:58 +00:00
|
|
|
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;
|
2024-08-15 13:46:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function power(element) {
|
|
|
|
psState[element].power(comms);
|
2024-08-14 23:00:58 +00:00
|
|
|
}
|