-
-
Notifications
You must be signed in to change notification settings - Fork 0
Migration v1.0
Thib3113 edited this page Aug 23, 2026
·
1 revision
This guide covers breaking changes and new features in the v1.0 release of nut-client.
Before: returned string (raw server response).
After: returns CommandResult | TrackedResult (structured object).
// Before (v0.x)
const response = await client.runCommand('myups', 'shutdown.return');
// response = "OK"
// After (v1.0)
const result = await client.runCommand('myups', 'shutdown.return');
// result = { tracked: false, success: true }If tracking is enabled:
// Before
const response = await client.runCommand('myups', 'shutdown.return');
// response = "OK TRACKING abc-123"
// After
const result = await client.runCommand('myups', 'shutdown.return');
// result = { tracked: true, trackingUid: 'abc-123' }Same as runCommand() — now returns CommandResult | TrackedResult instead of string.
Before: (key: string, oldValue: string, newValue: string)
After: (key: string, oldValue: string, newValue: string, oldVariables: nutVariables, newVariables: nutVariables)
// Before
monitor.on('VARIABLE_CHANGED', (key, oldValue, newValue) => { ... });
// After — old code still works, but you can now access full variable snapshots
monitor.on('VARIABLE_CHANGED', (key, oldValue, newValue, oldVars, newVars) => { ... });runCommand() now accepts an optional param argument:
await client.runCommand('myups', 'shutdown.return', '60'); // 60-second delayNew tracking system for long-running write operations. See Tracking for details.
await client.setTracking(true);
const result = await client.runCommand('myups', 'shutdown.return', '60', {
followTracking: true,
trackingTimeout: 60000,
});// Get UPS description
const desc = await client.getUPSDescription('myups');
// Force shutdown (set FSD flag)
await client.forceShutdown('myups');
// Static factory
const client = await NUTClient.create('127.0.0.1', 3493, {
username: 'admin',
password: 'secret',
autoReconnect: true,
});
// Check connection state
if (client.connected) { ... }Additional "NOT" events for flag disappearance:
monitor.on('NOTOL', () => ...); // OL disappeared
monitor.on('NOTOB', () => ...); // OB disappeared
monitor.on('NOTLB', () => ...); // LB disappeared
monitor.on('NOTFSD', () => ...); // FSD disappeared
monitor.on('NOTRB', () => ...); // RB disappearedNew variable events:
monitor.on('VARIABLES_CHANGED', (oldVars, newVars) => ...); // any variable changed
monitor.on('UNKNOWN_STATUS', (status) => ...); // unrecognized status codemonitor.pause(); // suppress events
monitor.isPaused(); // check state
monitor.resume(); // resume events
monitor.isDestroyed(); // check lifecycleawait ups.getInputVoltage(); // input voltage or NaN
await ups.getOutputVoltage(); // output voltage or NaN
await ups.getManufacturer(); // manufacturer string
await ups.getSerial(); // serial number stringNew exported types:
import type { CommandResult, TrackedResult, TrackingOptions } from 'nut-client';-
Update import paths if you imported from internal paths — use
nut-clientdirectly. -
Handle
runCommand()andsetVariable()return values — they are now objects, not strings. -
Update
VARIABLE_CHANGEDhandlers if you rely on the argument count — the signature gained 2 optional parameters. -
Enable tracking if you need write confirmation —
setTracking(true). -
Subscribe to
NOT*events if you need to react when status flags are cleared. - Test auto-reconnect if you rely on connection stability — the reconnect system is now more robust with session restoration.