From a987800cd7a3403d2a263113c43973d89309e988 Mon Sep 17 00:00:00 2001 From: Skylar Grant Date: Wed, 21 Aug 2024 22:02:23 -0400 Subject: [PATCH] Tentative test for control toggle --- src/custom_modules/HestiaClasses.js | 5 +++++ src/main.js | 9 ++++++++- 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/src/custom_modules/HestiaClasses.js b/src/custom_modules/HestiaClasses.js index e1786c9..54066dc 100644 --- a/src/custom_modules/HestiaClasses.js +++ b/src/custom_modules/HestiaClasses.js @@ -79,6 +79,11 @@ module.exports = { console.log(`Message received on topic ${topic}: ${msgStr}`); console.log(msgJson); state[msgJson.name].on = msgJson.on; + const change = { + name: msgJson.name, + on: msgJson.on + }; + this.emit('stateChange', change); }); } diff --git a/src/main.js b/src/main.js index d4844ad..adb8749 100644 --- a/src/main.js +++ b/src/main.js @@ -20,4 +20,11 @@ setInterval(() => { }).catch(e => console.error(e)); } } -}, 1000); \ No newline at end of file +}, 1000); + +comms.on('stateChange', (change) => { + console.log(`State change detected: ${change.name}`); + gpio.togglePin(config.states[change.name].pin, change.on).then(() => { + console.log(`Pin ${config.states[change.name].pin} set to ${change.on}`); + }); +}); \ No newline at end of file