Numeric state trigger: validate that above is not above below (#32421)

* Numeric state trigger: validate that above is not above below

* Lint
This commit is contained in:
Paulus Schoutsen
2020-03-03 17:26:44 -08:00
committed by GitHub
parent db7d0eb9b9
commit 4cf86262af
2 changed files with 28 additions and 0 deletions

View File

@@ -19,6 +19,23 @@ from homeassistant.helpers.event import async_track_same_state, async_track_stat
# mypy: allow-incomplete-defs, allow-untyped-calls, allow-untyped-defs
# mypy: no-check-untyped-defs
def validate_above_below(value):
"""Validate that above and below can co-exist."""
above = value.get(CONF_ABOVE)
below = value.get(CONF_BELOW)
if above is None or below is None:
return value
if above > below:
raise vol.Invalid(
f"A value can never be above {above} and below {below} at the same time. You probably want two different triggers.",
)
return value
TRIGGER_SCHEMA = vol.All(
vol.Schema(
{
@@ -35,6 +52,7 @@ TRIGGER_SCHEMA = vol.All(
}
),
cv.has_at_least_one_key(CONF_BELOW, CONF_ABOVE),
validate_above_below,
)
_LOGGER = logging.getLogger(__name__)