From ca30189c64d6b711d7f236f7996131b3199b9dc7 Mon Sep 17 00:00:00 2001 From: Skylar Grant Date: Wed, 14 Aug 2024 19:15:55 -0400 Subject: [PATCH] Testing 4 --- src/assets/HestiaClasses.js | 18 +----------------- src/assets/hestia.js | 28 +++++++++++++++++++++------- 2 files changed, 22 insertions(+), 24 deletions(-) diff --git a/src/assets/HestiaClasses.js b/src/assets/HestiaClasses.js index c7bf506..32be192 100644 --- a/src/assets/HestiaClasses.js +++ b/src/assets/HestiaClasses.js @@ -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 { - constructor() { + constructor(config) { config.mqtt.subscriptions.forEach(subscription => { this[subscription.name] = { on: false, diff --git a/src/assets/hestia.js b/src/assets/hestia.js index 034f03e..79cdef6 100644 --- a/src/assets/hestia.js +++ b/src/assets/hestia.js @@ -1,25 +1,39 @@ import { Communicator,State } from './HestiaClasses.js'; -const psState = new State(); -window.onload = function() { - refreshState(window.document); +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); }; -function refreshState(doc) { +function refreshState(doc, state) { const igniterStatus = doc.getElementById("igniterStatus"); const exhaustStatus = doc.getElementById("exhaustStatus"); const augerStatus = doc.getElementById("augerStatus"); let statusString; statusString = ''; - if (psState.igniter.on) statusString = "On"; else statusString = "Off"; + if (state.igniter.on) statusString = "On"; else statusString = "Off"; igniterStatus.innerHTML = statusString; statusString = ''; - if (psState.exhaust.on) statusString = "On"; else statusString = "Off"; + if (state.exhaust.on) statusString = "On"; else statusString = "Off"; exhaustStatus.innerHTML = statusString; statusString = ''; - if (psState.auger.on) statusString = "On"; else statusString = "Off"; + if (state.auger.on) statusString = "On"; else statusString = "Off"; augerStatus.innerHTML = statusString; } \ No newline at end of file