Testing 4

This commit is contained in:
Skylar Grant 2024-08-14 19:15:55 -04:00
parent 26c2f0a87d
commit ca30189c64
2 changed files with 22 additions and 24 deletions

View File

@ -1,21 +1,5 @@
// Custom Classes files
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);
});
export class State { export class State {
constructor() { constructor(config) {
config.mqtt.subscriptions.forEach(subscription => { config.mqtt.subscriptions.forEach(subscription => {
this[subscription.name] = { this[subscription.name] = {
on: false, on: false,

View File

@ -1,25 +1,39 @@
import { Communicator,State } from './HestiaClasses.js'; import { Communicator,State } from './HestiaClasses.js';
const psState = new State();
window.onload = function() { window.onload = async function() {
refreshState(window.document); 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);
}; };
function refreshState(doc) { function refreshState(doc, state) {
const igniterStatus = doc.getElementById("igniterStatus"); const igniterStatus = doc.getElementById("igniterStatus");
const exhaustStatus = doc.getElementById("exhaustStatus"); const exhaustStatus = doc.getElementById("exhaustStatus");
const augerStatus = doc.getElementById("augerStatus"); const augerStatus = doc.getElementById("augerStatus");
let statusString; let statusString;
statusString = ''; statusString = '';
if (psState.igniter.on) statusString = "On"; else statusString = "Off"; if (state.igniter.on) statusString = "On"; else statusString = "Off";
igniterStatus.innerHTML = statusString; igniterStatus.innerHTML = statusString;
statusString = ''; statusString = '';
if (psState.exhaust.on) statusString = "On"; else statusString = "Off"; if (state.exhaust.on) statusString = "On"; else statusString = "Off";
exhaustStatus.innerHTML = statusString; exhaustStatus.innerHTML = statusString;
statusString = ''; statusString = '';
if (psState.auger.on) statusString = "On"; else statusString = "Off"; if (state.auger.on) statusString = "On"; else statusString = "Off";
augerStatus.innerHTML = statusString; augerStatus.innerHTML = statusString;
} }