mirror of
https://github.com/esphome/esphome.git
synced 2026-08-24 07:06:20 +00:00
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:
+9
-2
@@ -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)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user