mirror of
https://github.com/esphome/esphome.git
synced 2024-11-25 00:18:11 +01:00
Read string of bool env and match against well known values (#5232)
This commit is contained in:
parent
db9dc11022
commit
a84365659b
2 changed files with 12 additions and 1 deletions
|
@ -144,7 +144,14 @@ def resolve_ip_address(host):
|
|||
|
||||
|
||||
def get_bool_env(var, default=False):
|
||||
return bool(os.getenv(var, default))
|
||||
value = os.getenv(var, default)
|
||||
if isinstance(value, str):
|
||||
value = value.lower()
|
||||
if value in ["1", "true"]:
|
||||
return True
|
||||
if value in ["0", "false"]:
|
||||
return False
|
||||
return bool(value)
|
||||
|
||||
|
||||
def get_str_env(var, default=None):
|
||||
|
|
|
@ -108,6 +108,10 @@ def test_is_ip_address__valid(value):
|
|||
("FOO", None, False, False),
|
||||
("FOO", None, True, True),
|
||||
("FOO", "", False, False),
|
||||
("FOO", "False", False, False),
|
||||
("FOO", "True", False, True),
|
||||
("FOO", "FALSE", True, False),
|
||||
("FOO", "fAlSe", True, False),
|
||||
("FOO", "Yes", False, True),
|
||||
("FOO", "123", False, True),
|
||||
),
|
||||
|
|
Loading…
Reference in a new issue