Ensure it's safe to call Entity.__repr__ on non added entity (#106032)
This commit is contained in:
parent
c83388fd2d
commit
c1f1b5c50b
3 changed files with 19 additions and 14 deletions
|
@ -1476,7 +1476,12 @@ class Entity(
|
|||
self.async_on_remove(self._async_unsubscribe_device_updates)
|
||||
|
||||
def __repr__(self) -> str:
|
||||
"""Return the representation."""
|
||||
"""Return the representation.
|
||||
|
||||
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 {self.entity_id}={self._stringify_state(self.available)}>"
|
||||
|
||||
async def async_request_call(self, coro: Coroutine[Any, Any, _T]) -> _T:
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue