mirror of
https://github.com/home-assistant/core.git
synced 2025-11-15 22:10:09 +00:00
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:
@@ -31,7 +31,6 @@ from homeassistant.const import (
|
||||
ATTR_SUPPORTED_FEATURES,
|
||||
ATTR_UNIT_OF_MEASUREMENT,
|
||||
DEVICE_DEFAULT_NAME,
|
||||
MAX_LENGTH_STATE_STATE,
|
||||
STATE_OFF,
|
||||
STATE_ON,
|
||||
STATE_UNAVAILABLE,
|
||||
@@ -1217,16 +1216,6 @@ class Entity(
|
||||
self._context = None
|
||||
self._context_set = None
|
||||
|
||||
if len(state) > MAX_LENGTH_STATE_STATE:
|
||||
_LOGGER.error(
|
||||
"State %s for %s is longer than %s, falling back to %s",
|
||||
state,
|
||||
self.entity_id,
|
||||
MAX_LENGTH_STATE_STATE,
|
||||
STATE_UNKNOWN,
|
||||
)
|
||||
state = STATE_UNKNOWN
|
||||
|
||||
# Intentionally called with positional args for performance reasons
|
||||
self.hass.states.async_set_internal(
|
||||
self.entity_id,
|
||||
|
||||
Reference in New Issue
Block a user