import { Communicator, State } from './HestiaClasses.js'; const psState = new State(); const comms = new Communicator(psState); const config = { "mqtt": { "address": "mqtt://192.168.0.3:8883", "username": "hestia", "password": "hestia", "subscriptions": [ { "name": "igniter", "topic": "hestia/status/igniter" }, { "name": "exhaust", "topic": "hestia/status/exhaust" }, { "name": "auger", "topic": "hestia/status/auger" } ] } }; window.onload = function() { psState.init(config); comms.init(psState, config); refreshState(window.document, psState); }; 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; console.log('State refreshed.'); } function power(element) { psState[element].power(comms); }