Tentatively got State and Communicator working
This commit is contained in:
parent
bb3f0cfad5
commit
805e5e28ab
@ -4,9 +4,11 @@ export class State {
|
||||
this[subscription.name] = {
|
||||
on: false,
|
||||
topic: subscription.topic,
|
||||
power: () => {
|
||||
publisher: 'back',
|
||||
power: (communicator) => {
|
||||
// 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;
|
||||
communicator.send(subscription.name, JSON.stringify(this));
|
||||
}
|
||||
};
|
||||
});
|
||||
@ -25,8 +27,8 @@ export class Communicator {
|
||||
});
|
||||
}
|
||||
|
||||
powerOn(element, state) {
|
||||
// Send the enable igniter message
|
||||
// Publish a message to the MQTT Broker
|
||||
send(topic, message) {
|
||||
// Publish with retain flag set to true
|
||||
this.client.publish(topic, message, { retain: true }, (err) => {
|
||||
if (err) {
|
||||
@ -34,38 +36,6 @@ export class Communicator {
|
||||
} 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;
|
||||
}
|
||||
}
|
@ -1 +1,5 @@
|
||||
// Hestia Control Panel Back-End
|
||||
import { State, Communicator } from './custom_modules/HestiaClasses';
|
||||
import config from './custom_modules/config.json' assert { type: 'json' };
|
||||
const psState = new State(config);
|
||||
const comm = new Communicator(psState);
|
Loading…
Reference in New Issue
Block a user