mirror of
https://github.com/home-assistant/core.git
synced 2025-11-15 22:10:09 +00:00
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:
@@ -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__)
|
||||
|
||||
Reference in New Issue
Block a user