Don't use entity_id in __repr__ of not added entity (#106861)

pull/106867/head
Erik Montnemery 2024-01-02 11:35:16 +01:00 committed by GitHub
parent 97a5f0b2af
commit 599271fdc0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 3 additions and 3 deletions

View File

@ -1481,7 +1481,7 @@ class Entity(
If the entity is not added to a platform it's not safe to call _stringify_state.
"""
if self._platform_state != EntityPlatformState.ADDED:
return f"<entity {self.entity_id}={STATE_UNKNOWN}>"
return f"<entity unknown.unknown={STATE_UNKNOWN}>"
return f"<entity {self.entity_id}={self._stringify_state(self.available)}>"
async def async_request_call(self, coro: Coroutine[Any, Any, _T]) -> _T:

View File

@ -1407,7 +1407,7 @@ async def test_repr(hass) -> None:
my_entity = MyEntity(entity_id="test.test", available=False)
# Not yet added
assert str(my_entity) == "<entity test.test=unknown>"
assert str(my_entity) == "<entity unknown.unknown=unknown>"
# Added
await platform.async_add_entities([my_entity])
@ -1415,7 +1415,7 @@ async def test_repr(hass) -> None:
# Removed
await platform.async_remove_entity(my_entity.entity_id)
assert str(my_entity) == "<entity test.test=unknown>"
assert str(my_entity) == "<entity unknown.unknown=unknown>"
async def test_warn_using_async_update_ha_state(