diff --git a/homeassistant/helpers/condition.py b/homeassistant/helpers/condition.py index da4fdab07d79e780a9c64818e5da9b8446830f44..2f63498c9cdb9478131f1a833e528566229ba803 100644 --- a/homeassistant/helpers/condition.py +++ b/homeassistant/helpers/condition.py @@ -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), diff --git a/tests/helpers/test_condition.py b/tests/helpers/test_condition.py index dd1abdecb72110578d24e2d0cadaeef130b63685..1fc1e07da5dfafc836e5d36966a25bcf26cd63e3 100644 --- a/tests/helpers/test_condition.py +++ b/tests/helpers/test_condition.py @@ -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):