working on a stable version
This commit is contained in:
@@ -61,25 +61,28 @@ class nodeClass {
|
||||
const mg = this.source;
|
||||
const mode = mg.mode;
|
||||
const scaling = mg.scaling;
|
||||
const totalFlow =
|
||||
Math.round(
|
||||
mg.measurements
|
||||
.type("flow")
|
||||
.variant("predicted")
|
||||
.position("downstream")
|
||||
.getCurrentValue() * 1
|
||||
) / 1;
|
||||
const totalPower =
|
||||
Math.round(
|
||||
mg.measurements
|
||||
.type("power")
|
||||
.variant("predicted")
|
||||
.position("upstream")
|
||||
.getCurrentValue() * 1
|
||||
) / 1;
|
||||
|
||||
// Add safety checks for measurements
|
||||
const totalFlow = mg.measurements
|
||||
?.type("flow")
|
||||
?.variant("predicted")
|
||||
?.position("downstream")
|
||||
?.getCurrentValue() || 0;
|
||||
|
||||
const totalPower = mg.measurements
|
||||
?.type("power")
|
||||
?.variant("predicted")
|
||||
?.position("upstream")
|
||||
?.getCurrentValue() || 0;
|
||||
|
||||
// Calculate total capacity based on available machines
|
||||
const availableMachines = Object.values(mg.machines).filter((machine) => {
|
||||
// Calculate total capacity based on available machines with safety checks
|
||||
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');
|
||||
return false;
|
||||
}
|
||||
|
||||
const state = machine.state.getCurrentState();
|
||||
const mode = machine.currentMode;
|
||||
return !(
|
||||
@@ -89,29 +92,27 @@ class nodeClass {
|
||||
);
|
||||
});
|
||||
|
||||
const totalCapacity = Math.round(mg.dynamicTotals.flow.max * 1) / 1;
|
||||
const totalCapacity = Math.round((mg.dynamicTotals?.flow?.max || 0) * 1) / 1;
|
||||
|
||||
// Determine overall status based on available machines
|
||||
const status =
|
||||
availableMachines.length > 0
|
||||
? `${availableMachines.length} machine(s) connected`
|
||||
: "No machines";
|
||||
const status = availableMachines.length > 0
|
||||
? `${availableMachines.length} machine(s) connected`
|
||||
: "No machines";
|
||||
|
||||
let scalingSymbol = "";
|
||||
switch (scaling.toLowerCase()) {
|
||||
switch ((scaling || "").toLowerCase()) {
|
||||
case "absolute":
|
||||
scalingSymbol = "Ⓐ"; // Clear symbol for Absolute mode
|
||||
scalingSymbol = "Ⓐ";
|
||||
break;
|
||||
case "normalized":
|
||||
scalingSymbol = "Ⓝ"; // Clear symbol for Normalized mode
|
||||
scalingSymbol = "Ⓝ";
|
||||
break;
|
||||
default:
|
||||
scalingSymbol = mode;
|
||||
scalingSymbol = mode || "";
|
||||
break;
|
||||
}
|
||||
|
||||
// Generate status text in a single line
|
||||
const text = ` ${mode} | ${scalingSymbol}: 💨=${totalFlow}/${totalCapacity} | ⚡=${totalPower} | ${status}`;
|
||||
const text = ` ${mode || 'Unknown'} | ${scalingSymbol}: 💨=${Math.round(totalFlow)}/${totalCapacity} | ⚡=${Math.round(totalPower)} | ${status}`;
|
||||
|
||||
return {
|
||||
fill: availableMachines.length > 0 ? "green" : "red",
|
||||
@@ -197,14 +198,26 @@ class nodeClass {
|
||||
const RED = this.RED;
|
||||
switch (msg.topic) {
|
||||
case "registerChild":
|
||||
//console.log(`Registering child in mgc: ${msg.payload}`);
|
||||
const childId = msg.payload;
|
||||
const childObj = RED.nodes.getNode(childId);
|
||||
mg.childRegistrationUtils.registerChild(
|
||||
childObj.source,
|
||||
msg.positionVsParent
|
||||
);
|
||||
break;
|
||||
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 "setMode":
|
||||
const mode = msg.payload;
|
||||
@@ -215,6 +228,7 @@ class nodeClass {
|
||||
case "setScaling":
|
||||
const scaling = msg.payload;
|
||||
mg.setScaling(scaling);
|
||||
|
||||
break;
|
||||
|
||||
case "Qd":
|
||||
|
||||
Reference in New Issue
Block a user