Skip to content

Commit a830441

Browse files
authored
Add upgrade command to CLI (#2041)
1 parent ebb8318 commit a830441

3 files changed

Lines changed: 59 additions & 0 deletions

File tree

src/wled/cli/__init__.py

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -310,6 +310,37 @@ async def command_reset(
310310
console.print("[green]WLED device has been rebooted!")
311311

312312

313+
@cli.command("upgrade")
314+
async def command_upgrade(
315+
host: Annotated[
316+
str,
317+
typer.Option(
318+
help="WLED device IP address or hostname",
319+
prompt="Host address",
320+
show_default=False,
321+
),
322+
],
323+
version: Annotated[
324+
str,
325+
typer.Option(
326+
help="WLED version to upgrade to",
327+
prompt="Version",
328+
show_default=False,
329+
),
330+
],
331+
) -> None:
332+
"""Upgrade a WLED device to a specific version."""
333+
async with WLED(host) as led:
334+
device = await led.update()
335+
console.print(f"[cyan]Current version: [bold]{device.info.version}[/bold]")
336+
console.print(f"[cyan]Upgrading to: [bold]{version}[/bold]")
337+
338+
with console.status("[cyan]Upgrading WLED device...", spinner="toggle12"):
339+
await led.upgrade(version=version)
340+
341+
console.print("[green]Upgrade complete! The device will reboot.")
342+
343+
313344
@cli.command("scan")
314345
async def command_scan() -> None:
315346
"""Scan for WLED devices on the network."""

tests/__snapshots__/test_cli.ambr

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,10 @@
2323
]),
2424
'scan': list([
2525
]),
26+
'upgrade': list([
27+
'host',
28+
'version',
29+
]),
2630
})
2731
# ---
2832
# name: test_connection_error_handler
@@ -289,3 +293,11 @@
289293

290294
'''
291295
# ---
296+
# name: test_upgrade_command
297+
'''
298+
Current version: 0.14.0
299+
Upgrading to: 0.15.0
300+
Upgrade complete! The device will reboot.
301+
302+
'''
303+
# ---

tests/test_cli.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -383,6 +383,22 @@ def test_reset_command(
383383
mock.return_value.reset.assert_awaited_once()
384384

385385

386+
@pytest.mark.usefixtures("stable_terminal")
387+
def test_upgrade_command(
388+
runner: CliRunner,
389+
snapshot: SnapshotAssertion,
390+
) -> None:
391+
"""Upgrade command shows progress and completes."""
392+
mock = _mock_wled(_device())
393+
with patch("wled.cli.WLED", mock):
394+
result = runner.invoke(
395+
cli, ["upgrade", "--host", "example.com", "--version", "0.15.0"]
396+
)
397+
assert result.exit_code == 0
398+
assert result.output == snapshot
399+
mock.return_value.upgrade.assert_awaited_once_with(version="0.15.0")
400+
401+
386402
@pytest.mark.usefixtures("stable_terminal")
387403
def test_releases_command(
388404
runner: CliRunner,

0 commit comments

Comments
 (0)