mirror of
https://github.com/esphome/esphome.git
synced 2026-10-02 09:20:22 +00:00
[core] Parse ESPHOME_SERIAL_LOGGING_RESET as a boolean (#19963)
This commit is contained in:
+2
-2
@@ -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",
|
||||
|
||||
@@ -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.
|
||||
|
||||
|
||||
Reference in New Issue
Block a user