Add a fast path for _stringify_state when state is already a str (#116295)

This commit is contained in:
J. Nick Koston 2024-04-27 10:48:17 -05:00 committed by GitHub
parent eea66921bb
commit f295172d07
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -1014,6 +1014,9 @@ class Entity(
return STATE_UNAVAILABLE
if (state := self.state) is None:
return STATE_UNKNOWN
if type(state) is str: # noqa: E721
# fast path for strings
return state
if isinstance(state, float):
# If the entity's state is a float, limit precision according to machine
# epsilon to make the string representation readable