#!/usr/bin/env tsx import { getDeviceFromArgs, prompt, promptInput } from './cli.js'; process.env.NODE_OPTIONS = '--openssl-legacy-provider'; const DEFAULT_STATE = { mode: 'cool', stemp: '22.0', f_rate: 'auto', f_dir: 'horizontal', }; let device: ReturnType | null = null; async function sleep(ms: number): Promise { return new Promise((resolve) => setTimeout(resolve, ms)); } async function getDevice() { if (!device) { device = await getDeviceFromArgs(); } return device; } async function printStatus() { const d = await getDevice(); await d.updateStatus(); console.log('\n--- Current Status ---'); console.log(`Power: ${d.values.get('pow')}`); console.log(`Mode: ${d.values.get('mode')}`); console.log(`Target Temp: ${d.targetTemperature}°C`); console.log(`Inside Temp: ${d.insideTemperature}°C`); console.log(`Outside Temp: ${d.outsideTemperature}°C`); console.log(`Fan Rate: ${d.values.get('f_rate')}`); console.log(`Fan Direction: ${d.values.get('f_dir')}`); console.log(`Advanced Mode: ${d.values.get('adv')}`); } async function menu() { console.log('\n'); console.log('========================================'); console.log(' DAIKIN AIR CONDITIONER CONTROL TEST'); console.log('========================================'); console.log(''); console.log('1. View Current Status'); console.log('2. Basic Control (On/Off, Mode, Temp)'); console.log('3. Fan Rate Test'); console.log('4. Fan Direction Test'); console.log('5. Advanced Modes (Powerful/Econo)'); console.log('6. Streamer Test'); console.log('7. Holiday Mode'); console.log('8. Humidity Control'); console.log('9. Restore Default State'); console.log('10. Exit'); console.log(''); const choice = await promptInput('Select option: '); console.log(''); switch (choice.trim()) { case '1': await viewStatus(); break; case '2': await testBasicControl(); break; case '3': await testFanRate(); break; case '4': await testFanDirection(); break; case '5': await testAdvancedModes(); break; case '6': await testStreamer(); break; case '7': await testHolidayMode(); break; case '8': await testHumidity(); break; case '9': await restoreDefaultState(); break; case '10': console.log('Exiting...'); return; default: console.log('Invalid option.'); } await menu(); } async function viewStatus() { console.log('=== VIEW STATUS ==='); await printStatus(); } async function testBasicControl() { console.log('=== BASIC CONTROL TEST ===\n'); const d = await getDevice(); await printStatus(); const continue1 = await prompt('\nTurn device OFF?'); if (continue1) { console.log('\nTurning OFF...'); await d.set({ mode: 'off' }); await sleep(2000); await printStatus(); } const continue2 = await prompt('\nTurn device ON (Cool, 22°C)?'); if (continue2) { console.log('\nTurning ON (Cool, 22°C)...'); await d.set({ mode: 'cool', stemp: '22.0', f_rate: 'auto', f_dir: 'off' }); await sleep(2000); await printStatus(); } const continue3 = await prompt('\nChange to Heat mode (26°C)?'); if (continue3) { console.log('\nSetting Heat mode (26°C)...'); await d.set({ mode: 'heat', stemp: '26.0' }); await sleep(2000); await printStatus(); } const continue4 = await prompt('\nChange to Dry mode (22°C)?'); if (continue4) { console.log('\nSetting Dry mode (22°C)...'); await d.set({ mode: 'dry', stemp: '22.0' }); await sleep(2000); await printStatus(); } const continue5 = await prompt('\nChange to Fan Only mode?'); if (continue5) { console.log('\nSetting Fan Only mode...'); await d.set({ mode: 'fan' }); await sleep(2000); await printStatus(); } const continue6 = await prompt('\nChange to Auto mode (23°C)?'); if (continue6) { console.log('\nSetting Auto mode (23°C)...'); await d.set({ mode: 'auto', stemp: '23.0' }); await sleep(2000); await printStatus(); } } async function testFanRate() { console.log('=== FAN RATE TEST ===\n'); const d = await getDevice(); await d.set({ mode: 'cool', stemp: '22.0', f_rate: 'auto', f_dir: 'off' }); await sleep(1000); await printStatus(); const rates = [ { value: 'auto', label: 'Auto' }, { value: 'silence', label: 'Silence' }, { value: '3', label: 'Speed 1 (lowest)' }, { value: '4', label: 'Speed 2' }, { value: '5', label: 'Speed 3' }, { value: '6', label: 'Speed 4' }, { value: '7', label: 'Speed 5 (highest)' }, ]; for (const rate of rates) { const cont = await prompt(`\nSet fan rate to ${rate.label}?`); if (cont) { console.log(`\nSetting fan rate to ${rate.label}...`); await d.set({ f_rate: rate.value }); await sleep(2000); await printStatus(); } else { break; } } } async function testFanDirection() { console.log('=== FAN DIRECTION TEST ===\n'); const d = await getDevice(); await d.set({ mode: 'cool', stemp: '22.0', f_rate: 'auto' }); await sleep(1000); await printStatus(); const directions = [ { value: 'off', label: 'Off (no swing)' }, { value: 'vertical', label: 'Vertical (up/down)' }, { value: 'horizontal', label: 'Horizontal (left/right)' }, { value: '3d', label: '3D (combined)' }, ]; for (const dir of directions) { const cont = await prompt(`\nSet fan direction to ${dir.label}?`); if (cont) { console.log(`\nSetting fan direction to ${dir.label}...`); await d.set({ f_dir: dir.value }); await sleep(2000); await printStatus(); } else { break; } } } async function testAdvancedModes() { console.log('=== ADVANCED MODES TEST ===\n'); const d = await getDevice(); await d.set({ mode: 'cool', stemp: '22.0', f_rate: 'auto', f_dir: 'off' }); await sleep(1000); await printStatus(); const cont1 = await prompt('\nEnable Powerful mode?'); if (cont1) { console.log('\nEnabling Powerful mode...'); await d.setAdvancedMode('powerful', 'on'); await sleep(2000); await printStatus(); } const cont2 = await prompt('\nDisable Powerful mode?'); if (cont2) { console.log('\nDisabling Powerful mode...'); await d.setAdvancedMode('powerful', 'off'); await sleep(2000); await printStatus(); } const cont3 = await prompt('\nEnable Econo mode?'); if (cont3) { console.log('\nEnabling Econo mode...'); await d.setAdvancedMode('econo', 'on'); await sleep(2000); await printStatus(); } const cont4 = await prompt('\nDisable Econo mode?'); if (cont4) { console.log('\nDisabling Econo mode...'); await d.setAdvancedMode('econo', 'off'); await sleep(2000); await printStatus(); } } async function testStreamer() { console.log('=== STREAMER TEST ===\n'); const d = await getDevice(); await d.set({ mode: 'cool', stemp: '22.0', f_rate: 'auto', f_dir: 'off' }); await sleep(1000); await printStatus(); const cont1 = await prompt('\nEnable Streamer?'); if (cont1) { console.log('\nEnabling Streamer...'); await d.setStreamer('on'); await sleep(2000); await printStatus(); } const cont2 = await prompt('\nDisable Streamer?'); if (cont2) { console.log('\nDisabling Streamer...'); await d.setStreamer('off'); await sleep(2000); await printStatus(); } } async function testHolidayMode() { console.log('=== HOLIDAY MODE TEST ===\n'); const d = await getDevice(); await d.set({ mode: 'cool', stemp: '22.0', f_rate: 'auto', f_dir: 'off' }); await sleep(1000); await printStatus(); console.log(`\nSupports holiday mode: ${d.supportAwayMode}`); if (!d.supportAwayMode) { console.log('Device does not support holiday mode.'); return; } const cont1 = await prompt('\nEnable Holiday mode?'); if (cont1) { console.log('\nEnabling Holiday mode...'); await d.setHoliday('on'); await sleep(2000); await printStatus(); } const cont2 = await prompt('\nDisable Holiday mode?'); if (cont2) { console.log('\nDisabling Holiday mode...'); await d.setHoliday('off'); await sleep(2000); await printStatus(); } } async function testHumidity() { console.log('=== HUMIDITY CONTROL TEST ===\n'); const d = await getDevice(); await d.updateStatus(); console.log(`Supports humidity: ${d.supportHumidity}`); console.log(`Current humidity: ${d.humidity}%`); console.log(`Target humidity: ${d.targetHumidity}%`); if (d.humidity === null) { console.log('Device does not have humidity sensor.'); return; } const cont = await prompt('\nSet target humidity to 50%?'); if (cont) { console.log('\nSetting target humidity to 50%...'); await d.set({ mode: 'dry', shum: '50' }); await sleep(2000); await printStatus(); } } async function restoreDefaultState() { console.log('=== RESTORE DEFAULT STATE ===\n'); console.log('Restoring to:'); console.log(` Mode: ${DEFAULT_STATE.mode}`); console.log(` Target Temp: ${DEFAULT_STATE.stemp}°C`); console.log(` Fan Rate: ${DEFAULT_STATE.f_rate}`); console.log(` Fan Direction: ${DEFAULT_STATE.f_dir}`); const cont = await prompt('\nRestore default state?'); if (cont) { const d = await getDevice(); console.log('\nRestoring...'); await d.set(DEFAULT_STATE); await sleep(2000); await printStatus(); console.log('\nDefault state restored!'); } } menu().catch((error) => { console.error('Error:', error instanceof Error ? error.message : error); process.exit(1); });