import { EcoFlowClient } from '../client.js';
export const setStandbyTool = {
name: 'ecoflow_set_standby',
description: 'Configure standby/timeout settings for an EcoFlow device. Set how long before the device, AC output, DC output, or LCD screen automatically turns off.',
inputSchema: {
type: 'object' as const,
properties: {
serial_number: {
type: 'string',
description: 'The device serial number'
},
device_timeout: {
type: 'number',
description: 'Device standby timeout in minutes. Set to 0 to disable auto-standby.'
},
ac_timeout: {
type: 'number',
description: 'AC output standby timeout in minutes. How long before AC output turns off when not in use.'
},
dc_timeout: {
type: 'number',
description: 'DC output standby timeout in minutes. How long before DC output turns off when not in use.'
},
lcd_timeout: {
type: 'number',
description: 'LCD screen timeout in seconds. How long before the screen dims/turns off.'
}
},
required: ['serial_number']
}
};
interface StandbyArgs {
serial_number: string;
device_timeout?: number;
ac_timeout?: number;
dc_timeout?: number;
lcd_timeout?: number;
}
export async function executeSetStandby(
client: EcoFlowClient,
args: StandbyArgs
): Promise<string> {
try {
// Validate inputs
if (args.device_timeout !== undefined && args.device_timeout < 0) {
throw new Error('device_timeout cannot be negative');
}
if (args.ac_timeout !== undefined && args.ac_timeout < 0) {
throw new Error('ac_timeout cannot be negative');
}
if (args.dc_timeout !== undefined && args.dc_timeout < 0) {
throw new Error('dc_timeout cannot be negative');
}
if (args.lcd_timeout !== undefined && args.lcd_timeout < 0) {
throw new Error('lcd_timeout cannot be negative');
}
await client.setStandbyTimeout(args.serial_number, {
deviceTimeout: args.device_timeout,
acTimeout: args.ac_timeout,
dcTimeout: args.dc_timeout,
lcdTimeout: args.lcd_timeout
});
const changes: string[] = [];
if (args.device_timeout !== undefined) {
changes.push(args.device_timeout === 0
? 'device auto-standby disabled'
: `device standby set to ${args.device_timeout} min`);
}
if (args.ac_timeout !== undefined) {
changes.push(args.ac_timeout === 0
? 'AC auto-standby disabled'
: `AC standby set to ${args.ac_timeout} min`);
}
if (args.dc_timeout !== undefined) {
changes.push(args.dc_timeout === 0
? 'DC auto-standby disabled'
: `DC standby set to ${args.dc_timeout} min`);
}
if (args.lcd_timeout !== undefined) {
changes.push(args.lcd_timeout === 0
? 'LCD auto-off disabled'
: `LCD timeout set to ${args.lcd_timeout} sec`);
}
return JSON.stringify({
success: true,
message: `Standby settings updated on device ${args.serial_number}: ${changes.join(', ')}`,
settings: {
deviceTimeoutMin: args.device_timeout,
acTimeoutMin: args.ac_timeout,
dcTimeoutMin: args.dc_timeout,
lcdTimeoutSec: args.lcd_timeout
}
}, null, 2);
} catch (error) {
const message = error instanceof Error ? error.message : String(error);
throw new Error(`Failed to set standby settings: ${message}`);
}
}