From 4debda856bd9ec2258f7f08e102ce5eae8b30f9c Mon Sep 17 00:00:00 2001 From: Juergen Kunz Date: Mon, 20 Oct 2025 12:20:40 +0000 Subject: [PATCH] fix(status): update status display to use action-based thresholds The status command was still trying to access ups.thresholds.battery which no longer exists in v4.1+ configs. Thresholds are now in the actions array. Changes: - Updated displaySingleUpsStatus() to get thresholds from actions - Finds first action with thresholds defined for battery symbol display - Shows success/warning symbol only if threshold is defined This fixes 'Cannot read properties of undefined (reading battery)' error when running nupst status on v4.1+ configs. --- ts/systemd.ts | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/ts/systemd.ts b/ts/systemd.ts index 312791e..9c2b3c3 100644 --- a/ts/systemd.ts +++ b/ts/systemd.ts @@ -330,7 +330,16 @@ WantedBy=multi-user.target // Display battery with color coding const batteryColor = getBatteryColor(status.batteryCapacity); - const batterySymbol = status.batteryCapacity >= ups.thresholds.battery ? symbols.success : symbols.warning; + + // Get threshold from actions (if any action has thresholds defined) + const actionWithThresholds = ups.actions?.find((action: any) => action.thresholds); + const batteryThreshold = actionWithThresholds?.thresholds?.battery; + const batterySymbol = batteryThreshold !== undefined && status.batteryCapacity >= batteryThreshold + ? symbols.success + : batteryThreshold !== undefined + ? symbols.warning + : ''; + logger.log(` Battery: ${batteryColor(status.batteryCapacity + '%')} ${batterySymbol} Runtime: ${getRuntimeColor(status.batteryRuntime)(status.batteryRuntime + ' min')}`); // Display host info