Add array to iterate over for elements

This commit is contained in:
Skylar Grant 2024-08-15 11:18:06 -04:00
parent 5af6ca77ba
commit f09f4dcf24

View File

@ -1,5 +1,6 @@
export class State { export class State {
constructor() { constructor() {
this.elements = ["igniter", "exhaust", "auger"],
this.igniter = { this.igniter = {
on: false, on: false,
topic: 'hestia/status/igniter', topic: 'hestia/status/igniter',
@ -55,10 +56,10 @@ export class Communicator {
client.on('connect', () => { client.on('connect', () => {
console.log('Connected to MQTT broker'); console.log('Connected to MQTT broker');
// Subscribe to status topics // Subscribe to status topics
state.forEach(element => { state.elements.forEach(element => {
client.subscribe(element.topic, (err) => { client.subscribe(state[element].topic, (err) => {
if (!err) { if (!err) {
console.log(`Subscribed to ${element.topic}`); console.log(`Subscribed to ${state[element].topic}`);
} }
}); });
}); });