Fix CLI echo of non-string output without rich (#1846)

Co-authored-by: junkerderprovinz <jdp@braethoria.com>
Co-authored-by: mash-graz <13013641+mash-graz@users.noreply.github.com>
This commit is contained in:
Junker der Provinz
2026-11-20 22:53:10 +01:00
committed by GitHub
parent 3bf95247d4
commit 765c4dae3c
2 changed files with 9 additions and 1 deletions

View File

@@ -41,7 +41,7 @@ except ImportError:
@wraps(echo_func) @wraps(echo_func)
def wrapper(message=None, *args, **kwargs) -> None: def wrapper(message=None, *args, **kwargs) -> None:
if message is not None: if isinstance(message, str):
message = rich_formatting.sub("", message) message = rich_formatting.sub("", message)
echo_func(message, *args, **kwargs) echo_func(message, *args, **kwargs)

View File

@@ -22,6 +22,7 @@ from kasa import (
KasaException, KasaException,
Module, Module,
) )
from kasa.cli.common import _echo
from kasa.cli.device import ( from kasa.cli.device import (
alias, alias,
factory_reset, 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]") module._echo("[bold red]Only discover is available[/bold red] [ABC]")
assert capsys.readouterr().out == "Only discover is available [ABC]\n" 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"