mirror of
https://github.com/home-assistant/core.git
synced 2025-11-09 10:59:40 +00:00
Refine printing of ConditionError (#46838)
* Refine printing of ConditionError * Improve coverage * name -> type
This commit is contained in:
committed by
GitHub
parent
e2fd255a96
commit
d33a1a5ff8
@@ -386,8 +386,12 @@ async def test_if_numeric_state_raises_on_unavailable(hass, caplog):
|
||||
|
||||
async def test_state_raises(hass):
|
||||
"""Test that state raises ConditionError on errors."""
|
||||
# No entity
|
||||
with pytest.raises(ConditionError, match="no entity"):
|
||||
condition.state(hass, entity=None, req_state="missing")
|
||||
|
||||
# Unknown entity_id
|
||||
with pytest.raises(ConditionError, match="Unknown entity"):
|
||||
with pytest.raises(ConditionError, match="unknown entity"):
|
||||
test = await condition.async_from_config(
|
||||
hass,
|
||||
{
|
||||
@@ -400,7 +404,7 @@ async def test_state_raises(hass):
|
||||
test(hass)
|
||||
|
||||
# Unknown attribute
|
||||
with pytest.raises(ConditionError, match=r"Attribute .* does not exist"):
|
||||
with pytest.raises(ConditionError, match=r"attribute .* does not exist"):
|
||||
test = await condition.async_from_config(
|
||||
hass,
|
||||
{
|
||||
@@ -414,6 +418,20 @@ async def test_state_raises(hass):
|
||||
hass.states.async_set("sensor.door", "open")
|
||||
test(hass)
|
||||
|
||||
# Unknown state entity
|
||||
with pytest.raises(ConditionError, match="input_text.missing"):
|
||||
test = await condition.async_from_config(
|
||||
hass,
|
||||
{
|
||||
"condition": "state",
|
||||
"entity_id": "sensor.door",
|
||||
"state": "input_text.missing",
|
||||
},
|
||||
)
|
||||
|
||||
hass.states.async_set("sensor.door", "open")
|
||||
test(hass)
|
||||
|
||||
|
||||
async def test_state_multiple_entities(hass):
|
||||
"""Test with multiple entities in condition."""
|
||||
@@ -564,7 +582,6 @@ async def test_state_using_input_entities(hass):
|
||||
"state": [
|
||||
"input_text.hello",
|
||||
"input_select.hello",
|
||||
"input_number.not_exist",
|
||||
"salut",
|
||||
],
|
||||
},
|
||||
@@ -616,7 +633,7 @@ async def test_state_using_input_entities(hass):
|
||||
async def test_numeric_state_raises(hass):
|
||||
"""Test that numeric_state raises ConditionError on errors."""
|
||||
# Unknown entity_id
|
||||
with pytest.raises(ConditionError, match="Unknown entity"):
|
||||
with pytest.raises(ConditionError, match="unknown entity"):
|
||||
test = await condition.async_from_config(
|
||||
hass,
|
||||
{
|
||||
@@ -629,7 +646,7 @@ async def test_numeric_state_raises(hass):
|
||||
test(hass)
|
||||
|
||||
# Unknown attribute
|
||||
with pytest.raises(ConditionError, match=r"Attribute .* does not exist"):
|
||||
with pytest.raises(ConditionError, match=r"attribute .* does not exist"):
|
||||
test = await condition.async_from_config(
|
||||
hass,
|
||||
{
|
||||
@@ -659,7 +676,7 @@ async def test_numeric_state_raises(hass):
|
||||
test(hass)
|
||||
|
||||
# Unavailable state
|
||||
with pytest.raises(ConditionError, match="State is not available"):
|
||||
with pytest.raises(ConditionError, match="state of .* is unavailable"):
|
||||
test = await condition.async_from_config(
|
||||
hass,
|
||||
{
|
||||
@@ -687,7 +704,7 @@ async def test_numeric_state_raises(hass):
|
||||
test(hass)
|
||||
|
||||
# Below entity missing
|
||||
with pytest.raises(ConditionError, match="below entity"):
|
||||
with pytest.raises(ConditionError, match="'below' entity"):
|
||||
test = await condition.async_from_config(
|
||||
hass,
|
||||
{
|
||||
@@ -700,8 +717,16 @@ async def test_numeric_state_raises(hass):
|
||||
hass.states.async_set("sensor.temperature", 50)
|
||||
test(hass)
|
||||
|
||||
# Below entity not a number
|
||||
with pytest.raises(
|
||||
ConditionError,
|
||||
match="'below'.*input_number.missing.*cannot be processed as a number",
|
||||
):
|
||||
hass.states.async_set("input_number.missing", "number")
|
||||
test(hass)
|
||||
|
||||
# Above entity missing
|
||||
with pytest.raises(ConditionError, match="above entity"):
|
||||
with pytest.raises(ConditionError, match="'above' entity"):
|
||||
test = await condition.async_from_config(
|
||||
hass,
|
||||
{
|
||||
@@ -714,6 +739,14 @@ async def test_numeric_state_raises(hass):
|
||||
hass.states.async_set("sensor.temperature", 50)
|
||||
test(hass)
|
||||
|
||||
# Above entity not a number
|
||||
with pytest.raises(
|
||||
ConditionError,
|
||||
match="'above'.*input_number.missing.*cannot be processed as a number",
|
||||
):
|
||||
hass.states.async_set("input_number.missing", "number")
|
||||
test(hass)
|
||||
|
||||
|
||||
async def test_numeric_state_multiple_entities(hass):
|
||||
"""Test with multiple entities in condition."""
|
||||
@@ -849,7 +882,10 @@ async def test_zone_raises(hass):
|
||||
},
|
||||
)
|
||||
|
||||
with pytest.raises(ConditionError, match="Unknown zone"):
|
||||
with pytest.raises(ConditionError, match="no zone"):
|
||||
condition.zone(hass, zone_ent=None, entity="sensor.any")
|
||||
|
||||
with pytest.raises(ConditionError, match="unknown zone"):
|
||||
test(hass)
|
||||
|
||||
hass.states.async_set(
|
||||
@@ -858,7 +894,10 @@ async def test_zone_raises(hass):
|
||||
{"name": "home", "latitude": 2.1, "longitude": 1.1, "radius": 10},
|
||||
)
|
||||
|
||||
with pytest.raises(ConditionError, match="Unknown entity"):
|
||||
with pytest.raises(ConditionError, match="no entity"):
|
||||
condition.zone(hass, zone_ent="zone.home", entity=None)
|
||||
|
||||
with pytest.raises(ConditionError, match="unknown entity"):
|
||||
test(hass)
|
||||
|
||||
hass.states.async_set(
|
||||
|
||||
Reference in New Issue
Block a user