Add toggle option for Bluetooth command - #2
Conversation
There was a problem hiding this comment.
Pull request overview
This PR adds a "toggle" command option to the Bluetooth manager application, allowing users to switch Bluetooth state without specifying the target state explicitly.
- Added "toggle" as a valid command-line argument alongside existing "on" and "off" options
- Implemented toggle logic that switches Bluetooth state based on current state
- Updated usage message and comments to reflect the new toggle command
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| var newState = bluetoothRadio.State == RadioState.On ? RadioState.Off : RadioState.On; | ||
| await bluetoothRadio.SetStateAsync(newState); | ||
| Console.WriteLine($"Bluetooth was toggled to {(newState == RadioState.On ? "on" : "off")} successfully."); | ||
| } |
There was a problem hiding this comment.
There is trailing whitespace at the end of this line. This should be removed for consistency and to follow best practices.
| } | |
| } |
| } | ||
| else if (command == "toggle") | ||
| { | ||
| var newState = bluetoothRadio.State == RadioState.On ? RadioState.Off : RadioState.On; |
There was a problem hiding this comment.
The toggle logic doesn't handle intermediate states. The bluetooth radio could be in states other than On or Off (such as Unknown or Disabled). If bluetoothRadio.State is not RadioState.On, the code will attempt to turn it On, which may not be the intended behavior for all states. Consider checking if the current state is valid before toggling.
| var newState = bluetoothRadio.State == RadioState.On ? RadioState.Off : RadioState.On; | |
| var currentState = bluetoothRadio.State; | |
| if (currentState != RadioState.On && currentState != RadioState.Off) | |
| { | |
| Console.WriteLine($"Bluetooth cannot be toggled from the current state: {currentState}."); | |
| return; | |
| } | |
| var newState = currentState == RadioState.On ? RadioState.Off : RadioState.On; |
Adresses Issue #1