update
This commit is contained in:
@@ -80,7 +80,7 @@ class nodeClass {
|
||||
const availableMachines = Object.values(mg.machines || {}).filter((machine) => {
|
||||
// Safety check: ensure machine and machine.state exist
|
||||
if (!machine || !machine.state || typeof machine.state.getCurrentState !== 'function') {
|
||||
console.warn(`Machine missing or invalid:`, machine?.config?.general?.id || 'unknown');
|
||||
mg.logger?.warn(`Machine missing or invalid: ${machine?.config?.general?.id || 'unknown'}`);
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -195,67 +195,52 @@ class nodeClass {
|
||||
this.node.on(
|
||||
"input",
|
||||
async (msg, send, done) => {
|
||||
const mg = this.source;
|
||||
const RED = this.RED;
|
||||
const mg = this.source;
|
||||
const RED = this.RED;
|
||||
try {
|
||||
switch (msg.topic) {
|
||||
case "registerChild":
|
||||
//console.log(`Registering child in mgc: ${msg.payload}`);
|
||||
const childId = msg.payload;
|
||||
const childObj = RED.nodes.getNode(childId);
|
||||
|
||||
// Debug: Check what we're getting
|
||||
//console.log(`Child object:`, childObj ? 'found' : 'NOT FOUND');
|
||||
//console.log(`Child source:`, childObj?.source ? 'exists' : 'MISSING');
|
||||
if (childObj?.source) {
|
||||
//console.log(`Child source type:`, childObj.source.constructor.name);
|
||||
//console.log(`Child has state:`, !!childObj.source.state);
|
||||
}
|
||||
|
||||
mg.childRegistrationUtils.registerChild(
|
||||
childObj.source,
|
||||
msg.positionVsParent
|
||||
);
|
||||
|
||||
// Debug: Check machines after registration
|
||||
//console.log(`Total machines after registration:`, Object.keys(mg.machines || {}).length);
|
||||
break;
|
||||
|
||||
case "registerChild": {
|
||||
const childId = msg.payload;
|
||||
const childObj = RED.nodes.getNode(childId);
|
||||
if (!childObj || !childObj.source) {
|
||||
mg.logger.warn(`registerChild skipped: missing child/source for id=${childId}`);
|
||||
break;
|
||||
}
|
||||
mg.childRegistrationUtils.registerChild(childObj.source, msg.positionVsParent);
|
||||
break;
|
||||
}
|
||||
case "setMode":
|
||||
const mode = msg.payload;
|
||||
mg.setMode(mode);
|
||||
mg.setMode(msg.payload);
|
||||
break;
|
||||
|
||||
case "setScaling":
|
||||
const scaling = msg.payload;
|
||||
mg.setScaling(scaling);
|
||||
|
||||
mg.setScaling(msg.payload);
|
||||
break;
|
||||
|
||||
case "Qd":
|
||||
case "Qd": {
|
||||
const Qd = parseFloat(msg.payload);
|
||||
const sourceQd = "parent";
|
||||
|
||||
if (isNaN(Qd)) {
|
||||
return mg.logger.error(`Invalid demand value: ${Qd}`);
|
||||
mg.logger.error(`Invalid demand value: ${msg.payload}`);
|
||||
break;
|
||||
}
|
||||
|
||||
try {
|
||||
await mg.handleInput(sourceQd, Qd);
|
||||
msg.topic = mg.config.general.name;
|
||||
msg.payload = "done";
|
||||
send(msg);
|
||||
} catch (e) {
|
||||
console.log(e);
|
||||
} catch (error) {
|
||||
mg.logger.error(`Failed to process Qd: ${error.message}`);
|
||||
}
|
||||
break;
|
||||
|
||||
}
|
||||
default:
|
||||
// Handle unknown topics if needed
|
||||
mg.logger.warn(`Unknown topic: ${msg.topic}`);
|
||||
break;
|
||||
}
|
||||
done();
|
||||
} catch (error) {
|
||||
mg.logger.error(`Input handler failure: ${error.message}`);
|
||||
}
|
||||
if (typeof done === 'function') done();
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
@@ -266,7 +251,7 @@ class nodeClass {
|
||||
this.node.on("close", (done) => {
|
||||
clearInterval(this._tickInterval);
|
||||
clearInterval(this._statusInterval);
|
||||
done();
|
||||
if (typeof done === 'function') done();
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user