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.
This commit is contained in:
J. Nick Koston
2026-08-23 13:21:38 -05:00
parent 454e7027e4
commit 6b6943955b
+9 -2
View File
@@ -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)