From 954393008569030e7d5fcbe13543b001413ebf36 Mon Sep 17 00:00:00 2001 From: "J. Nick Koston" Date: Sat, 22 Aug 2026 23:43:38 -0500 Subject: [PATCH] State the cv.boolean alignment at the definition --- esphome/helpers.py | 6 ++++++ tests/unit_tests/test_helpers.py | 2 +- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/esphome/helpers.py b/esphome/helpers.py index 0a9aed9516..91413550aa 100644 --- a/esphome/helpers.py +++ b/esphome/helpers.py @@ -395,6 +395,12 @@ def sort_ip_addresses(address_list: list[str]) -> list[str]: def get_bool_env(var, default=False): + """Read a boolean environment knob. + + Accepts the same spellings as ``cv.boolean`` does in YAML, so the + environment speaks the config language's boolean dialect; anything + unrecognized falls through to ``bool(value)``. + """ value = os.getenv(var, default) if isinstance(value, str): value = value.lower() diff --git a/tests/unit_tests/test_helpers.py b/tests/unit_tests/test_helpers.py index 3375e34459..a7b911351d 100644 --- a/tests/unit_tests/test_helpers.py +++ b/tests/unit_tests/test_helpers.py @@ -1124,6 +1124,6 @@ def test_format_duration(seconds: float, expected: str) -> None: def test_get_bool_env_common_spellings( monkeypatch: pytest.MonkeyPatch, value: str, expected: bool ) -> None: - """The common on/off spellings parse instead of reading as truthy.""" + """The cv.boolean spellings parse instead of reading as truthy.""" monkeypatch.setenv("SOME_KNOB", value) assert helpers.get_bool_env("SOME_KNOB") is expected