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.
This commit is contained in:
@@ -330,7 +330,16 @@ WantedBy=multi-user.target
|
|||||||
|
|
||||||
// Display battery with color coding
|
// Display battery with color coding
|
||||||
const batteryColor = getBatteryColor(status.batteryCapacity);
|
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')}`);
|
logger.log(` Battery: ${batteryColor(status.batteryCapacity + '%')} ${batterySymbol} Runtime: ${getRuntimeColor(status.batteryRuntime)(status.batteryRuntime + ' min')}`);
|
||||||
|
|
||||||
// Display host info
|
// Display host info
|
||||||
|
Reference in New Issue
Block a user