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
1 changed files with 4 additions and 3 deletions

View File

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