import 'dart:io'; const int MIN_TEMP = 15; const int MAX_TEMP = 30; void main() { bool lightsOn = false; int thermostat = 20; String security = 'disarmed'; print('Welcome to Smart Home CLI!'); bool running = true; while (running) { print('\nMain Menu:'); print('1. Control Lights'); print('2. Control Thermostat'); print('3. Control Security System'); print('4. View System Status'); print('5. Exit'); stdout.write('Select an option (1-5): '); String choice = (stdin.readLineSync() ?? '').trim(); if (choice == '1') { _handleLights((value) { lightsOn = value; }, lightsOn); } else if (choice == '2') { thermostat = _handleThermostat(thermostat); } else if (choice == '3') { security = _handleSecurity(security); } else if (choice == '4') { _displayStatus(lightsOn, thermostat, security); } else if (choice == '5') { running = false; print('Exiting Smart Home CLI. Goodbye!'); } else { print('Invalid choice. Please enter a number between 1 and 5.'); } } } void _handleLights(void Function(bool) updateLights, bool currentState) { print('\nLights Control:'); print('1. Turn ON'); print('2. Turn OFF'); print('3. Back'); stdout.write('Choose: '); String input = (stdin.readLineSync() ?? '').trim(); if (input == '1') { if (!currentState) { updateLights(true); print('Lights turned ON.'); } else { print('Lights are already ON.'); } } else if (input == '2') { if (currentState) { updateLights(false); print('Lights turned OFF.'); } else { print('Lights are already OFF.'); } } else if (input == '3') { } else { print('Invalid selection for lights.'); } } int _handleThermostat(int currentTemp) { print('\nThermostat Control:'); print('Current temperature: ${currentTemp}°C'); stdout.write('Enter new temperature ($MIN_TEMP-$MAX_TEMP) or press Enter to cancel: '); String raw = (stdin.readLineSync() ?? '').trim(); if (raw.isEmpty) { print('Thermostat unchanged.'); return currentTemp; } int? newTemp = int.tryParse(raw); if (newTemp == null) { print('Invalid input. Please enter an integer temperature.'); return currentTemp; } if (newTemp < MIN_TEMP || newTemp > MAX_TEMP) { print('Temperature must be between $MIN_TEMP°C and $MAX_TEMP°C.'); return currentTemp; } print('Thermostat set to ${newTemp}°C.'); return newTemp; } String _handleSecurity(String current) { print('\nSecurity System Control:'); print('1. Arm System'); print('2. Disarm System'); print('3. Back'); stdout.write('Choose: '); String input = (stdin.readLineSync() ?? '').trim(); if (input == '1') { if (current.toLowerCase() == 'armed') { print('Security system is already ARMED.'); return current; } else { print('Security system is now ARMED.'); return 'armed'; } } else if (input == '2') { if (current.toLowerCase() == 'disarmed') { print('Security system is already DISARMED.'); return current; } else { print('Security system is now DISARMED.'); return 'disarmed'; } } else if (input == '3') { return current; } else { print('Invalid selection for security system.'); return current; } } void _displayStatus(bool lightsOn, int thermostat, String security) { print('\n--- System Status ---'); String lightsStatus = lightsOn ? 'ON' : 'OFF'; String securityStatusUpper = security.toUpperCase(); print('Lights: $lightsStatus'); print('Thermostat: ${thermostat}°C'); print('Security System: $securityStatusUpper'); bool multipleOf3 = (thermostat % 3 == 0); bool multipleOf5 = (thermostat % 5 == 0); if (multipleOf3 && multipleOf5) { print('${thermostat}°C — Perfect Day'); } else if (multipleOf3) { print('${thermostat}°C — Cool Day'); } else if (multipleOf5) { print('${thermostat}°C — Warm Day'); } print('---------------------'); }