From 8760c729457917c3e701b67941a2da59e907e91e Mon Sep 17 00:00:00 2001 From: "J. Nick Koston" Date: Sat, 22 Aug 2026 23:26:10 -0500 Subject: [PATCH] [core] Parse the common on/off spellings in boolean env vars --- esphome/helpers.py | 4 ++-- tests/unit_tests/test_helpers.py | 21 +++++++++++++++++++++ 2 files changed, 23 insertions(+), 2 deletions(-) diff --git a/esphome/helpers.py b/esphome/helpers.py index 9b2a461ccd..0a9aed9516 100644 --- a/esphome/helpers.py +++ b/esphome/helpers.py @@ -398,9 +398,9 @@ def get_bool_env(var, default=False): value = os.getenv(var, default) if isinstance(value, str): value = value.lower() - if value in ["1", "true"]: + if value in ("1", "true", "yes", "on", "enable"): return True - if value in ["0", "false"]: + if value in ("0", "false", "no", "off", "disable"): return False return bool(value) diff --git a/tests/unit_tests/test_helpers.py b/tests/unit_tests/test_helpers.py index 6e00e5b80f..7eaa4963c7 100644 --- a/tests/unit_tests/test_helpers.py +++ b/tests/unit_tests/test_helpers.py @@ -1108,3 +1108,24 @@ def test_progressbar_enabled_on_pipe_with_dashboard(monkeypatch) -> None: def test_format_duration(seconds: float, expected: str) -> None: """Test that durations are rendered as short human-readable strings.""" assert helpers.format_duration(seconds) == expected + + +@pytest.mark.parametrize( + ("value", "expected"), + [ + ("yes", True), + ("on", True), + ("enable", True), + ("no", False), + ("off", False), + ("disable", False), + ], +) +def test_get_bool_env_common_spellings( + monkeypatch: pytest.MonkeyPatch, value: str, expected: bool +) -> None: + """The common on/off spellings parse instead of falling through to + bool(str), which read "off" as enabled (e.g. IDF_CCACHE_ENABLE=off + left ccache on).""" + monkeypatch.setenv("SOME_KNOB", value) + assert helpers.get_bool_env("SOME_KNOB") is expected