Ready to test startup and shutdown
This commit is contained in:
parent
7fa0339791
commit
bdeb3152d2
@ -104,6 +104,7 @@ module.exports = {
|
|||||||
|
|
||||||
// Handle when the Broker sends us a message
|
// Handle when the Broker sends us a message
|
||||||
client.on('message', (topic, message) => {
|
client.on('message', (topic, message) => {
|
||||||
|
if (topic.startsWith('hestia/status')) {
|
||||||
// Save the existing state
|
// Save the existing state
|
||||||
const oldState = JSON.parse(JSON.stringify(state));
|
const oldState = JSON.parse(JSON.stringify(state));
|
||||||
// The message is a buffer which will need to be converted to string
|
// The message is a buffer which will need to be converted to string
|
||||||
@ -123,6 +124,15 @@ module.exports = {
|
|||||||
state[msgJson.name].on = msgJson.on;
|
state[msgJson.name].on = msgJson.on;
|
||||||
// Emit the state change
|
// Emit the state change
|
||||||
this.emit('stateChange', oldState, state);
|
this.emit('stateChange', oldState, state);
|
||||||
|
} else if (topic === 'hestia/command/startup') {
|
||||||
|
// Empty block for 'hestia/command' topics
|
||||||
|
this.emit('startup');
|
||||||
|
} else if (topic === 'hestia/command/shutdown') {
|
||||||
|
// Empty block for 'hestia/command' topics
|
||||||
|
this.emit('shutdown');
|
||||||
|
} else {
|
||||||
|
console.log(`Unknown topic: ${topic}`);
|
||||||
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -8,7 +8,9 @@
|
|||||||
"exhaust": "hestia/status/exhaust",
|
"exhaust": "hestia/status/exhaust",
|
||||||
"auger": "hestia/status/auger",
|
"auger": "hestia/status/auger",
|
||||||
"pof": "hestia/status/pof",
|
"pof": "hestia/status/pof",
|
||||||
"vacuum": "hestia/status/vacuum"
|
"vacuum": "hestia/status/vacuum",
|
||||||
|
"startup": "hestia/command/startup",
|
||||||
|
"shutdown": "hestia/command/shutdown"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"states": {
|
"states": {
|
||||||
@ -17,7 +19,9 @@
|
|||||||
"exhaust",
|
"exhaust",
|
||||||
"auger",
|
"auger",
|
||||||
"pof",
|
"pof",
|
||||||
"vacuum"
|
"vacuum",
|
||||||
|
"startup",
|
||||||
|
"shutdown"
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
"pins": [
|
"pins": [
|
||||||
|
10
src/main.js
10
src/main.js
@ -31,3 +31,13 @@ comms.on('stateChange', (oldState, state) => {
|
|||||||
console.log(`State change detected.`);
|
console.log(`State change detected.`);
|
||||||
fn.handlers.stateChange(oldState, state);
|
fn.handlers.stateChange(oldState, state);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
comms.on('startup', () => {
|
||||||
|
console.log(`Startup detected.`);
|
||||||
|
fn.power.start.init().catch(e => console.error(e));
|
||||||
|
});
|
||||||
|
|
||||||
|
comms.on('shutdown', () => {
|
||||||
|
console.log(`Shutdown detected.`);
|
||||||
|
fn.power.stop.init().catch(e => console.error(e));
|
||||||
|
});
|
Loading…
Reference in New Issue
Block a user