mirror of
https://github.com/home-assistant/core.git
synced 2025-07-16 09:47:13 +00:00
Collapse valid state check when creating a state (#93655)
Inline valid state check when creating a state This was added in #9696 and only used in one place so it does not need to be another function
This commit is contained in:
parent
560e744f1e
commit
c721cbd10c
@ -188,11 +188,6 @@ def valid_entity_id(entity_id: str) -> bool:
|
|||||||
return VALID_ENTITY_ID.match(entity_id) is not None
|
return VALID_ENTITY_ID.match(entity_id) is not None
|
||||||
|
|
||||||
|
|
||||||
def valid_state(state: str) -> bool:
|
|
||||||
"""Test if a state is valid."""
|
|
||||||
return len(state) <= MAX_LENGTH_STATE_STATE
|
|
||||||
|
|
||||||
|
|
||||||
def callback(func: _CallableT) -> _CallableT:
|
def callback(func: _CallableT) -> _CallableT:
|
||||||
"""Annotation to mark method as safe to call from within the event loop."""
|
"""Annotation to mark method as safe to call from within the event loop."""
|
||||||
setattr(func, "_hass_callback", True)
|
setattr(func, "_hass_callback", True)
|
||||||
@ -1256,7 +1251,7 @@ class State:
|
|||||||
"Format should be <domain>.<object_id>"
|
"Format should be <domain>.<object_id>"
|
||||||
)
|
)
|
||||||
|
|
||||||
if not valid_state(state):
|
if len(state) > MAX_LENGTH_STATE_STATE:
|
||||||
raise InvalidStateError(
|
raise InvalidStateError(
|
||||||
f"Invalid state encountered for entity ID: {entity_id}. "
|
f"Invalid state encountered for entity ID: {entity_id}. "
|
||||||
"State max length is 255 characters."
|
"State max length is 255 characters."
|
||||||
|
Loading…
x
Reference in New Issue
Block a user