hestia/src/assets/hestia.js

54 lines
1.5 KiB
JavaScript
Raw Normal View History

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);
const config = {
"mqtt": {
2024-08-15 14:31:12 +00:00
"address": "wss://192.168.0.3:9001",
"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
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;
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
}