Skip to content

Add on, off, and brightness commands to CLI#2043

Merged
frenck merged 1 commit intomainfrom
frenck-2026-0376
Apr 16, 2026
Merged

Add on, off, and brightness commands to CLI#2043
frenck merged 1 commit intomainfrom
frenck-2026-0376

Conversation

@frenck
Copy link
Copy Markdown
Owner

@frenck frenck commented Apr 16, 2026

Proposed Changes

Add wled on, wled off, and wled brightness commands for basic device control.

Summary by CodeRabbit

  • New Features
    • Added on command to turn WLED devices on
    • Added off command to turn WLED devices off
    • Added brightness command to control device brightness (0-255 range)
    • All commands require specifying the device host (IP address or hostname)

@frenck frenck added the new-feature New features or options. label Apr 16, 2026
@coderabbitai
Copy link
Copy Markdown

coderabbitai bot commented Apr 16, 2026

📝 Walkthrough

Walkthrough

Three new async CLI subcommands (on, off, brightness) are added to control WLED devices via host parameter, establishing async WLED contexts and invoking master control methods with confirmation output.

Changes

Cohort / File(s) Summary
CLI Commands Implementation
src/wled/cli/__init__.py
Added three async subcommands: command_on(), command_off(), and command_brightness(). Each accepts a host option with prompting, opens an async WLED context, invokes the corresponding led.master() method, and outputs confirmation messages.
Test Cases & Snapshots
tests/test_cli.py, tests/__snapshots__/test_cli.ambr
Added three snapshot-based tests verifying CLI command outputs and behavior with mocked WLED contexts. Snapshot entries include expected output strings and updated CLI structure definitions with the new on, off, and brightness commands.

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
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Possibly related PRs

  • Add reset command to CLI #2040: Adds similar async Typer CLI subcommands in src/wled/cli/__init__.py that create WLED contexts and invoke device methods (resets device instead of controlling power/brightness).

Poem

🐰 With whiskers twitching and eyes aglow,
Three new commands make the LED lights flow!
On, off, and brightness—what joy to behold!
From CLI to context, a tale brightly told.

🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The pull request title accurately summarizes the main change: adding three new CLI commands (on, off, and brightness) to the WLED CLI interface.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch frenck-2026-0376

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Copy Markdown

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🧹 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

📥 Commits

Reviewing files that changed from the base of the PR and between 85162a2 and 1a63710.

📒 Files selected for processing (3)
  • src/wled/cli/__init__.py
  • tests/__snapshots__/test_cli.ambr
  • tests/test_cli.py

@frenck frenck merged commit 8de1ced into main Apr 16, 2026
30 checks passed
@frenck frenck deleted the frenck-2026-0376 branch April 16, 2026 19:02
@github-actions github-actions bot locked and limited conversation to collaborators Apr 18, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

new-feature New features or options.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant