diff --git a/src/assets/HestiaClasses.js b/src/assets/HestiaClasses.js index 027d063..a1439e2 100644 --- a/src/assets/HestiaClasses.js +++ b/src/assets/HestiaClasses.js @@ -48,18 +48,6 @@ export class State { communicator.send(config.mqtt.topics.pof, JSON.stringify(this.pof)); } }; - - this.vacuum = { - on: false, - name: "vacuum", - topic: config.mqtt.topics.vacuum, - publisher: 'backend', - power: (communicator) => { - // This *should* toggle the state, asks if state is true, if it is set it false, otherwise set it true - this.vacuum.on ? this.vacuum.on = false : this.vacuum.on = true; - communicator.send(config.mqtt.topics.vacuum, JSON.stringify(this.vacuum)); - } - }; console.log(`State initialized.`) }; }; diff --git a/src/assets/hestia.js b/src/assets/hestia.js index 7cd4709..f52f8a7 100644 --- a/src/assets/hestia.js +++ b/src/assets/hestia.js @@ -10,7 +10,6 @@ const config = { "exhaust": "hestia/status/exhaust", "auger": "hestia/status/auger", "pof": "hestia/status/pof", - "vacuum": "hestia/status/vacuum" } }, "states": { @@ -19,42 +18,64 @@ const config = { "exhaust", "auger", "pof", - "vacuum" ] + }, + "feedRates": { + "low": 500, + "medium-low": 625, + "medium": 750, + "medium-high": 875, + "high": 1000, + "reverse": { + "500": "Low", + "625": "Medium-Low", + "750": "Medium", + "875": "Medium-High", + "1000": "High", + } } }; + +// Create a new state and communicator const psState = new State(config); const comms = new Communicator(psState); +// Grab elements from the DOM const setFeedRateButton = document.getElementById("set-feed-rate"); +const igniterStatus = doc.getElementById("igniter-status"); +const exhaustStatus = doc.getElementById("exhaust-status"); +const augerStatus = doc.getElementById("auger-status"); +const pofStatus = doc.getElementById("pof-status"); +const feedRateStatus = document.getElementById("feed-rate-status"); export function refreshState(doc, state) { - const igniterStatus = doc.getElementById("igniter-status"); - const exhaustStatus = doc.getElementById("exhaust-status"); - const augerStatus = doc.getElementById("auger-status"); - const pofStatus = doc.getElementById("pof-status"); - const vacuumStatus = doc.getElementById("vacuum-status"); - let statusString; + let statusString = new String('Loading...'); - statusString = ''; + // Igniter if (state.igniter.on) statusString = "On"; else statusString = "Off"; igniterStatus.innerHTML = statusString; - statusString = ''; + // Exhaust + statusString = 'Loading...'; if (state.exhaust.on) statusString = "On"; else statusString = "Off"; exhaustStatus.innerHTML = statusString; - statusString = ''; + // Auger + statusString = 'Loading...'; if (state.auger.on) statusString = "On"; else statusString = "Off"; augerStatus.innerHTML = statusString; - statusString = ''; + // Proof of Fire + statusString = 'Loading...'; if (state.pof.on) statusString = "On"; else statusString = "Off"; pofStatus.innerHTML = statusString; - statusString = ''; - if (state.vacuum.on) statusString = "On"; else statusString = "Off"; - vacuumStatus.innerHTML = statusString; + // This is needlessly complicated but it matches the other status updates + statusString = 'Loading...'; + const { feedRate } = state.auger; + if (config.feedRates.reverse[feedRate]) statusString = config.feedRates.reverse[feedRate]; + else statusString = feedRate; + feedRateStatus.innerHTML = statusString; console.log('State refreshed.'); } @@ -72,6 +93,7 @@ export function shutdown() { comms.shutdown(); } +// Run stuff once the page loads window.onload = function() { comms.init(psState, config); refreshState(window.document, psState); diff --git a/src/index.html b/src/index.html index 42c16f3..0f3411d 100644 --- a/src/index.html +++ b/src/index.html @@ -45,16 +45,16 @@