import { EcoFlowClient } from '../client.js';
export const listDevicesTool = {
name: 'ecoflow_list_devices',
description: 'List all EcoFlow devices linked to your account. Returns device serial numbers, names, product types, and online status.',
inputSchema: {
type: 'object' as const,
properties: {},
required: []
}
};
export async function executeListDevices(client: EcoFlowClient): Promise<string> {
try {
const devices = await client.getDevices();
if (devices.length === 0) {
return 'No EcoFlow devices found linked to this account.';
}
const deviceList = devices.map(device => ({
serialNumber: device.sn,
name: device.deviceName || 'Unknown',
product: device.productName || 'Unknown',
status: device.online === 1 ? 'Online' : 'Offline'
}));
return JSON.stringify({
count: devices.length,
devices: deviceList
}, null, 2);
} catch (error) {
const message = error instanceof Error ? error.message : String(error);
throw new Error(`Failed to list devices: ${message}`);
}
}