[core] Parse ESPHOME_SERIAL_LOGGING_RESET as a boolean (#19963)

This commit is contained in:
Panda
2026-10-01 06:56:32 -05:00
committed by GitHub
parent 5a11f8d7c3
commit 3dc608c772
2 changed files with 26 additions and 2 deletions
+2 -2
View File
@@ -2343,7 +2343,7 @@ def parse_args(argv):
"-r",
action="store_true",
help="Reset the device before starting serial logs.",
default=os.getenv("ESPHOME_SERIAL_LOGGING_RESET"),
default=get_bool_env("ESPHOME_SERIAL_LOGGING_RESET"),
)
_add_states_args(parser_logs)
@@ -2384,7 +2384,7 @@ def parse_args(argv):
"-r",
action="store_true",
help="Reset the device before starting serial logs.",
default=os.getenv("ESPHOME_SERIAL_LOGGING_RESET"),
default=get_bool_env("ESPHOME_SERIAL_LOGGING_RESET"),
)
parser_run.add_argument(
"--ota-platform",
+24
View File
@@ -6437,6 +6437,30 @@ def test_parse_args_logs_states() -> None:
assert args.states is True
@pytest.mark.parametrize("command", ["logs", "run"])
@pytest.mark.parametrize(
("env_value", "expected"),
[(None, False), ("false", False), ("0", False), ("true", True), ("1", True)],
)
def test_parse_args_serial_logging_reset_env(
monkeypatch: pytest.MonkeyPatch,
command: str,
env_value: str | None,
expected: bool,
) -> None:
"""The serial reset environment default must be a boolean for both commands."""
if env_value is None:
monkeypatch.delenv("ESPHOME_SERIAL_LOGGING_RESET", raising=False)
else:
monkeypatch.setenv("ESPHOME_SERIAL_LOGGING_RESET", env_value)
args = parse_args(["esphome", command, "device.yaml"])
assert args.reset is expected
if not expected:
args = parse_args(["esphome", command, "--reset", "device.yaml"])
assert args.reset is True
def test_parse_args_argcomplete_only_runs_when_completing() -> None:
"""Only import and invoke argcomplete when _ARGCOMPLETE is set.