Skip to content

Commit ebb8318

Browse files
frenckCopilot
andauthored
Add reset command to CLI (#2040)
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
1 parent 242afe0 commit ebb8318

3 files changed

Lines changed: 42 additions & 0 deletions

File tree

src/wled/cli/__init__.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -291,6 +291,25 @@ async def command_releases() -> None:
291291
console.print(table)
292292

293293

294+
@cli.command("reset")
295+
async def command_reset(
296+
host: Annotated[
297+
str,
298+
typer.Option(
299+
help="WLED device IP address or hostname",
300+
prompt="Host address",
301+
show_default=False,
302+
),
303+
],
304+
) -> None:
305+
"""Reboot a WLED device."""
306+
with console.status("[cyan]Rebooting WLED device...", spinner="toggle12"):
307+
async with WLED(host) as led:
308+
await led.reset()
309+
310+
console.print("[green]WLED device has been rebooted!")
311+
312+
294313
@cli.command("scan")
295314
async def command_scan() -> None:
296315
"""Scan for WLED devices on the network."""

tests/__snapshots__/test_cli.ambr

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,9 @@
1818
]),
1919
'releases': list([
2020
]),
21+
'reset': list([
22+
'host',
23+
]),
2124
'scan': list([
2225
]),
2326
})
@@ -252,6 +255,12 @@
252255

253256
'''
254257
# ---
258+
# name: test_reset_command
259+
'''
260+
WLED device has been rebooted!
261+
262+
'''
263+
# ---
255264
# name: test_scan_command_keyboard_interrupt
256265
'''
257266
Scanning for WLED devices...

tests/test_cli.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -369,6 +369,20 @@ def test_presets_command_empty(
369369
assert output == snapshot
370370

371371

372+
@pytest.mark.usefixtures("stable_terminal")
373+
def test_reset_command(
374+
runner: CliRunner,
375+
snapshot: SnapshotAssertion,
376+
) -> None:
377+
"""Reset command reboots the device."""
378+
mock = _mock_wled(_device())
379+
with patch("wled.cli.WLED", mock):
380+
result = runner.invoke(cli, ["reset", "--host", "example.com"])
381+
assert result.exit_code == 0
382+
assert result.output == snapshot
383+
mock.return_value.reset.assert_awaited_once()
384+
385+
372386
@pytest.mark.usefixtures("stable_terminal")
373387
def test_releases_command(
374388
runner: CliRunner,

0 commit comments

Comments
 (0)