mirror of
https://github.com/home-assistant/core.git
synced 2025-07-19 19:27:45 +00:00
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
This commit is contained in:
parent
815ee58ea3
commit
a090652560
@ -957,7 +957,7 @@ class Entity(ABC):
|
|||||||
|
|
||||||
def __repr__(self) -> str:
|
def __repr__(self) -> str:
|
||||||
"""Return the representation."""
|
"""Return the representation."""
|
||||||
return f"<Entity {self.name}: {self.state}>"
|
return f"<entity {self.entity_id}={self._stringify_state(self.available)}>"
|
||||||
|
|
||||||
async def async_request_call(self, coro: Coroutine[Any, Any, Any]) -> None:
|
async def async_request_call(self, coro: Coroutine[Any, Any, Any]) -> None:
|
||||||
"""Process request batched."""
|
"""Process request batched."""
|
||||||
|
@ -953,3 +953,18 @@ async def test_translation_key(hass):
|
|||||||
)
|
)
|
||||||
mock_entity2.entity_id = "hello.world"
|
mock_entity2.entity_id = "hello.world"
|
||||||
assert mock_entity2.translation_key == "from_entity_description"
|
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) == "<entity test.test=unavailable>"
|
||||||
|
Loading…
x
Reference in New Issue
Block a user