diff --git a/.DS_Store b/.DS_Store index f5ae1c8..f1cd3af 100644 Binary files a/.DS_Store and b/.DS_Store differ diff --git a/src/custom_modules/HestiaClasses.js b/src/custom_modules/HestiaClasses.js new file mode 100644 index 0000000..32be192 --- /dev/null +++ b/src/custom_modules/HestiaClasses.js @@ -0,0 +1,71 @@ +export class State { + constructor(config) { + config.mqtt.subscriptions.forEach(subscription => { + this[subscription.name] = { + on: false, + topic: subscription.topic, + power: () => { + // This *should* toggle the state, asks if state is true, if it is set it false, otherwise set it true + this[subscription.name].on ? this[subscription.name].on = false : this[subscription.name].on = true; + } + }; + }); + }; +}; + +export class Communicator { + constructor(state) { + // Connect to the MQTT Broker + this.client = mqtt.connect(config.mqtt.address); + + // Subscribe to status topics + config.mqtt.subscriptions.forEach(subscription => { + this.client.subscribe(subscription.topic); + state[subscription.name].topic = subscription.topic; + }); + } + + powerOn(element, state) { + // Send the enable igniter message + // Publish with retain flag set to true + this.client.publish(topic, message, { retain: true }, (err) => { + if (err) { + console.error('Failed to publish message:', err); + } else { + console.log('Message published and retained on topic:', topic); + } + + // Optionally close the connection + client.end(); + }); + // Confirm + + // Update state + state.igniterOn(); + return state; + } + + igniterOn(state) { + + } + + augerOn(state) { + // Send the enable auger message + + // Confirm + + // Update state + state.augerOn(); + return state; + } + + exhaustOn(state) { + // Send the enable exhaust message + + // Confirm + + // Update state + state.exhaustOn(); + return state; + } +} \ No newline at end of file diff --git a/src/custom_modules/config.json b/src/custom_modules/config.json new file mode 100644 index 0000000..129060e --- /dev/null +++ b/src/custom_modules/config.json @@ -0,0 +1,19 @@ +{ + "mqtt": { + "address": "wd://broker-url:port", + "subscriptions": [ + { + "name": "igniter", + "topic": "hestia/status/igniter" + }, + { + "name": "exhaust", + "topic": "hestia/status/exhaust" + }, + { + "name": "auger", + "topic": "hestia/status/auger" + } + ] + } +} \ No newline at end of file