From a090652560b6f8ab00830c74c2b465da167b48b2 Mon Sep 17 00:00:00 2001 From: Paulus Schoutsen Date: Mon, 6 Feb 2023 13:35:36 -0500 Subject: [PATCH] Use correct state in Entity repr and output similar value to State class (#87519) * Use correct state in Entity repr * Test Entity.__repr__ * Align with State class --- homeassistant/helpers/entity.py | 2 +- tests/helpers/test_entity.py | 15 +++++++++++++++ 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/homeassistant/helpers/entity.py b/homeassistant/helpers/entity.py index f9bb1effeb2..a3b64b5de15 100644 --- a/homeassistant/helpers/entity.py +++ b/homeassistant/helpers/entity.py @@ -957,7 +957,7 @@ class Entity(ABC): def __repr__(self) -> str: """Return the representation.""" - return f"" + return f"" async def async_request_call(self, coro: Coroutine[Any, Any, Any]) -> None: """Process request batched.""" diff --git a/tests/helpers/test_entity.py b/tests/helpers/test_entity.py index ac337b11b50..57f8ae03eaa 100644 --- a/tests/helpers/test_entity.py +++ b/tests/helpers/test_entity.py @@ -953,3 +953,18 @@ async def test_translation_key(hass): ) mock_entity2.entity_id = "hello.world" assert mock_entity2.translation_key == "from_entity_description" + + +async def test_repr_using_stringify_state(): + """Test that repr uses stringify state.""" + + class MyEntity(MockEntity): + """Mock entity.""" + + @property + def state(self): + """Return the state.""" + raise ValueError("Boom") + + entity = MyEntity(entity_id="test.test", available=False) + assert str(entity) == ""