From 765c4dae3ce0aacd8aab0b5595a8aa0f062b938e Mon Sep 17 00:00:00 2001 From: Junker der Provinz Date: Fri, 20 Nov 2026 22:53:10 +0100 Subject: [PATCH] Fix CLI echo of non-string output without rich (#1846) Co-authored-by: junkerderprovinz Co-authored-by: mash-graz <13013641+mash-graz@users.noreply.github.com> --- kasa/cli/common.py | 2 +- tests/test_cli.py | 8 ++++++++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/kasa/cli/common.py b/kasa/cli/common.py index 58927be1..597687c1 100644 --- a/kasa/cli/common.py +++ b/kasa/cli/common.py @@ -41,7 +41,7 @@ except ImportError: @wraps(echo_func) def wrapper(message=None, *args, **kwargs) -> None: - if message is not None: + if isinstance(message, str): message = rich_formatting.sub("", message) echo_func(message, *args, **kwargs) diff --git a/tests/test_cli.py b/tests/test_cli.py index 11023d23..029ae1fb 100644 --- a/tests/test_cli.py +++ b/tests/test_cli.py @@ -22,6 +22,7 @@ from kasa import ( KasaException, Module, ) +from kasa.cli.common import _echo from kasa.cli.device import ( alias, factory_reset, @@ -1568,3 +1569,10 @@ def test_echo_strips_rich_tags_without_rich(monkeypatch, capsys): module._echo("[bold red]Only discover is available[/bold red] [ABC]") assert capsys.readouterr().out == "Only discover is available [ABC]\n" + + +def test_echo_prints_non_string_messages(capsys): + """Messages other than strings are echoed as-is.""" + _echo(1) + + assert capsys.readouterr().out == "1\n"