import { UnifiedTpLinkApi } from '../../src/unified-api'; import { TapoLightState } from '../../src/lightstate/tapo-lightstate'; import { DeviceProtocol } from '../../src/unified-device-factory'; export const testTapoDevice = async (host: string, email: string, password: string) => { console.log(`Testing Tapo device at ${host}...`); const api = new UnifiedTpLinkApi({ email, password }); try { // Create a test device object const device = { id: `tapo_${host.replace(/\./g, '_')}`, name: 'Test Tapo Device', host, protocol: DeviceProtocol.TAPO, deviceType: 'bulb', model: 'Unknown', }; // Get device info console.log('Getting device info...'); const info = await api.getDeviceInfo(device.id); console.log('Device info:', info); // Test power control console.log('Testing power control...'); await api.turnOn(device.id); console.log('Device turned on'); await new Promise((resolve) => setTimeout(resolve, 2000)); await api.turnOff(device.id); console.log('Device turned off'); await new Promise((resolve) => setTimeout(resolve, 2000)); await api.turnOn(device.id); console.log('Device turned back on'); // Test brightness and color (if it's a bulb) if (device.deviceType === 'bulb') { console.log('Testing brightness control...'); await api.setBrightness(device.id, 60); console.log('Brightness set to 60%'); await new Promise((resolve) => setTimeout(resolve, 2000)); console.log('Testing color control...'); await api.setRgb(device.id, 0, 0, 255); // Blue console.log('Color changed to blue'); await new Promise((resolve) => setTimeout(resolve, 2000)); await api.setRgb(device.id, 255, 255, 0); // Yellow console.log('Color changed to yellow'); } // Test energy monitoring (if supported) try { const energy = await api.getEnergyUsage(device.id); console.log('Energy reading:', energy); } catch { console.log('Energy monitoring not supported'); } return true; } catch (error) { console.error('Tapo device test failed:', error); return false; } };