From 888c9e120de997a4cb0419901b3a170f46286305 Mon Sep 17 00:00:00 2001
From: Anders Melchiorsen <amelchio@nogoto.net>
Date: Thu, 11 Feb 2021 17:29:17 +0100
Subject: [PATCH] Raise ConditionError for time errors (#46250)

---
 homeassistant/helpers/condition.py | 8 ++++++--
 tests/helpers/test_condition.py    | 7 +++++--
 2 files changed, 11 insertions(+), 4 deletions(-)

diff --git a/homeassistant/helpers/condition.py b/homeassistant/helpers/condition.py
index da4fdab07d7..2f63498c9cd 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 dd1abdecb72..1fc1e07da5d 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):
-- 
GitLab