Handle ConditionError with multiple entity_id for state/numeric_state (#46855)

This commit is contained in:
Anders Melchiorsen 2021-02-22 08:11:59 +01:00 committed by GitHub
parent 75b37b4c2a
commit d61d39de08
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 61 additions and 33 deletions

View file

@ -390,17 +390,18 @@ async def test_state_raises(hass):
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"):
test = await condition.async_from_config(
hass,
{
"condition": "state",
"entity_id": "sensor.door_unknown",
"state": "open",
},
)
# Unknown entities
test = await condition.async_from_config(
hass,
{
"condition": "state",
"entity_id": ["sensor.door_unknown", "sensor.window_unknown"],
"state": "open",
},
)
with pytest.raises(ConditionError, match="unknown entity.*door"):
test(hass)
with pytest.raises(ConditionError, match="unknown entity.*window"):
test(hass)
# Unknown attribute
@ -632,17 +633,18 @@ 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"):
test = await condition.async_from_config(
hass,
{
"condition": "numeric_state",
"entity_id": "sensor.temperature_unknown",
"above": 0,
},
)
# Unknown entities
test = await condition.async_from_config(
hass,
{
"condition": "numeric_state",
"entity_id": ["sensor.temperature_unknown", "sensor.humidity_unknown"],
"above": 0,
},
)
with pytest.raises(ConditionError, match="unknown entity.*temperature"):
test(hass)
with pytest.raises(ConditionError, match="unknown entity.*humidity"):
test(hass)
# Unknown attribute