Add on, off, and brightness commands to CLI#2043
Conversation
📝 WalkthroughWalkthroughThree new async CLI subcommands ( Changes
Sequence Diagram(s)sequenceDiagram
participant User as User/CLI
participant TyperCLI as Typer CLI
participant Command as on/off/brightness<br/>Command
participant WLEDContext as WLED Context<br/>Manager
participant Device as WLED Device<br/>(master method)
User->>TyperCLI: Execute command with --host
TyperCLI->>Command: Invoke command with host
Command->>WLEDContext: Create async context<br/>WLED(host)
WLEDContext->>WLEDContext: Enter context
Command->>Device: Await led.master()<br/>(on/off/brightness param)
Device->>Device: Execute control operation
Device-->>Command: Return/Complete
WLEDContext->>WLEDContext: Exit context
Command-->>TyperCLI: Print confirmation
TyperCLI-->>User: Display output
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Possibly related PRs
Poem
🚥 Pre-merge checks | ✅ 3✅ Passed checks (3 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
🧹 Nitpick comments (1)
tests/test_cli.py (1)
293-307: Add brightness boundary/error-path tests for stronger CLI validation coverage.Consider adding cases for
--brightness 0,--brightness 255, and invalid values (-1,256) to lock in the option constraints behavior.🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@tests/test_cli.py` around lines 293 - 307, Add dedicated test cases around test_brightness_command to cover boundary and invalid brightness values: create tests that call runner.invoke(cli, ["brightness","--host","example.com","--brightness","0"]) and ["255"] and assert exit_code == 0, result.output matches snapshots (or expected output) and mock.return_value.master.assert_awaited_once_with(brightness=0) / with(brightness=255); also add tests for invalid inputs ["-1"] and ["256"] asserting non-zero exit_code, an appropriate error message in result.output (or snapshot), and that mock.return_value.master.assert_not_awaited() to ensure the command rejects out-of-range values rather than sending them to WLED. Ensure you patch wled.cli.WLED the same way and reuse _mock_wled(_device()) and runner: CliRunner to keep test structure consistent.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Nitpick comments:
In `@tests/test_cli.py`:
- Around line 293-307: Add dedicated test cases around test_brightness_command
to cover boundary and invalid brightness values: create tests that call
runner.invoke(cli, ["brightness","--host","example.com","--brightness","0"]) and
["255"] and assert exit_code == 0, result.output matches snapshots (or expected
output) and mock.return_value.master.assert_awaited_once_with(brightness=0) /
with(brightness=255); also add tests for invalid inputs ["-1"] and ["256"]
asserting non-zero exit_code, an appropriate error message in result.output (or
snapshot), and that mock.return_value.master.assert_not_awaited() to ensure the
command rejects out-of-range values rather than sending them to WLED. Ensure you
patch wled.cli.WLED the same way and reuse _mock_wled(_device()) and runner:
CliRunner to keep test structure consistent.
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro
Run ID: 644b9648-4e29-45e8-b41b-87f26148e983
📒 Files selected for processing (3)
src/wled/cli/__init__.pytests/__snapshots__/test_cli.ambrtests/test_cli.py
Proposed Changes
Add wled on, wled off, and wled brightness commands for basic device control.
Summary by CodeRabbit
oncommand to turn WLED devices onoffcommand to turn WLED devices offbrightnesscommand to control device brightness (0-255 range)