From 6b6943955bf144397b2efc1a3305b778de7fbbc8 Mon Sep 17 00:00:00 2001 From: "J. Nick Koston" Date: Sun, 23 Aug 2026 13:21:38 -0500 Subject: [PATCH] Derive the env spellings from cv.boolean's shared tables TRUTHY/FALSY_BOOL_STRINGS live in helpers and cv.boolean consumes them, so the two parsers cannot drift; the env variants add only the 1/0 convention. --- esphome/helpers.py | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/esphome/helpers.py b/esphome/helpers.py index 9bb57b6468..7f0f340454 100644 --- a/esphome/helpers.py +++ b/esphome/helpers.py @@ -31,6 +31,13 @@ SockAddr = IPv4SockAddr | IPv6SockAddr _LOGGER = logging.getLogger(__name__) +# cv.boolean's closed spelling tables, shared with the env-knob parsing below +TRUTHY_BOOL_STRINGS = frozenset({"true", "yes", "on", "enable"}) +FALSY_BOOL_STRINGS = frozenset({"false", "no", "off", "disable"}) +# cv.boolean's spelling tables plus the 1/0 env convention +TRUTHY_ENV_STRINGS = TRUTHY_BOOL_STRINGS | {"1"} +FALSY_ENV_STRINGS = FALSY_BOOL_STRINGS | {"0"} + IS_MACOS = platform.system() == "Darwin" IS_WINDOWS = platform.system() == "Windows" IS_LINUX = platform.system() == "Linux" @@ -400,9 +407,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", "yes", "on", "enable"): + if value in TRUTHY_ENV_STRINGS: return True - if value in ("0", "false", "no", "off", "disable"): + if value in FALSY_ENV_STRINGS: return False return bool(value)