Skip to content

Commit

Permalink
Make boolean config validator more efficient
Browse files Browse the repository at this point in the history
  • Loading branch information
bachya committed Jan 18, 2024
1 parent e710d22 commit 69abdc4
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions ecowitt2mqtt/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,9 @@
CONF_HASS_DISCOVERY,
)

TRUTHY_VALUES = {"1", "true", "yes", "on", "enable"}
FALSEY_VALUES = {"0", "false", "no", "off", "disable"}


class ConfigError(EcowittError):
"""Define an error related to bad configuration."""
Expand All @@ -74,9 +77,9 @@ def validate_boolean(value: bool | str | Number) -> bool:
return value
if isinstance(value, str):
value = value.lower().strip()
if value in ("1", "true", "yes", "on", "enable"):
if value in TRUTHY_VALUES:
return True
if value in ("0", "false", "no", "off", "disable"):
if value in FALSEY_VALUES:
return False
elif isinstance(value, Number):
# type ignore: https://github.com/python/mypy/issues/3186
Expand Down

0 comments on commit 69abdc4

Please sign in to comment.