Don't use entity_id in __repr__ of not added entity (#106861)
parent
97a5f0b2af
commit
599271fdc0
|
@ -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:
|
||||
|
|
|
@ -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(
|
||||
|
|
Loading…
Reference in New Issue