mirror of
https://github.com/home-assistant/core.git
synced 2025-11-09 02:49:40 +00:00
Raise ConditionError for state errors (#46244)
This commit is contained in:
committed by
GitHub
parent
6a62ebb6a4
commit
f27066e773
@@ -359,6 +359,37 @@ async def test_if_numeric_state_raises_on_unavailable(hass, caplog):
|
||||
assert len(caplog.record_tuples) == 0
|
||||
|
||||
|
||||
async def test_state_raises(hass):
|
||||
"""Test that state raises ConditionError on errors."""
|
||||
# Unknown entity_id
|
||||
with pytest.raises(ConditionError, match="Unknown entity"):
|
||||
test = await condition.async_from_config(
|
||||
hass,
|
||||
{
|
||||
"condition": "state",
|
||||
"entity_id": "sensor.door_unknown",
|
||||
"state": "open",
|
||||
},
|
||||
)
|
||||
|
||||
test(hass)
|
||||
|
||||
# Unknown attribute
|
||||
with pytest.raises(ConditionError, match=r"Attribute .* does not exist"):
|
||||
test = await condition.async_from_config(
|
||||
hass,
|
||||
{
|
||||
"condition": "state",
|
||||
"entity_id": "sensor.door",
|
||||
"attribute": "model",
|
||||
"state": "acme",
|
||||
},
|
||||
)
|
||||
|
||||
hass.states.async_set("sensor.door", "open")
|
||||
test(hass)
|
||||
|
||||
|
||||
async def test_state_multiple_entities(hass):
|
||||
"""Test with multiple entities in condition."""
|
||||
test = await condition.async_from_config(
|
||||
@@ -466,7 +497,8 @@ async def test_state_attribute_boolean(hass):
|
||||
assert not test(hass)
|
||||
|
||||
hass.states.async_set("sensor.temperature", 100, {"no_happening": 201})
|
||||
assert not test(hass)
|
||||
with pytest.raises(ConditionError):
|
||||
test(hass)
|
||||
|
||||
hass.states.async_set("sensor.temperature", 100, {"happening": False})
|
||||
assert test(hass)
|
||||
@@ -567,7 +599,7 @@ async def test_numeric_state_raises(hass):
|
||||
},
|
||||
)
|
||||
|
||||
assert test(hass)
|
||||
test(hass)
|
||||
|
||||
# Unknown attribute
|
||||
with pytest.raises(ConditionError, match=r"Attribute .* does not exist"):
|
||||
|
||||
Reference in New Issue
Block a user