Compare commits

..

6 Commits

Author SHA1 Message Date
316c66c344 chore(release): bump version to 4.2.4
Some checks failed
CI / Type Check & Lint (push) Failing after 5s
CI / Build Test (Current Platform) (push) Successful in 5s
Release / build-and-release (push) Successful in 45s
CI / Build All Platforms (push) Successful in 50s
2025-10-20 12:20:42 +00:00
4debda856b 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.
2025-10-20 12:20:40 +00:00
0e7bcab499 chore(release): bump version to 4.2.3
Some checks failed
CI / Type Check & Lint (push) Failing after 4s
CI / Build Test (Current Platform) (push) Successful in 6s
Release / build-and-release (push) Successful in 43s
CI / Build All Platforms (push) Successful in 48s
2025-10-20 12:17:06 +00:00
7bf65d8495 fix(migrations): revert to correct migration v4.0-to-v4.1
The migration was correct as v4.0→v4.1. Config version goes from 4.0 to 4.1
when thresholds are moved to actions. The original error was not the migration
but the ups-handler.ts bug (already fixed in v4.2.1).

User's config shows version "4.1" with actions already present, confirming
the migration ran successfully.
2025-10-20 12:17:03 +00:00
f2ce0180d3 chore(release): bump version to 4.2.2
Some checks failed
CI / Type Check & Lint (push) Failing after 5s
CI / Build Test (Current Platform) (push) Successful in 6s
Release / build-and-release (push) Successful in 45s
CI / Build All Platforms (push) Successful in 48s
2025-10-20 12:14:16 +00:00
8c1be6555f fix(migrations): correct migration version from v4.0-to-v4.1 to v4.1-to-v4.2
The migration was incorrectly named as v4.0→v4.1 but was actually performing
the v4.1→v4.2 migration (moving thresholds from UPS-level to action-level).
This meant users upgrading from v4.1 would not get their configs migrated.

Changes:
- Renamed migration file from migration-v4.0-to-v4.1.ts to migration-v4.1-to-v4.2.ts
- Updated class name from MigrationV4_0ToV4_1 to MigrationV4_1ToV4_2
- Updated fromVersion from '4.0' to '4.1'
- Updated toVersion from '4.1' to '4.2'
- Updated shouldRun() to check for config.version === '4.1'
- Updated all imports and exports to reference the new class name
- Updated comments and log messages to reflect v4.1→v4.2 migration
2025-10-20 12:14:02 +00:00
4 changed files with 17 additions and 8 deletions

View File

@@ -1,6 +1,6 @@
{ {
"name": "@serve.zone/nupst", "name": "@serve.zone/nupst",
"version": "4.2.1", "version": "4.2.4",
"exports": "./mod.ts", "exports": "./mod.ts",
"tasks": { "tasks": {
"dev": "deno run --allow-all mod.ts", "dev": "deno run --allow-all mod.ts",

View File

@@ -19,7 +19,7 @@ export class MigrationRunner {
new MigrationV1ToV2(), new MigrationV1ToV2(),
new MigrationV3ToV4(), new MigrationV3ToV4(),
new MigrationV4_0ToV4_1(), new MigrationV4_0ToV4_1(),
// Add future migrations here (v4.2, v4.3, etc.) // Add future migrations here (v4.3, v4.4, etc.)
]; ];
// Sort by version order to ensure they run in sequence // Sort by version order to ensure they run in sequence

View File

@@ -10,7 +10,7 @@ import { logger } from '../logger.ts';
* 3. Adds empty actions array to UPS devices without actions * 3. Adds empty actions array to UPS devices without actions
* 4. Adds empty actions array to groups * 4. Adds empty actions array to groups
* *
* Transforms v4.0 format: * Transforms v4.0 format (with UPS-level thresholds):
* { * {
* version: "4.0", * version: "4.0",
* upsDevices: [ * upsDevices: [
@@ -24,7 +24,7 @@ import { logger } from '../logger.ts';
* ] * ]
* } * }
* *
* To v4.1 format: * To v4.1 format (with action-level thresholds):
* { * {
* version: "4.1", * version: "4.1",
* upsDevices: [ * upsDevices: [
@@ -37,7 +37,7 @@ import { logger } from '../logger.ts';
* { * {
* type: "shutdown", * type: "shutdown",
* thresholds: { battery: 60, runtime: 20 }, * thresholds: { battery: 60, runtime: 20 },
* onlyOnThresholdViolation: true, * triggerMode: "onlyThresholds",
* shutdownDelay: 5 * shutdownDelay: 5
* } * }
* ] * ]
@@ -50,7 +50,7 @@ export class MigrationV4_0ToV4_1 extends BaseMigration {
readonly toVersion = '4.1'; readonly toVersion = '4.1';
async shouldRun(config: any): Promise<boolean> { async shouldRun(config: any): Promise<boolean> {
// Run if config is version 4.0 or missing version with v4 structure // Run if config is version 4.0
if (config.version === '4.0') { if (config.version === '4.0') {
return true; return true;
} }
@@ -59,7 +59,7 @@ export class MigrationV4_0ToV4_1 extends BaseMigration {
if (config.upsDevices && config.upsDevices.length > 0) { if (config.upsDevices && config.upsDevices.length > 0) {
const firstDevice = config.upsDevices[0]; const firstDevice = config.upsDevices[0];
// v4.0 has thresholds at UPS level, v4.1 has them in actions // v4.0 has thresholds at UPS level, v4.1 has them in actions
return firstDevice.thresholds !== undefined && firstDevice.actions === undefined; return firstDevice.thresholds !== undefined;
} }
return false; return false;

View File

@@ -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