Move state length validation to StateMachine APIs (#143681)

* Move state length validation to StateMachine async_set method

We call validate_state to make sure we do not allow any states
into the state machine that have a length>255 so we do not break
the recorder. Since async_set_internal already requires callers
to pre-validate the state, we can move the check to async_set
instead of at State object creation time to avoid needing to
check it twice in the hot path (entity write state)

* move check in async_set_internal so it only happens on state change

* no need to check if same_state
This commit is contained in:
J. Nick Koston
2025-04-25 15:15:15 -10:00
committed by GitHub
parent 03950f270a
commit 34d17ca458
4 changed files with 51 additions and 22 deletions

View File

@@ -1711,7 +1711,7 @@ async def test_invalid_state(
ent.async_write_ha_state()
assert hass.states.get("test.test").state == STATE_UNKNOWN
assert (
"homeassistant.helpers.entity",
"homeassistant.core",
logging.ERROR,
f"State {long_state} for test.test is longer than 255, "
f"falling back to {STATE_UNKNOWN}",