2024-08-15 13:46:45 +00:00
|
|
|
import { Communicator, State } from './HestiaClasses.js';
|
|
|
|
const psState = new State();
|
2024-08-15 13:47:34 +00:00
|
|
|
const comms = new Communicator(psState);
|
2024-08-15 14:24:49 +00:00
|
|
|
const config = {
|
|
|
|
"mqtt": {
|
2024-08-15 14:26:59 +00:00
|
|
|
"address": "mqtt://192.168.0.3:8883",
|
2024-08-15 14:24:49 +00:00
|
|
|
"username": "hestia",
|
|
|
|
"password": "hestia",
|
|
|
|
"subscriptions": [
|
|
|
|
{
|
|
|
|
"name": "igniter",
|
|
|
|
"topic": "hestia/status/igniter"
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"name": "exhaust",
|
|
|
|
"topic": "hestia/status/exhaust"
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"name": "auger",
|
|
|
|
"topic": "hestia/status/auger"
|
|
|
|
}
|
|
|
|
]
|
|
|
|
}
|
|
|
|
};
|
2024-08-14 23:00:58 +00:00
|
|
|
|
2024-08-15 14:24:49 +00:00
|
|
|
window.onload = function() {
|
|
|
|
psState.init(config);
|
|
|
|
comms.init(psState, config);
|
|
|
|
refreshState(window.document, psState);
|
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 14:24:49 +00:00
|
|
|
console.log('State refreshed.');
|
2024-08-15 13:46:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function power(element) {
|
|
|
|
psState[element].power(comms);
|
2024-08-14 23:00:58 +00:00
|
|
|
}
|