diff --git a/src/helper/childRegistrationUtils.js b/src/helper/childRegistrationUtils.js index 8db49d8..eac2e7d 100644 --- a/src/helper/childRegistrationUtils.js +++ b/src/helper/childRegistrationUtils.js @@ -85,12 +85,12 @@ class ChildRegistrationUtils { case "actuator": this.logger.debug(`Registering linear actuator child: ${id}`); - this.connectActuator(child,positionVsParent); + this.connectActuator(child, positionVsParent); break; case "reactor": this.logger.debug(`Registering reactor child: ${id}`); - this.connectReactor(child); + this.connectReactor(child, positionVsParent); break; default: @@ -228,18 +228,30 @@ class ChildRegistrationUtils { //wanneer hij deze ontvangt is deltaP van een van de valves veranderd (kan ook zijn niet child zijn, maar dat maakt niet uit) - connectReactor(reactor) { + connectReactor(reactor, positionVsParent) { if (!reactor) { this.logger.warn("Invalid reactor provided."); return; } - this.mainClass.upstreamReactor = reactor; // Add reactor to the main class - this.logger.info(`Reactor registered successfully.`); + + if (this.mainClass?.upstreamReactor){ + this.mainClass.upstreamReactor = reactor; // Add reactor to the main class + this.logger.info(`Upstream reactor registered successfully.`); + } else if (this.mainClass?.reactors) { + if (positionVsParent == "downstream") { + this.mainClass.reactors[0] = reactor; + } + if (positionVsParent == "upstream") { + this.mainClass.reactors[1] = reactor; + } + this.logger.info(`Reactor registered successfully: ${this.mainClass.reactors}`); + } else { + this.logger.error(`Reactor not registered!`) + } reactor.emitter.on("stateChange", (data) => { - this.mainClass.logger.debug(`State change of reactor detected: ${data}`); - this.mainClass.setInflux = data; - this.mainClass.updateState(data.timestamp); + this.mainClass.logger.debug(`State change of upstream reactor detected.`); + this.mainClass.updateState(data); }); }