Raise ConditionError for time errors (#46250)

pull/46433/head
Anders Melchiorsen 2021-02-11 17:29:17 +01:00 committed by GitHub
parent 5ce49c62b1
commit 888c9e120d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 11 additions and 4 deletions

View File

@ -518,7 +518,9 @@ def time(
elif isinstance(after, str):
after_entity = hass.states.get(after)
if not after_entity:
return False
raise ConditionError(
f"Error in 'time' condition: The 'after' entity {after} is not available"
)
after = dt_util.dt.time(
after_entity.attributes.get("hour", 23),
after_entity.attributes.get("minute", 59),
@ -530,7 +532,9 @@ def time(
elif isinstance(before, str):
before_entity = hass.states.get(before)
if not before_entity:
return False
raise ConditionError(
f"Error in 'time' condition: The 'before' entity {before} is not available"
)
before = dt_util.dt.time(
before_entity.attributes.get("hour", 23),
before_entity.attributes.get("minute", 59),

View File

@ -334,8 +334,11 @@ async def test_time_using_input_datetime(hass):
hass, after="input_datetime.pm", before="input_datetime.am"
)
assert not condition.time(hass, after="input_datetime.not_existing")
assert not condition.time(hass, before="input_datetime.not_existing")
with pytest.raises(ConditionError):
condition.time(hass, after="input_datetime.not_existing")
with pytest.raises(ConditionError):
condition.time(hass, before="input_datetime.not_existing")
async def test_if_numeric_state_raises_on_unavailable(hass, caplog):