Compare commits

...

2 Commits

Author SHA1 Message Date
Erik 38db9d18f7 Fix review comments 2026-06-17 07:37:00 +02:00
Erik 6439ed840c Fail schema validation for state attribute condition with duration 2026-06-17 07:36:51 +02:00
2 changed files with 14 additions and 1 deletions
+1 -1
View File
@@ -1557,13 +1557,13 @@ STATE_CONDITION_BASE_SCHEMA = {
vol.Lower, vol.Any(ENTITY_MATCH_ALL, ENTITY_MATCH_ANY)
),
vol.Optional(CONF_ATTRIBUTE): str,
vol.Optional(CONF_FOR): positive_time_period_template,
}
STATE_CONDITION_STATE_SCHEMA = vol.Schema(
{
**STATE_CONDITION_BASE_SCHEMA,
vol.Required(CONF_STATE): vol.Any(str, [str]),
vol.Optional(CONF_FOR): positive_time_period_template,
}
)
+13
View File
@@ -1462,6 +1462,19 @@ async def test_state_for_invalid_template(
assert not test.async_check()
def test_state_for_not_allowed_with_attribute() -> None:
"""Test state condition rejects `for` combined with `attribute` is rejected."""
config = {
"condition": "state",
"entity_id": "sensor.temperature",
"attribute": "battery_level",
"state": "100",
"for": {"seconds": 5},
}
with pytest.raises(vol.Invalid, match=r"extra keys not allowed @ data\['for'\]"):
cv.CONDITION_SCHEMA(config)
async def test_state_unknown_attribute(hass: HomeAssistant) -> None:
"""Test that state returns False on unknown attribute."""
# Unknown attribute