From bb3f0cfad5030ac3e2517b52553eedb862f60ea6 Mon Sep 17 00:00:00 2001 From: Skylar Grant Date: Thu, 15 Aug 2024 08:40:20 -0400 Subject: [PATCH] Import classes --- .DS_Store | Bin 8196 -> 8196 bytes src/custom_modules/HestiaClasses.js | 71 ++++++++++++++++++++++++++++ src/custom_modules/config.json | 19 ++++++++ 3 files changed, 90 insertions(+) create mode 100644 src/custom_modules/HestiaClasses.js create mode 100644 src/custom_modules/config.json diff --git a/.DS_Store b/.DS_Store index f5ae1c832d4b18839f7c1a31817ffac2be2bcfb7..f1cd3af21a2fb2a287d0e66b38b50c2f4047580c 100644 GIT binary patch delta 88 zcmZp1XmQxEM~F$jY4ScHF^APWzg}~hA9G}2U|?n_W+-Av&dpD8Ny^Dj0*Y{8$`)i8 Y1}Ep|764^|z=2_MpRm|wE#X@{0LkweR{#J2 delta 88 zcmZp1XmQxEM~F#6b@DzTF^Au)dz-n;k2x|hFfcO|GZZl-=jNxlB<18M0Yx}4WeYM4 YgOl@f3xKjfV8AfBPgrcTmhdee0J#bo7XSbN 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