fix: guard demo IIFE with require.main check

Prevents demo code from executing when module is required by Node-RED,
which caused crashes due to missing measurement data.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
Rene De Ren
2026-03-11 16:38:08 +01:00
parent f01b0bcb19
commit 3ff76228eb

View File

@@ -613,7 +613,8 @@ function pushSample(measurement, type, value, unit) { // eslint-disable-line no-
} }
/** Demo *********************************************************************/ /** Demo *********************************************************************/
(async function demoStationWithPump() { // Only run the demo when this file is executed directly (not when required as a module)
if (require.main === module) (async function demoStationWithPump() {
const station = new PumpingStation(createPumpingStationConfig("PumpingStationDemo")); const station = new PumpingStation(createPumpingStationConfig("PumpingStationDemo"));
const pump = new RotatingMachine(createMachineConfig("Pump1"), createMachineStateConfig()); const pump = new RotatingMachine(createMachineConfig("Pump1"), createMachineStateConfig());